VirtueMart Forum

VirtueMart 2 + 3 => Virtuemart Development and bug reports => Topic started by: reinhold on August 02, 2017, 23:21:25 pm

Title: Automatic updates for VM plugins since Joomla 3.7...
Post by: reinhold on August 02, 2017, 23:21:25 pm
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:
Code: [Select]
<?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:
Code: [Select]
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
Title: Re: Automatic updates for VM plugins since Joomla 3.7...
Post by: Milbo on August 05, 2017, 20:26:49 pm
Does this work in vmplugin.php?

Code: [Select]
//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);
}
Title: Re: Automatic updates for VM plugins since Joomla 3.7...
Post by: Milbo on August 05, 2017, 20:27:45 pm
hey crazy, our code syntax highlighter recognises php. Wahh I use this forum so many years and did not know.
Title: Re: Automatic updates for VM plugins since Joomla 3.7...
Post by: reinhold on August 05, 2017, 23:45:06 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.
Title: Re: Automatic updates for VM plugins since Joomla 3.7...
Post by: Milbo on August 07, 2017, 11:35:01 am
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.
Title: Re: Automatic updates for VM plugins since Joomla 3.7...
Post by: vassiskansa on August 21, 2017, 16:01:29 pm
Hi,
can i have an update of this problem?
Thank you.
Title: Re: Automatic updates for VM plugins since Joomla 3.7...
Post by: Milbo on August 21, 2017, 17:31:33 pm
The plugin is in the last "our really last RC for vm3.2.4" (works like a charm)  http://dev.virtuemart.net/attachments/download/1087/com_virtuemart.3.2.3.9624_extract_first.zip