API16

JInstallerLanguage/update

From Joomla! Documentation

< API16:JInstallerLanguage

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Custom update method


<! removed transcluded page call, red link never existed >

Syntax[edit]

update()


Returns[edit]

boolean True on success, false on failure

Defined in[edit]

libraries/joomla/installer/adapters/language.php

Importing[edit]

jimport( 'joomla.installer.adapters.language' );

Source Body[edit]

public function update()
{
        $xml = &$this->parent->getManifest();

        $this->manifest = $xml;

        $cname          = $xml->attributes()->client;

        // Attempt to map the client to a base path
        jimport('joomla.application.helper');
        $client = &JApplicationHelper::getClientInfo($cname, true);
        if ($client === null || (empty($cname) && $cname !== 0))
        {
                $this->parent->abort(JText::sprintf('Instr_Abort', JText::sprintf('Instr_Error_Unknown_client_type', $cname)));
                return false;
        }
        $basePath = $client->path;
        $clientId = $client->id;

        // Get the language name
        // Set the extensions name
        $name = (string)$this->manifest->name;
        $name = JFilterInput::getInstance()->clean($name, 'cmd');
        $this->set('name', $name);

        // Get the Language tag [ISO tag, eg. en-GB]
        $tag = (string)$xml->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(JText::sprintf('Instr_Abort', JText::_('Instr_Error_No_Language_Tag')));
                return false;
        }

        $this->set('tag', $tag);
        $folder = $tag;

        // Set the language installation path
        $this->parent->setPath('extension_site', $basePath.DS.'language'.DS.$this->get('tag'));

        // Do we have a meta file in the file list?  In other words... is this a core language pack?
        if (count($xml->files->children()))
        {
                foreach ($xml->files->children() as $file)
                {
                        if ((string)$file->attributes()->file == 'meta')
                        {
                                $this->_core = true;
                                break;
                        }
                }
        }

        // Either we are installing a core pack or a core pack must exist for the language we are installing.
        if (!$this->_core)
        {
                if (!JFile::exists($this->parent->getPath('extension_site').DS.$this->get('tag').'.xml'))
                {
                        $this->parent->abort(JText::sprintf('Instr_Abort', JText::sprintf('Instr_Error_No_core_language', $this->get('tag'))));
                        return false;
                }
        }

        // Copy all the necessary files
        if ($this->parent->parseFiles($xml->files) === false)
        {
                // Install failed, rollback changes
                $this->parent->abort();
                return false;
        }

        // Copy all the necessary font files to the common pdf_fonts directory
        $this->parent->setPath('extension_site', $basePath.DS.'language'.DS.'pdf_fonts');
        $overwrite = $this->parent->setOverwrite(true);
        if ($this->parent->parseFiles($xml->fonts) === false)
        {
                // Install failed, rollback changes
                $this->parent->abort();
                return false;
        }
        $this->parent->setOverwrite($overwrite);

        // Get the language description and set it as message
        $this->parent->set('message', (string)$xml->description);

        // Clobber any possible pending updates
        $update = &JTable::getInstance('update');
        $uid = $update->find(Array('element'=>$this->get('tag'),
                                                        'type'=>'language',
                                                        'client_id'=>$clientId));
        if ($uid)
        {
                $update->delete($uid);
        }

        // Update an entry to the extension table
        $row = & JTable::getInstance('extension');
        $eid = $row->find(Array('element'=>strtolower($this->get('tag')),
                                        'type'=>'language'));
        if ($eid) {
                $row->load($eid);
        }
        else
        {
                // set the defaults
                $row->set('folder', ''); // There is no folder for language
                $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('name', $this->get('name'));
        $row->set('type', 'language');
        $row->set('element', $this->get('tag'));
        $row->set('manifest_cache', $this->parent->generateManifestCache());

        if (!$row->store())
        {
                // Install failed, roll back changes
                $this->parent->abort(JText::sprintf('Instr_Abort', $db->getErrorMsg()));
                return false;
        }

        // And now we run the postflight
        ob_start();
        ob_implicit_flush(false);
        if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'postflight'))
        {
                $this->parent->manifestClass->postflight('update', $this);
        }
        $msg .= ob_get_contents(); // append messages
        ob_end_clean();
        if ($msg != '') {
                $this->parent->set('extension_message', $msg);
        }

        return $row->get('extension_id');
}


<! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]