/**
* Discovered package installation method
*
* @param integer $eid Extension ID
*
* @return boolean True if successful
*
* @since 3.1
*/
public function discover_install($eid = null)
{
if (!$eid) {
$this->abort(Text::_('JLIB_INSTALLER_ABORT_EXTENSIONNOTVALID'));
return false;
}
if (!$this->extension->load($eid)) {
$this->abort(Text::_('JLIB_INSTALLER_ABORT_LOAD_DETAILS'));
return false;
}
if ($this->extension->state != -1) {
$this->abort(Text::_('JLIB_INSTALLER_ABORT_ALREADYINSTALLED'));
return false;
}
// Load the adapter(s) for the install manifest
$type = $this->extension->type;
$params = array('extension' => $this->extension, 'route' => 'discover_install');
$adapter = $this->loadAdapter($type, $params);
if (!\is_object($adapter)) {
return false;
}
if (!method_exists($adapter, 'discover_install') || !$adapter->getDiscoverInstallSupported()) {
$this->abort(Text::sprintf('JLIB_INSTALLER_ERROR_DISCOVER_INSTALL_UNSUPPORTED', $type));
return false;
}
// The adapter needs to prepare itself
if (method_exists($adapter, 'prepareDiscoverInstall')) {
try {
$adapter->prepareDiscoverInstall();
} catch (\RuntimeException $e) {
$this->abort($e->getMessage());
return false;
}
}
// Add the languages from the package itself
if (method_exists($adapter, 'loadLanguage')) {
$adapter->loadLanguage();
}
// Fire the onExtensionBeforeInstall event.
PluginHelper::importPlugin('extension');
Factory::getApplication()->triggerEvent('onExtensionBeforeInstall', array('method' => 'discover_install', 'type' => $this->extension->get('type'), 'manifest' => null, 'extension' => $this->extension->get('extension_id')));
// Run the install
$result = $adapter->discover_install();
// Fire the onExtensionAfterInstall
Factory::getApplication()->triggerEvent('onExtensionAfterInstall', array('installer' => clone $this, 'eid' => $result));
if ($result !== false) {
// Refresh versionable assets cache
Factory::getApplication()->flushAssets();
return true;
}
return false;
}