4

I am creating a module that I hope will do a little more complex functions than many. However, I will need to do certain things like DB modification and moving files when the module installs.

I am working with Joomla 3.3.

Is it possible to do a postflight routine on a module install? Can you show example or link to docs?

Thanks!

2

Yes, this is possible and is pretty straight forward as well. Firstly, you need to add the following to your modules XML file:

<scriptfile>script.php</scriptfile>

And of course, going by this, you will need to create a file called script.php or whatever you wish to call it. Just make sure you change the file name in the code above accordingly. Them, in the file, add the following code:

<?php  
defined('_JEXEC') or die('Restricted access');

class com_helloWorldInstallerScript
{    
     function postflight($type, $parent) 
     {
           // all your code goes in here
     }
}

Simply add your code in the postflight function which will then get executed after the module has been installed. Joomla also provides 4 other built in functions:

  1. install
  2. uninstall
  3. preflight
  4. update

These may also come in handy for the future. more information can be found on all of this here:

https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_an_install-uninstall-update_script_file

Hope this helps

  • If my module is HelloWorld do I NEED to camelcase my class name like this: mod_helloWorldInstallerScript? or is there some leniency afforded to mod_HelloWorldInstallerScript? My boss and I are trying to get my first module to seamlessly install via Drag-n-Drop. When I remove my script.php file and <scriptfile>script.php</script> in the xml file it works ...but then we have to perform several other followup actions to publish and position the module (which is not cool) any quick pieces of advice pertaining to the script file before I post a new question? I'm getting a vague "error" – mickmackusa Apr 12 '18 at 0:36
  • 1
    I'm not too sure on the requirements as my own module seems to differ from what the docs mention. The docs say The name of this class is dependent on the component being installed. The class name should have the component's name, directly followed by the text InstallerScript. So I assume you'd need mod_HelloWorldInstallerScript – Lodder Apr 12 '18 at 8:58
2

Yes you should be able too.

http://docs.joomla.org/J2.5:Developing_a_MVC_Component/Adding_an_install-uninstall-update_script_file

http://docs.joomla.org/J2.5:Creating_a_simple_module/Adding_an_install-uninstall-update_script_file

You can adjust that to use "mod" as well and in the config file for the module you just need to add <scriptfile>path</scriptfile> (I think, it could be slightly different then that).

In order to do any database and file manipulation you will need JDatabase and JFile/JFolder.

http://docs.joomla.org/Selecting_data_using_JDatabase http://docs.joomla.org/How_to_use_the_filesystem_package

These should help get you started.

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.