Back to ComponentAdapter class

Method storeExtension

protected void
storeExtension
(mixed $deleteExisting = false)
Method to store the extension to the database
Parameters
  • bool $deleteExisting Should I try to delete existing records of the same component?
Returns
  • void
Since
  • 3.4
-
  • \RuntimeException

Method storeExtension - Source code

/**
 * Method to store the extension to the database
 *
 * @param   bool  $deleteExisting  Should I try to delete existing records of the same component?
 *
 * @return  void
 *
 * @since   3.4
 * @throws  \RuntimeException
 */
protected function storeExtension($deleteExisting = false)
{
    // The extension is stored during prepareDiscoverInstall for discover installs
    if ($this->route === 'discover_install') {
        return;
    }
    // Add or update an entry to the extension table
    $this->extension->name = $this->name;
    $this->extension->type = 'component';
    $this->extension->element = $this->element;
    $this->extension->changelogurl = $this->changelogurl;
    // If we are told to delete existing extension entries then do so.
    if ($deleteExisting) {
        $name = $this->extension->name;
        $type = $this->extension->type;
        $element = $this->extension->element;
        // Try to delete existing failed records before retrying
        $db = $this->db;
        $query = $db->getQuery(true)->select($db->quoteName('extension_id'))->from($db->quoteName('#__extensions'))->where([$db->quoteName('name') . ' = :name', $db->quoteName('type') . ' = :type', $db->quoteName('element') . ' = :element'])->bind(':name', $name)->bind(':type', $type)->bind(':element', $element);
        $db->setQuery($query);
        $extension_ids = $db->loadColumn();
        if (!empty($extension_ids)) {
            foreach ($extension_ids as $eid) {
                // Remove leftover admin menus for this extension ID
                $this->_removeAdminMenus($eid);
                // Remove the extension record itself
                /** @var Extension $extensionTable */
                $extensionTable = Table::getInstance('extension');
                $extensionTable->delete($eid);
            }
        }
    }
    // Namespace is optional
    if (isset($this->manifest->namespace)) {
        $this->extension->namespace = (string) $this->manifest->namespace;
    }
    // If there is not already a row, generate a heap of defaults
    if (!$this->currentExtensionId) {
        $this->extension->folder = '';
        $this->extension->enabled = 1;
        $this->extension->protected = 0;
        $this->extension->access = 0;
        $this->extension->client_id = 1;
        $this->extension->params = $this->parent->getParams();
    }
    $this->extension->manifest_cache = $this->parent->generateManifestCache();
    $couldStore = $this->extension->store();
    if (!$couldStore && $deleteExisting) {
        // Install failed, roll back changes
        throw new \RuntimeException(Text::sprintf('JLIB_INSTALLER_ABORT_COMP_INSTALL_ROLLBACK', $this->extension->getError()));
    }
    if (!$couldStore && !$deleteExisting) {
        // Maybe we have a failed installation (e.g. timeout). Let's retry after deleting old records.
        $this->storeExtension(true);
    }
}