[SOLVED] Couldn’t find constant JPATH_ in Joomla! 2.5

 

Jan
26

0


Since the release of Joomla! 2.5, we’ve been testing and updating all our joomla components and plugins to work with the new, long term stability release of Joomla!

With warnings turned on, we kept seeing warnings such as:

“Warning: constant() [function:constant]: Couldn’t find constant JPATH_ in librairies/joomla/installer/adapters/module.php on line 117”

and

“Warning: constant() [function:constant]: Couldn’t find constant JPATH_ in librairies/joomla/installer/adapters/module.php on line 119”

I googled for a while, found references to .sys.ini files and other problems, but nothing that addressed how to fix this easily.

Here’s the solution.

Looking at the code, we see:

$client = (string) $this->manifest->attributes()->client;
$lang->load($extension . '.sys', $source, null, false, false)
|| $lang->load($extension . '.sys', constant('JPATH_' . strtoupper($client)), null, false, false)
|| $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false)
|| $lang->load($extension . '.sys', constant('JPATH_' . strtoupper($client)), $lang->getDefault(), false, false);

Looking at the bold and underlined sections above, it becomes clear [if you know php and know that in this case the manifest is the XML install manifest file after it has been parsed] that the system is trying to determine which side of the site to install the module: the SITE or the ADMIN.  The fix in the insall was then relatively straightforward: where 1.5 assumes all installs are performed in the SITE unless told otherwise, for 2.5 you have to declare it specifically in the manifest:

<install type=”module” version=”1.5.0″ method=”upgrade” client=”site”>

simply add “client=site” (or admin, if you prefer) to the module manifest file.

The same issue will most likely strike with any extension that can have a front-end or back-end installation: modules, languages and templates, to name a few.

IMO, this is really a bug in Joomla!, and has been reported as such: constants shouldn’t be chosen dynamically from user input such as a manifest file. Instead, the code should use  a switch statement or some other method,  then either use reasonable defaults as used to be the case (most modules are for the site, right?) or  fail gracefully with an error message if it can’t determine where to load the files.

Let’s hope this is addressed in a future version of the Joomla! core. In the meantime, module authors can use this solution to update their manifest files and solve the “Couldn’t find constant JPATH_” errors for their customers.

 

 

Comments are closed.