/**
* Method to store the extension to the database
*
* @return void
*
* @since 3.4
* @throws \RuntimeException
*/
protected function storeExtension()
{
// Discover installs are stored a little differently
if ($this->route === 'discover_install') {
$manifest_details = Installer::parseXMLInstallFile($this->parent->getPath('manifest'));
$this->extension->manifest_cache = json_encode($manifest_details);
$this->extension->state = 0;
$this->extension->name = $manifest_details['name'];
$this->extension->enabled = 1;
$this->extension->params = $this->parent->getParams();
if (!$this->extension->store()) {
// Install failed, roll back changes
throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_MOD_DISCOVER_STORE_DETAILS'));
}
return;
}
// Was there a module already installed with the same name?
if ($this->currentExtensionId) {
if (!$this->parent->isOverwrite()) {
// Install failed, roll back changes
throw new \RuntimeException(Text::sprintf('JLIB_INSTALLER_ABORT_MOD_INSTALL_ALLREADY_EXISTS', Text::_('JLIB_INSTALLER_' . $this->route), $this->name));
}
// Load the entry and update the manifest_cache
$this->extension->load($this->currentExtensionId);
// Update name
$this->extension->name = $this->name;
// Update namespace
$this->extension->namespace = (string) $this->manifest->namespace;
// Update changelogurl
$this->extension->changelogurl = (string) $this->manifest->changelogurl;
// Update manifest
$this->extension->manifest_cache = $this->parent->generateManifestCache();
if (!$this->extension->store()) {
// Install failed, roll back changes
throw new \RuntimeException(Text::sprintf('JLIB_INSTALLER_ABORT_MOD_ROLLBACK', Text::_('JLIB_INSTALLER_' . $this->route), $this->extension->getError()));
}
} else {
$this->extension->name = $this->name;
$this->extension->type = 'module';
$this->extension->element = $this->element;
$this->extension->namespace = (string) $this->manifest->namespace;
$this->extension->changelogurl = $this->changelogurl;
// There is no folder for modules
$this->extension->folder = '';
$this->extension->enabled = 1;
$this->extension->protected = 0;
$this->extension->access = $this->clientId == 1 ? 2 : 0;
$this->extension->client_id = $this->clientId;
$this->extension->params = $this->parent->getParams();
// Update the manifest cache for the entry
$this->extension->manifest_cache = $this->parent->generateManifestCache();
if (!$this->extension->store()) {
// Install failed, roll back changes
throw new \RuntimeException(Text::sprintf('JLIB_INSTALLER_ABORT_MOD_ROLLBACK', Text::_('JLIB_INSTALLER_' . $this->route), $this->extension->getError()));
}
// Since we have created a module item, we add it to the installation step stack
// so that if we have to rollback the changes we can undo it.
$this->parent->pushStep(array('type' => 'extension', 'extension_id' => $this->extension->extension_id));
// Create unpublished module
$name = preg_replace('#[\\*?]#', '', Text::_($this->name));
/** @var \Joomla\CMS\Table\Module $module */
$module = Table::getInstance('module');
$module->title = $name;
$module->content = '';
$module->module = $this->element;
$module->access = '1';
$module->showtitle = '1';
$module->params = '';
$module->client_id = $this->clientId;
$module->language = '*';
$module->store();
}
}