Jump to content

Installing modules via code


jsmit2

Recommended Posts

You can check if required module is installed by simply adding this:

$this->dependencies = array('some_module_name');

to your module __construct method. User will not be able to install module before installing required module.

 

This is how you can install module with code:

$module = Module::getInstanceByName('module_name');
$module->install();
Edited by Krystian Podemski (see edit history)
  • Like 2
Link to comment
Share on other sites

  On 1/19/2015 at 8:01 AM, Krystian Podemski said:

 

You can check if required module is installed by simply adding this:

$this->dependencies = array('some_module_name');

to your module __construct method. User will not be able to install module before installing required module.

 

This is how you can install module with code:

$module = Module::getInstanceByName('module_name');
$module->install();
 

Thanks for your answer

With this suggestion I can send a message requiring them to install it. That can work but is it possible to install it for them? because that would be easier on the user.

Link to comment
Share on other sites

  On 1/19/2015 at 8:07 AM, Krystian Podemski said:

Yes, you can, just do not run code dependent on other module if module is not yet installed, check in __construct/getContent or other method if module is installed and if not install module using this little snippet from my previous post.

 

Thanks for your help! I am running code dependant on the prestashops cronjob module. And since not everyone has SSH access and/or a cronjob webservice availible this looked like the best solution

Link to comment
Share on other sites

  On 1/19/2015 at 11:17 AM, cristic said:

You also have to check if the module folder actually exists on the server.

 

No, there is no need to check this. There is need to check if (in this case) $module is Validate::isLoadedObject, checking for folder doesn't help at all because it's already done in getInstanceByName method.

Link to comment
Share on other sites

  On 1/19/2015 at 4:11 PM, Krystian Podemski said:

No, there is no need to check this. There is need to check if (in this case) $module is Validate::isLoadedObject, checking for folder doesn't help at all because it's already done in getInstanceByName method.

Yes, you are right.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...