1

I have two plugins and i need to package them together. Is there a way to make a script to install two plugins at once? And auto publish only one of them?

This script works to one:

public function postflight($route, JAdapterInstance $adapter)
{
    // We only need to perform this if the extension is being installed, not updated.
    if ( $route == 'install' ) 
    {    
        // Get a database object.   
        $db = JFactory::getDbo();

        // Create a new query object.
        $query = $db->getQuery(true);

        $fields = array(
            $db->quoteName('enabled') . ' = ' . (int) 1
        );

        $conditions = array(
            $db->quoteName('element') . ' = ' . $db->quote('plugin_name'), 
            $db->quoteName('folder') . ' = ' . $db->quote('plugin_group')
        );

        $query->update($db->quoteName('#__extensions'))->set($fields)->where($conditions);

        // Set the query and load the result.
        $db->setQuery($query);   
        $result = $db->query();    
    }
}
2

You don't need to use the install.php to install separate plugins. For this, you can simply use your XML file.

So firstly, make sure you define the type of extension as a package like so:

<extension type="package" version="3.3" method"upgrade">

Then, add the following to your XML:

<files folder="packages">
   <file type="plugin" id="helloworld" group="system">plg_sys_helloworld.zip</file>
   <file type="plugin" id="helloworld2" group="system">plg_sys_helloworld2.zip</file>
</files>

For more information on this (please read this), have a look at the following:

https://docs.joomla.org/Package

  • So, i will need both plugin zipped separately with their own xml files and another xml file to install both as package? If i need to add a postflight script i should included in the related plugin? – n.h. Jan 27 '15 at 15:31
  • Yes, that's the way it would work. As for your postflight script, all you need to do is run a database query as you're currently doing and target the plugin by it's name – Lodder Jan 27 '15 at 15:33
1

Installing with package is most suitable in this case as @Lodder has suggested.

But in case you do not want to go ahead with package then there is an alternate.

You can install this by using JInstaller class.

$installer =  new JInstaller();
$installer->install($path);

here $path will contain the path of the another plugin which you want to install. You can include the related plugin code in the same zip and provide that path.

So you can add this code in the postflight method of the plugin installation script.

About the plugin enable state, by default plugin will remain disable on installation. And in case of plugin upgrade, previous state will be maintained.

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.