2

How could you do programmatically what Joomla does when you install a plugin? Let's say, for simplicity's sake, that you have a plugin package file local with your Joomla instance.

A solution might look like one of:

  • a) You make a POST request to a Joomla endpoint with the package file that installs the plugin.

  • b) You write a shell script that both installs the package file's contents in the correct folder, and writes the required data to the db (more brittle this way).

1 Answer 1

3

Use Install model.

if (!defined('_JEXEC'))
{
    define('_JEXEC', 1);
    define('JPATH_BASE', realpath(__DIR__));
    require_once JPATH_BASE . '/includes/defines.php';
    require_once JPATH_BASE . '/includes/framework.php';
}

JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_installer/models', 'InstallerModel');
$input = JFactory::getApplication('site')->input;
$input->set('installtype', 'folder');
$input->set('install_directory', $path);
$model = JModelLegacy::getInstance('Install', 'InstallerModel', array('ignore_request' => true));
$model->install();

Where $path is path to extension installation files.

3
  • Thanks for this. This would work once I have access to the Joomla runtime. Do you know of any way this could be done externally, without access to that runtime?
    – steel
    Jul 26, 2018 at 13:24
  • If you need to run this in external script, add Joomla dependencies and define the application in JFactory::getApplication() call. I have updated the answer to reflect this. You may also look into making a CLI application.
    – Sharky
    Jul 27, 2018 at 8:47
  • You can create a new controller inside your component, and call it externally via GET/POST and pass the required details as paramteres. Jun 3, 2022 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.