API16:JInstallerTemplate/install
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Custom install method
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
install()
Returns
boolean True on success
Defined in
libraries/joomla/installer/adapters/template.php
Importing
jimport( 'joomla.installer.adapters.template' );
Source Body
public function install() { $xml = $this->parent->getManifest(); // Get the client application target if ($cname = (string)$xml->attributes()->client) { // Attempt to map the client to a base path jimport('joomla.application.helper'); $client = &JApplicationHelper::getClientInfo($cname, true); if ($client === false) { $this->parent->abort(JText::_('Template').' '.JText::_('Install').': '.JText::_('Unknown client type').' ['.$cname.']'); return false; } $basePath = $client->path; $clientId = $client->id; } else { // No client attribute was found so we assume the site as the client $cname = 'site'; $basePath = JPATH_SITE; $clientId = 0; } // Set the extensions name $name = JFilterInput::getInstance()->clean((string)$xml->name, 'cmd'); $element = strtolower(str_replace(" ", "_", $name)); $this->set('name', $name); $this->set('element',$element); $db = &$this->parent->getDbo(); $db->setQuery('SELECT extension_id FROM #__extensions WHERE type="template" AND element = "'. $element .'"'); $result = $db->loadResult(); // TODO: Rewrite this! We shouldn't uninstall a template, we should back up the params as well if ($result) { // already installed, can we upgrade? if ($this->parent->getOverwrite() || $this->parent->getUpgrade()) { // we can upgrade, so uninstall the old one $installer = new JInstaller(); // we don't want to compromise this instance! $installer->uninstall('template', $result); } else { // abort the install, no upgrade possible $this->parent->abort(JText::_('Template').' '.JText::_('Install').': '.JText::_('Template already installed')); return false; } } // Set the template root path $this->parent->setPath('extension_root', $basePath.DS.'templates'.DS.$element); /* * If the template directory already exists, then we will assume that the template is already * installed or another template is using that directory. */ if (file_exists($this->parent->getPath('extension_root')) && !$this->parent->getOverwrite()) { JError::raiseWarning(100, JText::_('Template').' '.JText::_('Install').': '.JText::_('ANOTHER_TEMPLATE_IS_ALREADY_USING_DIRECTORY').': "'.$this->parent->getPath('extension_root').'"'); return false; } // If the template directory does not exist, lets create it $created = false; if (!file_exists($this->parent->getPath('extension_root'))) { if (!$created = JFolder::create($this->parent->getPath('extension_root'))) { $this->parent->abort(JText::_('Template').' '.JText::_('Install').': '.JText::_('FAILED_TO_CREATE_DIRECTORY').' "'.$this->parent->getPath('extension_root').'"'); return false; } } // If we created the template directory and will want to remove it if we have to roll back // the installation, lets add it to the installation step stack if ($created) { $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root'))); } // Copy all the necessary files if ($this->parent->parseFiles($xml->files, -1) === false) { // Install failed, rollback changes $this->parent->abort(); return false; } if ($this->parent->parseFiles($xml->images, -1) === false) { // Install failed, rollback changes $this->parent->abort(); return false; } if ($this->parent->parseFiles($xml->css, -1) === false) { // Install failed, rollback changes $this->parent->abort(); return false; } // Parse optional tags $this->parent->parseFiles($xml->media, $clientId); $this->parent->parseLanguages($xml->languages, $clientId); // Get the template description $this->parent->set('message', JText::_((string)$xml->description)); // Lastly, we will copy the manifest file to its appropriate place. if (!$this->parent->copyManifest(-1)) { // Install failed, rollback changes $this->parent->abort(JText::_('Template').' '.JText::_('Install').': '.JText::_('COULD_NOT_COPY_SETUP_FILE')); return false; } $row = & JTable::getInstance('extension'); $row->name = $this->get('name'); $row->type = 'template'; $row->element = $this->get('name'); $row->folder = ''; // There is no folder for templates $row->enabled = 1; $row->protected = 0; $row->access = 1; $row->client_id = $clientId; $row->params = $this->parent->getParams(); $row->custom_data = ''; // custom data $row->manifest_cache = $this->parent->generateManifestCache(); if (!$row->store()) { // Install failed, roll back changes $this->parent->abort(JText::_('Template').' '.JText::_('Install').': '.$db->stderr(true)); return false; } //insert record in #__template_styles $query = 'INSERT INTO #__template_styles'. ' (template,client_id,home,title,params)'. ' VALUE ('.$db->Quote($row->name).','. $db->Quote($clientId).',0,'. $db->Quote(JText::_('Default')).','. $db->Quote($row->params). ')'; $db->setQuery($query); $db->query(); return $row->get('extension_id'); }
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />
