Error installing library Topic is solved

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
jjbongio
Joomla! Intern
Joomla! Intern
Posts: 56
Joined: Mon Dec 16, 2013 2:29 pm

Error installing library

Post by jjbongio » Fri Dec 30, 2022 1:18 am

I recently converted from Joomla 3.10 to Joomla 4.2.6

When I install a library, I always get the error
Cannot declare class XXXXInstallerScript because the name is already in use

Screen shot attached.
joomla.jpg
Clearing all caches always fixes it
You do not have the required permissions to view the files attached to this post.

jjbongio
Joomla! Intern
Joomla! Intern
Posts: 56
Joined: Mon Dec 16, 2013 2:29 pm

Re: Error installing library

Post by jjbongio » Fri Dec 30, 2022 2:11 am

Update. The odd thing is that if I clear all caches before doing the install, it fails with the error above. When I then clear caches and reinstall, it works.

jjbongio
Joomla! Intern
Joomla! Intern
Posts: 56
Joined: Mon Dec 16, 2013 2:29 pm

Re: Error installing library

Post by jjbongio » Fri Dec 30, 2022 6:49 pm

The zip installs without problems on Joomla 3.10.11

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17442
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Error installing library

Post by toivo » Fri Dec 30, 2022 10:41 pm

Which particular library is it? Are you sure it is compatible with Joomla 4?
Toivo Talikka, Global Moderator

jjbongio
Joomla! Intern
Joomla! Intern
Posts: 56
Joined: Mon Dec 16, 2013 2:29 pm

Re: Error installing library

Post by jjbongio » Sat Dec 31, 2022 5:50 pm

It's my own library, and it runs fine under Joomla 4 once it's installed. The only problem I see is the install problem referenced here.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30935
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Error installing library

Post by Per Yngve Berg » Sat Dec 31, 2022 7:44 pm

Mod. Note: Relocated the topic to the Coding Forum.

User avatar
ceford
Joomla! Hero
Joomla! Hero
Posts: 2677
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Error installing library

Post by ceford » Sun Jan 01, 2023 2:29 pm

Looks like you are using a custom installer script that does all the work usually done from index.php. Joomla 3 and 4 install.php scripts look quite different, like this:

Code: Select all

\defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
[or various other classes needed for installation]

class com_fooInstallerScript
{

}
Where the class contains various functions called by the installer (the Joomla one). I don't know how you might fix the problem! If the library gets installed and works it may be best to leave it alone.

jjbongio
Joomla! Intern
Joomla! Intern
Posts: 56
Joined: Mon Dec 16, 2013 2:29 pm

Re: Error installing library

Post by jjbongio » Mon Jan 02, 2023 6:25 pm

Thanks. Do you have a pointer to the differences in installer scripts between J3 and J4?
My script is quite simple. I want to display a message with the component version and to delete obsolete files. All of that does work after I clear the cache, so it's not a huge deal.

User avatar
ceford
Joomla! Hero
Joomla! Hero
Posts: 2677
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Error installing library

Post by ceford » Mon Jan 02, 2023 7:48 pm

I can't really help, other than point you to libraries/src/Installer/InstallerAdapter.php line 961 where you are loading a file containing a class name that is already loaded. You probably know that. Look at the script files in some of the administrator components - mostly you only need preflight and postflight. What does your script file do?

jjbongio
Joomla! Intern
Joomla! Intern
Posts: 56
Joined: Mon Dec 16, 2013 2:29 pm

Re: Error installing library

Post by jjbongio » Mon Jan 02, 2023 9:22 pm

Thanks, I'll look there. It just displays the installed version and deletes obsolete files.

jjbongio
Joomla! Intern
Joomla! Intern
Posts: 56
Joined: Mon Dec 16, 2013 2:29 pm

Re: Error installing library

Post by jjbongio » Tue Jan 03, 2023 1:30 am

Good suggestion to look at other components.

Poking around components, I found nothing unusual, but I did find something looking at library install scripts. Few libraries that I use have them, but Regular Labs does. And they wrap their class with a check to see that the class isn't already defined. When I did the same thing, the problem went away, and it seemed to run the install script correctly.

I'm guessing that there's something in library install where the script can get loaded twice, but I'm not going to debug it.

Thanks for the help.


Locked

Return to “Joomla! 4.x Coding”