Back to LanguageAdapter class

Method _install

protected bool|int
_install
(mixed $cname, mixed $basePath, mixed $clientId, mixed &$element)
Install function that is designed to handle individual clients
Parameters
  • string $cname Cname @todo: not used
  • string $basePath The base name.
  • int $clientId The client id.
  • object & $element The XML element.
Returns
  • bool|int The extension ID on success, boolean false on failure
Since
  • 3.1

Method _install - Source code

/**
 * Install function that is designed to handle individual clients
 *
 * @param   string   $cname     Cname @todo: not used
 * @param   string   $basePath  The base name.
 * @param   integer  $clientId  The client id.
 * @param   object   &$element  The XML element.
 *
 * @return  boolean|integer  The extension ID on success, boolean false on failure
 *
 * @since   3.1
 */
protected function _install($cname, $basePath, $clientId, &$element)
{
    $this->setManifest($this->parent->getManifest());
    // Get the language name
    // Set the extensions name
    $this->name = InputFilter::getInstance()->clean((string) $this->getManifest()->name, 'string');
    // Get the Language tag [ISO tag, eg. en-GB]
    $tag = (string) $this->getManifest()->tag;
    // Check if we found the tag - if we didn't, we may be trying to install from an older language package
    if (!$tag) {
        $this->parent->abort(Text::sprintf('JLIB_INSTALLER_ABORT', Text::_('JLIB_INSTALLER_ERROR_NO_LANGUAGE_TAG')));
        return false;
    }
    $this->tag = $tag;
    // Set the language installation path
    $this->parent->setPath('extension_site', $basePath . '/language/' . $tag);
    // Do we have a meta file in the file list?  In other words... is this a core language pack?
    if ($element && \count($element->children())) {
        $files = $element->children();
        foreach ($files as $file) {
            if ((string) $file->attributes()->file === 'meta') {
                $this->core = true;
                break;
            }
        }
    }
    // If the language directory does not exist, let's create it
    $created = false;
    if (!file_exists($this->parent->getPath('extension_site'))) {
        if (!($created = Folder::create($this->parent->getPath('extension_site')))) {
            $this->parent->abort(Text::sprintf('JLIB_INSTALLER_ABORT', Text::sprintf('JLIB_INSTALLER_ERROR_CREATE_FOLDER_FAILED', $this->parent->getPath('extension_site'))));
            return false;
        }
    } else {
        // Look for an update function or update tag
        $updateElement = $this->getManifest()->update;
        // Upgrade manually set or update tag detected
        if ($updateElement || $this->parent->isUpgrade()) {
            // Transfer control to the update function
            return $this->update();
        } elseif (!$this->parent->isOverwrite()) {
            // Overwrite is set
            // We didn't have overwrite set, find an update function or find an update tag so lets call it safe
            if (file_exists($this->parent->getPath('extension_site'))) {
                // If the site exists say so.
                Log::add(Text::sprintf('JLIB_INSTALLER_ABORT', Text::sprintf('JLIB_INSTALLER_ERROR_FOLDER_IN_USE', $this->parent->getPath('extension_site'))), Log::WARNING, 'jerror');
            } elseif (file_exists($this->parent->getPath('extension_administrator'))) {
                // If the admin exists say so.
                Log::add(Text::sprintf('JLIB_INSTALLER_ABORT', Text::sprintf('JLIB_INSTALLER_ERROR_FOLDER_IN_USE', $this->parent->getPath('extension_administrator'))), Log::WARNING, 'jerror');
            } else {
                // If the api exists say so.
                Log::add(Text::sprintf('JLIB_INSTALLER_ABORT', Text::sprintf('JLIB_INSTALLER_ERROR_FOLDER_IN_USE', $this->parent->getPath('extension_api'))), Log::WARNING, 'jerror');
            }
            return false;
        }
    }
    /*
     * If we created the language directory we will want to remove it if we
     * have to roll back the installation, so let's add it to the installation
     * step stack
     */
    if ($created) {
        $this->parent->pushStep(array('type' => 'folder', 'path' => $this->parent->getPath('extension_site')));
    }
    // Copy all the necessary files
    if ($this->parent->parseFiles($element) === false) {
        // Install failed, rollback changes
        $this->parent->abort();
        return false;
    }
    // Parse optional tags
    $this->parent->parseMedia($this->getManifest()->media);
    // Get the language description
    $description = (string) $this->getManifest()->description;
    if ($description) {
        $this->parent->set('message', Text::_($description));
    } else {
        $this->parent->set('message', '');
    }
    // Add an entry to the extension table with a whole heap of defaults
    $row = Table::getInstance('extension');
    $row->set('name', $this->name);
    $row->set('type', 'language');
    $row->set('element', $this->tag);
    $row->set('changelogurl', (string) $this->getManifest()->changelogurl);
    // There is no folder for languages
    $row->set('folder', '');
    $row->set('enabled', 1);
    $row->set('protected', 0);
    $row->set('access', 0);
    $row->set('client_id', $clientId);
    $row->set('params', $this->parent->getParams());
    $row->set('manifest_cache', $this->parent->generateManifestCache());
    if (!$row->check() || !$row->store()) {
        // Install failed, roll back changes
        $this->parent->abort(Text::sprintf('JLIB_INSTALLER_ABORT', $row->getError()));
        return false;
    }
    if ((int) $clientId === 0) {
        $this->createContentLanguage($this->tag);
    }
    // Clobber any possible pending updates
    /** @var Update $update */
    $update = Table::getInstance('update');
    $uid = $update->find(array('element' => $this->tag, 'type' => 'language', 'folder' => ''));
    if ($uid) {
        $update->delete($uid);
    }
    // Clean installed languages cache.
    Factory::getCache()->clean('com_languages');
    return $row->get('extension_id');
}