API15:JInstallerPlugin/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
Description:JInstallerPlugin/install
Syntax
install()
Returns
boolean True on success
Defined in
libraries/joomla/installer/adapters/plugin.php
Importing
jimport( 'joomla.installer.adapters.plugin' );
Source Body
function install() { // Get a database connector object $db =& $this->parent->getDBO(); // Get the extension manifest object $manifest =& $this->parent->getManifest(); $this->manifest =& $manifest->document; // Set the extensions name $name =& $this->manifest->getElementByPath('name'); $name = JFilterInput::clean($name->data(), 'string'); $this->set('name', $name); // Get the component description $description = & $this->manifest->getElementByPath('description'); if (is_a($description, 'JSimpleXMLElement')) { $this->parent->set('message', $description->data()); } else { $this->parent->set('message', '' ); } /* * Backward Compatability * @todo Deprecate in future version */ $type = $this->manifest->attributes('type'); // Set the installation path $element =& $this->manifest->getElementByPath('files'); if (is_a($element, 'JSimpleXMLElement') && count($element->children())) { $files = $element->children(); foreach ($files as $file) { if ($file->attributes($type)) { $pname = $file->attributes($type); break; } } } $group = $this->manifest->attributes('group'); if (!empty ($pname) && !empty($group)) { $this->parent->setPath('extension_root', JPATH_ROOT.DS.'plugins'.DS.$group); } else { $this->parent->abort(JText::_('Plugin').' '.JText::_('Install').': '.JText::_('No plugin file specified')); return false; } // If the plugin 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::_('Plugin').' '.JText::_('Install').': '.JText::_('Failed to create directory').': "'.$this->parent->getPath('extension_root').'"'); return false; } } /* * If we created the plugin 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 necessary files if ($this->parent->parseFiles($element, -1) === false) { // Install failed, roll back changes $this->parent->abort(); return false; } // Parse optional tags -- media and language files for plugins go in admin app $this->parent->parseMedia($this->manifest->getElementByPath('media'), 1); $this->parent->parseLanguages($this->manifest->getElementByPath('languages'), 1); // Check to see if a plugin by the same name is already installed $query = 'SELECT `id`' . ' FROM `#__plugins`' . ' WHERE folder = '.$db->Quote($group) . ' AND element = '.$db->Quote($pname); $db->setQuery($query); if (!$db->Query()) { // Install failed, roll back changes $this->parent->abort(JText::_('Plugin').' '.JText::_('Install').': '.$db->stderr(true)); return false; } $id = $db->loadResult(); // Was there a module already installed with the same name? if ($id) { if (!$this->parent->getOverwrite()) { // Install failed, roll back changes $this->parent->abort(JText::_('Plugin').' '.JText::_('Install').': '.JText::_('Plugin').' "'.$pname.'" '.JText::_('already exists!')); return false; } } else { $row =& JTable::getInstance('plugin'); $row->name = $this->get('name'); $row->ordering = 0; $row->folder = $group; $row->iscore = 0; $row->access = 0; $row->client_id = 0; $row->element = $pname; $row->params = $this->parent->getParams(); // Editor plugins are published by default if ($group == 'editors') { $row->published = 1; } if (!$row->store()) { // Install failed, roll back changes $this->parent->abort(JText::_('Plugin').' '.JText::_('Install').': '.$db->stderr(true)); return false; } // Since we have created a plugin item, we add it to the installation step stack // so that if we have to rollback the changes we can undo it. $this->parent->pushStep(array ('type' => 'plugin', 'id' => $row->id)); } // Lastly, we will copy the manifest file to its appropriate place. if (!$this->parent->copyManifest(-1)) { // Install failed, rollback changes $this->parent->abort(JText::_('Plugin').' '.JText::_('Install').': '.JText::_('Could not copy setup file')); return false; } // Load plugin language file $lang =& JFactory::getLanguage(); $lang->load('plg_'.$group.'_'.$pname); return true; }
[Edit See Also] SeeAlso:JInstallerPlugin/install
Examples
<CodeExamplesForm />
