Back to ComponentAdapter class

Method prepareDiscoverInstall

public void
prepareDiscoverInstall
()
Prepares the adapter for a discover_install task
Returns
  • void
Since
  • 3.4
-
  • \RuntimeException

Method prepareDiscoverInstall - Source code

/**
 * Prepares the adapter for a discover_install task
 *
 * @return  void
 *
 * @since   3.4
 * @throws  \RuntimeException
 */
public function prepareDiscoverInstall()
{
    // Need to find to find where the XML file is since we don't store this normally
    $client = ApplicationHelper::getClientInfo($this->extension->client_id);
    $short_element = str_replace('com_', '', $this->extension->element);
    $manifestPath = $client->path . '/components/' . $this->extension->element . '/' . $short_element . '.xml';
    $this->parent->manifest = $this->parent->isManifest($manifestPath);
    $this->parent->setPath('manifest', $manifestPath);
    $this->parent->setPath('source', $client->path . '/components/' . $this->extension->element);
    $this->parent->setPath('extension_root', $this->parent->getPath('source'));
    $this->setManifest($this->parent->getManifest());
    $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();
    $stored = false;
    try {
        $this->extension->store();
        $stored = true;
    } catch (\RuntimeException $e) {
        $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);
            }
        }
    }
    if (!$stored) {
        try {
            $this->extension->store();
        } catch (\RuntimeException $e) {
            throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_COMP_DISCOVER_STORE_DETAILS'), $e->getCode(), $e);
        }
    }
}