Back to PackageAdapter class

Method finaliseInstall

protected void
finaliseInstall
()
Method to finalise the installation processing
Returns
  • void
Since
  • 3.4
-
  • \RuntimeException

Method finaliseInstall - Source code

/**
 * Method to finalise the installation processing
 *
 * @return  void
 *
 * @since   3.4
 * @throws  \RuntimeException
 */
protected function finaliseInstall()
{
    // Clobber any possible pending updates
    /** @var Update $update */
    $update = Table::getInstance('update');
    $uid = $update->find(array('element' => $this->element, 'type' => $this->type));
    if ($uid) {
        $update->delete($uid);
    }
    // Set the package ID for each of the installed extensions to track the relationship
    if (!empty($this->installedIds)) {
        $db = $this->db;
        $query = $db->getQuery(true)->update($db->quoteName('#__extensions'))->set($db->quoteName('package_id') . ' = :id')->whereIn($db->quoteName('extension_id'), $this->installedIds)->bind(':id', $this->extension->extension_id, ParameterType::INTEGER);
        try {
            $db->setQuery($query)->execute();
        } catch (ExecutionFailureException $e) {
            Log::add(Text::_('JLIB_INSTALLER_ERROR_PACK_SETTING_PACKAGE_ID'), Log::WARNING, 'jerror');
        }
    }
    // Lastly, we will copy the manifest file to its appropriate place.
    $manifest = array();
    $manifest['src'] = $this->parent->getPath('manifest');
    $manifest['dest'] = JPATH_MANIFESTS . '/packages/' . basename($this->parent->getPath('manifest'));
    if (!$this->parent->copyFiles(array($manifest), true)) {
        // Install failed, rollback changes
        throw new \RuntimeException(Text::sprintf('JLIB_INSTALLER_ABORT_COPY_SETUP', Text::_('JLIB_INSTALLER_' . strtoupper($this->route))));
    }
    // If there is a manifest script, let's copy it.
    if ($this->manifest_script) {
        // First, we have to create a folder for the script if one isn't present
        if (!file_exists($this->parent->getPath('extension_root'))) {
            if (!Folder::create($this->parent->getPath('extension_root'))) {
                throw new \RuntimeException(Text::sprintf('JLIB_INSTALLER_ABORT_CREATE_DIRECTORY', Text::_('JLIB_INSTALLER_' . $this->route), $this->parent->getPath('extension_root')));
            }
            /*
             * Since we created the extension directory and will want to remove it if
             * we have to roll back the installation, let's add it to the
             * installation step stack
             */
            $this->parent->pushStep(array('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
        }
        $path['src'] = $this->parent->getPath('source') . '/' . $this->manifest_script;
        $path['dest'] = $this->parent->getPath('extension_root') . '/' . $this->manifest_script;
        if ($this->parent->isOverwrite() || !file_exists($path['dest'])) {
            if (!$this->parent->copyFiles(array($path))) {
                // Install failed, rollback changes
                throw new \RuntimeException(Text::sprintf('JLIB_INSTALLER_ABORT_MANIFEST', Text::_('JLIB_INSTALLER_' . strtoupper($this->route))));
            }
        }
    }
}