? ? Pending

User tests: Successful: Unsuccessful:

avatar dgrammatiko
dgrammatiko
18 Apr 2021

Pull Request for Issue # .

Summary of Changes

Since #32633 J4 (non legacy) Modules don't have a module.php file in their root folder

<filename module="mod_quickicon">mod_quickicon.php</filename>

and thus it's impossible to install a module that uses namespace, check the existing code:

public function getElement($element = null)
{
if (!$element)
{
if (\count($this->getManifest()->files->children()))
{
foreach ($this->getManifest()->files->children() as $file)
{
if ((string) $file->attributes()->module)
{
$element = strtolower((string) $file->attributes()->module);
break;
}
}
}
}
return $element;
}
.

To mitigate this in the easiest possible way I propose to require (for the J4 native modules, not the legacy) one field in the XML: eg <element>mod_wow</element>;

Testing Instructions

You could test this in 2 different ways:

  • go to your db and delete in the extension table the mod_quickicon
  • Then move the administrator/mopdules/mod_quickicon to a folder outside of the Joomla folder
  • Zip the content of the folder and try to install it (it will fail with a message file mod_quickicon.php doesn't exist)
  • Edit the XML file removing the line <filename module="mod_quickicon">mod_quickicon.php</filename> and adding after line 3 <element>mod_quickicon</element> then zip the contents of the folder and try again

Alternative you can download https://jinvalidate.netlify.app/dist/j4/mod_invalidatecache_0.0.6.zip and observe that the module installs correctly

Actual result BEFORE applying this Pull Request

Expected result AFTER applying this Pull Request

Documentation Changes Required

@laoneo some feedback here?
@wilsonge ?

avatar dgrammatiko dgrammatiko - open - 18 Apr 2021
avatar dgrammatiko dgrammatiko - change - 18 Apr 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 18 Apr 2021
Category Libraries
avatar dgrammatiko
dgrammatiko - comment - 18 Apr 2021

BTW this should be a release blocker

c3739e5 18 Apr 2021 avatar dgrammatiko CS
avatar dgrammatiko dgrammatiko - change - 18 Apr 2021
Labels Added: ?
avatar dgrammatiko dgrammatiko - change - 18 Apr 2021
The description was changed
avatar dgrammatiko dgrammatiko - edited - 18 Apr 2021
avatar dgrammatiko dgrammatiko - change - 18 Apr 2021
The description was changed
avatar dgrammatiko dgrammatiko - edited - 18 Apr 2021
avatar PhilETaylor
PhilETaylor - comment - 23 Apr 2021

Please update the method to be this.

This employs "return early" pattern.

This code has been fully tested with the new Unit Test you can use in PR #33260 - the tests pass before and after this refactoring.

	/**
	 * Get the filtered extension element from the manifest
	 *
	 * @param   string  $element  Optional element name to be converted
	 *
	 * @return  string|null  The filtered element
	 *
	 * @since   3.4
	 */
	public function getElement($element = null)
	{
		if ($element)
		{
			return $element;
		}

		// Joomla 4 Module.
		if ((string) $this->getManifest()->element)
		{
			return (string) $this->getManifest()->element;
		}

		if (!\count($this->getManifest()->files->children()))
		{
			return $element;
		}

		foreach ($this->getManifest()->files->children() as $file)
		{
			if ((string) $file->attributes()->module)
			{
				// Joomla 3 (legacy) Module.
				return strtolower((string) $file->attributes()->module);
			}
		}

		return $element;
	}
avatar dgrammatiko
dgrammatiko - comment - 23 Apr 2021

Thanks @PhilETaylor code updated

avatar richard67 richard67 - test_item - 23 Apr 2021 - Tested successfully
avatar richard67
richard67 - comment - 23 Apr 2021

I have tested this item successfully on fbe603a

I've tested with use of https://jinvalidate.netlify.app/dist/j4/mod_invalidatecache_0.0.6.zip . Without this PR, there is an error when trying to install the module. With the PR, there is no error, and the module is installed. Other modules can still be installed, too.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33182.

avatar alikon alikon - test_item - 23 Apr 2021 - Tested successfully
avatar alikon
alikon - comment - 23 Apr 2021

I have tested this item successfully on fbe603a


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33182.

avatar alikon alikon - change - 23 Apr 2021
Status Pending Ready to Commit
avatar alikon
alikon - comment - 23 Apr 2021

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33182.

avatar chmst chmst - close - 23 Apr 2021
avatar chmst chmst - merge - 23 Apr 2021
avatar chmst chmst - change - 23 Apr 2021
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2021-04-23 15:22:56
Closed_By chmst
Labels Added: ?
avatar chmst
chmst - comment - 23 Apr 2021

Thanks!

Add a Comment

Login with GitHub to post a comment