Jump to content

Installing modules via code


jsmit2
 Share

Recommended Posts

Does anyone know if it is possible to install a module that is on the server but not installed, trough another modules code?. I want to install a modules wich my module depends on.

 

Any help would be appreciated.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More