/**
* Custom update method
*
* @return boolean True on success, false on failure
*
* @since 3.1
*/
public function update()
{
$xml = $this->parent->getManifest();
$this->setManifest($xml);
$cname = $xml->attributes()->client;
// Attempt to map the client to a base path
$client = ApplicationHelper::getClientInfo($cname, true);
if ($client === null || empty($cname) && $cname !== 0) {
$this->parent->abort(Text::sprintf('JLIB_INSTALLER_ABORT', Text::sprintf('JLIB_INSTALLER_ERROR_UNKNOWN_CLIENT_TYPE', $cname)));
return false;
}
$basePath = $client->path;
$clientId = $client->id;
// Get the language name
// Set the extensions name
$name = (string) $this->getManifest()->name;
$name = InputFilter::getInstance()->clean($name, 'string');
$this->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(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 (\count($xml->files->children())) {
foreach ($xml->files->children() as $file) {
if ((string) $file->attributes()->file === 'meta') {
$this->core = true;
break;
}
}
}
// Copy all the necessary files
if ($this->parent->parseFiles($xml->files) === false) {
// Install failed, rollback changes
$this->parent->abort();
return false;
}
// Parse optional tags
$this->parent->parseMedia($xml->media);
// Get the language description and set it as message
$this->parent->set('message', (string) $xml->description);
/**
* ---------------------------------------------------------------------------------------------
* Finalization and Cleanup Section
* ---------------------------------------------------------------------------------------------
*/
// Clobber any possible pending updates
$update = Table::getInstance('update');
$uid = $update->find(array('element' => $this->tag, 'type' => 'language', 'client_id' => $clientId));
if ($uid) {
$update->delete($uid);
}
// Update an entry to the extension table
$row = Table::getInstance('extension');
$eid = $row->find(array('element' => $this->tag, 'type' => 'language', 'client_id' => $clientId));
if ($eid) {
$row->load($eid);
} else {
// Set the defaults
// There is no folder for language
$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('name', $this->name);
$row->set('type', 'language');
$row->set('element', $this->tag);
$row->set('manifest_cache', $this->parent->generateManifestCache());
$row->set('changelogurl', (string) $this->getManifest()->changelogurl);
// Clean installed languages cache.
Factory::getCache()->clean('com_languages');
if (!$row->check() || !$row->store()) {
// Install failed, roll back changes
$this->parent->abort(Text::sprintf('JLIB_INSTALLER_ABORT', $row->getError()));
return false;
}
if ($clientId === 0) {
$this->createContentLanguage($this->tag);
}
return $row->get('extension_id');
}