Automatic updates for VM plugins since Joomla 3.7...

Started by reinhold, August 02, 2017, 23:21:25 PM

Previous topic - Next topic

reinhold

Since Joomla 3.7 the Joomla plugin updater appears to try to load a plugin before a plugin update is executed (so a possible trigger onInstallerBeforePackageDownload is available). This is done in administrator/components/com_installer/models/update.php, function preparePreUpdate.
Whenever the plugin is updated through the plugin updater, it is now explicitly loaded by a call to JPluginHelper::importPlugin. Unfortunately, only the plugin is loaded, not the whole VM environment apparently. All VM plugins are loaded from within VM, so all these plugins assume VM is already properly setup.

In particular, all shipping and payment plugins I have seen simply start like:

<?php
defined 
('_JEXEC') or die('Restricted access');
if (!
class_exists ('vmPSPlugin')) {
        require(
JPATH_VM_PLUGINS DS 'vmpsplugin.php');
}
[...]


This will fail with an error message when the plugin is updated through the Joomla plugin updater:

Notice: Use of undefined constant JPATH_VM_PLUGINS - assumed 'JPATH_VM_PLUGINS' in /var/www/html/plugins/vmshipment/rules_shipping_advanced/rules_shipping_advanced.php on line 23
Notice: Use of undefined constant DS - assumed 'DS' in /var/www/html/plugins/vmshipment/rules_shipping_advanced/rules_shipping_advanced.php on line 23
Warning: require(JPATH_VM_PLUGINSDSvmpsplugin.php): failed to open stream: No such file or directory in /var/www/html/plugins/vmshipment/rules_shipping_advanced/rules_shipping_advanced.php on line 23
Fatal error: require(): Failed opening required 'JPATH_VM_PLUGINSDSvmpsplugin.php' (include_path='.:/usr/local/lib/php') in /var/www/html/plugins/vmshipment/rules_shipping_advanced/rules_shipping_advanced.php on line 23


Manually installing the .zip file of the new version works fine to update the plugin, but the Joomla plugin updater (which is now more or less forced by the JED) triggers this problem.

What is the proper way to ensure VM is fully loaded in a plugin, so that a JPluginHelper::importPlugin call on a plugin works?

Thanks,
Reinhold

Milbo

Does this work in vmplugin.php?


//systemplugins must not load the language
$wLang = ($this->_type != 'system');

if (!class_exists( 'VmConfig' )) {
require(JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php');
VmConfig::loadConfig(FALSE, FALSE, $wLang);
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

hey crazy, our code syntax highlighter recognises php. Wahh I use this forum so many years and did not know.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

reinhold

Quote from: Milbo on August 05, 2017, 20:26:49 PM
Does this work in vmplugin.php?

Unfortunately, it doesn't, because Joomla isn't able to locate and load the vmpsplugin.php, as the JPATH_VM_PLUGINS constant is not defined.

Milbo

Just as information.

We had a longer chat in our dev chat with Reinhold and it seems the only way is a system plugin, loading vm for the installation. Thanks to Reinhold the plugin is already written and will be provided with the next update.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

vassiskansa


Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/