0

I've a module that I want to run a script post installation, post update etc.

I think this can be done by adding a script.php into the module zip file and then calling it in the installation file.

<scriptfile>script.php</scriptfile>

in the xml file to set up the script.

In the script.php I've some test type stuff:

            <?php
            // No direct access to this file
            defined('_JEXEC') or die;

            /**
             * Script file of HelloWorld module
             */
            class mod_W4cAccordionDisplayInstallerScript
            {

                /**
                 * Method to install the extension
                 * $parent is the class calling this method
                 *
                 * @return void
                 */
                function install($parent) 
                {
                    echo '<p>The module has been installed</p>';
                            $db = JFactory::getDbo();
                    $query = $db->getQuery(true)
                            ->update('#__update_sites')
                            ->set('extra_query = "ids=12354"')
                            ->where('name = "Accordian Display"');
                    $db->setQuery($query);

                    $db->execute();

                }

                /**
                 * Method to uninstall the extension
                 * $parent is the class calling this method
                 *
                 * @return void
                 */
                function uninstall($parent) 

I haven't copied the whole file since it's basically a copy of the joomla example.

When I run this by updating in the update then it says installation complete but it doesn't adjust the update sites table.

Any ideas where I might be going wrong


So I've now changed out the database update for

mail("myemail@gmail.com","My subject","user id is: ");

and put it into function postflight($type, $parent)

but there is no email response - I think that it's not loading and running the script :(


Figured it out - I had the wrong class name. I had removed all the _ characters like you normally do for class names but apparently you don't for this script. Hope this helps someone else. Thanks for the thoughts.

  • Are you sure the class is correct in accordance with your module name? – Lodder Feb 15 at 16:13
  • module is mod_W4c_Accordion_Display – user1616338 Feb 15 at 16:16
  • In the query there is a misspelling of the table field (at ->where) name Accordian instead of Accordion, maybe... – Zollie Feb 15 at 16:19
  • @ Zollie - I checked and the module name is spelt that way Accordian Display – user1616338 Feb 15 at 16:27
  • Please would you mind writing your solution as a proper answer below and mark it as accepted. Thank you – Lodder Feb 16 at 14:46
0

On update, you should use the update method like

function update($parent) 
{
    // on update stuff
}

You can find it in Joomla documentation Creating the extension script file

Hope it helps.

0

I changed the script to

            <?php
            // No direct access to this file
            defined('_JEXEC') or die;

            /**
             * Script file of HelloWorld module
             */
            class mod_w4c_accordion_displayInstallerScript
            {

                /**
                 * Method to install the extension
                 * $parent is the class calling this method
                 *
                 * @return void
                 */

The key to success was NOT removing the underscores - something you do with other areas of Joomla like in a helper.php file. Once I'd done this it worked without a problem.

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.