Uninstall an extension on Joomla 4
The script file is executed and the function 'uninstall' is called inside the class com_xxxxInstallerScript, when the function 'uninstall' is called it's still possible to use JText::_('...'); loading language files included under the component folder such as:
Joomla40/administrator/components/com_xxx/language/en-GB/en-GB.com_xxx.ini
Files are already deleted at this stage compared to the current Joomla 3 and Joomla 2.5
Thus the JText won't translate strings anymore because it's no more possible to load language files already deleted. It works only if the component was using language files under:
Joomla40/administrator/language/en-GB/en-GB.com_xxx.ini
function uninstall($parent) { $lang = \Joomla\CMS\Factory::getLanguage(); $lang->load('com_xxx'); echo \JText::_('COM_XXX_UNINSTALL_SUCCESS' ); ....
Labels |
Added:
?
|
Category | ⇒ | Language & Strings |
I don't know what's going on... however to have it still working on Joomla 4 i had to move the code loading language files to the preflight() stage
function preflight($type, $parent) { $lang = \Joomla\CMS\Factory::getLanguage(); $lang->load('com_xxx'); }
load()
with only an extension parameter only loads files from the global language directory. If you're trying to load them from an extension directory, you have to pass the path. It's why you have multiple calls to the load()
method in most places, like https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Component/ComponentHelper.php#L361
I tried that too, but nothing changes. Moreover this does not explain why the language files are not loaded anymore in Joomla 4... if the setupUninstall would work the following code should not be needed at all.
// Manage partial language translations $jLang = \Joomla\CMS\Factory::getLanguage(); $jLang->load('com_xxx', JPATH_COMPONENT_ADMINISTRATOR, 'en-GB', true, true); ì
Well without somebody debugging it we're just going to go back and forth with a "it's broken, this that and the other thing don't work" commentary
I'm just doing it... i think that the problem is that the '$this->element' property is 'null' during the setupUnistall
// Attempt to load the admin language file; might have uninstall strings $this->loadLanguage(JPATH_ADMINISTRATOR . '/components/' . $this->element);
Use $this->extension->element
and it should be fine.
You got it ;)
That's the problem, changing the line 704 of /Joomla40staging/libraries/src/Installer/Adapter/ComponentAdapter.php
from:
$this->loadLanguage(JPATH_ADMINISTRATOR . '/components/' . $this->element);
to:
$this->loadLanguage(JPATH_ADMINISTRATOR . '/components/' . $this->extension->element);
fix the issue.
I guess this issue needs a PR
Status | New | ⇒ | Discussion |
Labels |
Added:
J4 Issue
?
|
Category | Language & Strings | ⇒ |
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2019-11-16 17:42:09 |
Closed_By | ⇒ | Quy |
Please test PR #27090
Unless someone screwed up a merge, #16343 did not change the order things were processed; the
uninstall
hook is still long before the instruction to delete the extension files. Language files are even explicitly loaded as the last instruction in each adapter'ssetupUninstall
method (which is before theuninstall
hook).