7

I am creating a plugin and am attempting to run a script after it is installed. For whatever reason, it appears the script file is loading, but my code is never run.

My script.php file contains the following:

// No direct access
defined('_JEXEC') or die('Restricted access');

/**
 * Script file for the plg_system_example plugin    
 */
class plg_system_notifierInstallerScript{

  /**
   * Method to run after the plugin install, update, or discover_update actions have completed.
   *
   * @return void
   */
  function postflight($type,$parent){
    // For Testing Purposes
    die('Hello World');
  }
}

I have tried to use a number of different derivations of the class name with no luck. If I place a die() statement outside of the class, it is run, which leads me to believe that the file is loaded. I have also tried other methods, such as install() without success.

Note that I had actual code in place of the die() statement, but have switched to this in the course of debugging this issue.

What am I doing wrong that Joomla! is not calling the postflight() method in my class on install?

7

Did you try the class name without underscores?

"plgSystemNotifierInstallerScript"

(or possibly "plgSystemnotifierInstallerScript" not sure)

That seems to be the format the two plugins I checked use.

  • plgSystemNotifierInstallerScript worked as expected. Oddly, this is contrary to Joomla!'s documentation which clearly shows the use of underscores. =( Thanks for your help! – Zachary Draper Dec 16 '14 at 1:33
  • It would be great to improve your answer by providing a clear reference to the documentation or to the code regarding the naming convention. Thanks! – Valentin Despa Dec 16 '14 at 20:22
  • @ValentinDespa I didn't find any real documentation. There is some for modules and components, but the naming convention differs. It has underscores, so it is probably what Zachary Draper was talking about with the documentation to contrary. – Ville Niemi Dec 16 '14 at 20:59
  • I couldn't get this to work until I got the CamelCase correct. plgSystemPluginnameInstallerScript Only the first character of the plugin name is capitalized. David (below) has a good explanation - but misses the capitalization requirement. – Michael Mar 29 '17 at 22:29
2

On Joomla 3.4 the installer class name is based on the plugin group (e.g. system) from the root tag in the manifest:

    <extension type="plugin" group="system" version="3.0" method="upgrade">

and the plugin name (e.g. myplugin) that goes in the following line in the manifest:

    <filename plugin="myplugin">pluginfile.php</filename>

And then you put it all together prepended with plg like so:

    plgSystemMyPluginInstallerScript
2

Just in case anyone doing an editors-xtd plugin stumbles across this note that following the comment from papacho, you need to use plgEditorsxtdMypluginnameInstallerScript with the hyphen removed.

Thus for plugin MyPluginName in the manifest mypluginname.xml

<extension version="3.0" type="plugin" group="editors-xtd" method="upgrade">
...
<filename plugin="mypluginname">mypluginname.php</filename>

In the plugin file mypluginname.php

class plgButtonMypluginname extends JPlugin {
...

and in the script.php file

class plgEditorsxtdMypluginnameInstallerScript {
...

got there in the end... :-)

PS I can't work out why you use plgButton... in the plugin file but editors-xtd in the manifest and in the script (without the hyphen), but no other combination seems to work, so Hey Ho.

1

Class name of Script installer is defined in $JPATH_ROOT/libraries/cms/installer/adapter.php:553

$className = JFilterInput::getInstance()->clean($this->element, 'cmd') . 'InstallerScript';
// Cannot have - in class names
$className = str_replace('-', '', $className);

this mean

  • plg => PLGNAMEInstallerScript
  • mod => MODNAMEInstallerScript
  • component => COMNAMEInstallerScript
  • template => TEMPLATENAMEInstallerScript
    widthout any '-' that be supressed by str_replace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.