/**
* 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_TPL_DISCOVER_STORE_DETAILS'));
}
return;
}
// Was there a template already installed with the same name?
if ($this->currentExtensionId) {
if (!$this->parent->isOverwrite()) {
// Install failed, roll back changes
throw new \RuntimeException(Text::_('JLIB_INSTALLER_ABORT_TPL_INSTALL_ALREADY_INSTALLED'));
}
// Load the entry and update the manifest_cache
$this->extension->load($this->currentExtensionId);
} else {
$this->extension->type = 'template';
$this->extension->element = $this->element;
// There is no folder for templates
$this->extension->folder = '';
$this->extension->enabled = 1;
$this->extension->protected = 0;
$this->extension->access = 1;
$this->extension->client_id = $this->clientId;
$this->extension->params = $this->parent->getParams();
$this->extension->changelogurl = $this->changelogurl;
}
// Name might change in an update
$this->extension->name = $this->name;
// Update the manifest cache for the entry
$this->extension->manifest_cache = $this->parent->generateManifestCache();
$this->extension->changelogurl = $this->changelogurl;
if (!$this->extension->store()) {
// Install failed, roll back changes
throw new \RuntimeException(Text::sprintf('JLIB_INSTALLER_ABORT_ROLLBACK', Text::_('JLIB_INSTALLER_' . strtoupper($this->route)), $this->extension->getError()));
}
}