Author Topic: Automatic updates for VM plugins since Joomla 3.7...  (Read 7354 times)

reinhold

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 204
Automatic updates for VM plugins since Joomla 3.7...
« 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

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10545
  • VM4.0.7 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Automatic updates for VM plugins since Joomla 3.7...
« Reply #1 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);
}
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10545
  • VM4.0.7 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Automatic updates for VM plugins since Joomla 3.7...
« Reply #2 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.
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

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 204
Re: Automatic updates for VM plugins since Joomla 3.7...
« Reply #3 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.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10545
  • VM4.0.7 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Automatic updates for VM plugins since Joomla 3.7...
« Reply #4 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.
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

  • Beginner
  • *
  • Posts: 1
  • A beginner
Re: Automatic updates for VM plugins since Joomla 3.7...
« Reply #5 on: August 21, 2017, 16:01:29 pm »
Hi,
can i have an update of this problem?
Thank you.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10545
  • VM4.0.7 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Automatic updates for VM plugins since Joomla 3.7...
« Reply #6 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
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/