Reputation: 499
Normally when you want to uninstall or install a component, package, plugin or module, you normally do this manually from within the Joomla admin interface.
In this case I´m looking for a way to programmatically uninstall and install a component or package directly from PHP (within the Joomla framework), probably from a system plugin.
So basically I want to initiate the uninstall and install process of a package programmatically, so that all the components, modules, plugins etc. are uninstalled and installed, the same way the would normally be unstalled and installed by uninstalling and installing the package manually from within Joomla admin.
Can someone give me a hint to how I would accomplish this, preferably using Joomla´s core class specific functions.
I have tried to find information about this by searching various Joomla documentation, but no luck so far.
UPDATE I have located the core model files that are used when installing and uninstalling extensions from Joomla admin.
I have found a function that I might be able to use for uninstalling extension(s) from a plugin, in this class file: /administrator/components/com_installer/models/manage.php
The function is: "remove($eid = array())" as part of the class: "InstallerModelManage" which extends "InstallerModel"
I have also found a function to use for installing extension(s) from a plugin, in this class file: /administrator/components/com_installer/models/install.php
The function is: "install()" as part of the class: "InstallerModelInstall" which extends "JModelLegacy"
Now I only need to find the best (correct) way to include these functions in my plugin file so that I can execute remove($eid = array()) and install()
Upvotes: 1
Views: 718
Reputation: 3080
This is how you call it.
JModelLegacy::addIncludePath(JPATH_ROOT . '/administrator/components/com_installer/models');
$model = JModelLegacy::getInstance('Install', 'InstallerModel');
$model->install();
But It will take some data from input. So you have to prepare it BEFORE
$input = JFactory::getApplication()->input;
$input->set('installtype', 'url');
$input->set('install_url', 'path/to/instalation/asyou/would/enter/it/in/installation/interface');
Upvotes: 1