API16:JInstallerLibrary/install
From Joomla! Documentation
Description
Custom install method
<! removed transcluded page call, red link never existed >
Syntax
install()
Returns
boolean True on success
Defined in
libraries/joomla/installer/adapters/library.php
Importing
jimport( 'joomla.installer.adapters.library' );
Source Body
function install()
{
// Get the extension manifest object
$this->manifest = $this->parent->getManifest();
// Set the extensions name
$name = JFilterInput::getInstance()->clean((string)$this->manifest->name, 'string');
$element = str_replace('.xml','',basename($this->parent->getPath('manifest')));
$this->set('name', $name);
$this->set('element', $element);
$db = &$this->parent->getDbo();
$db->setQuery('SELECT extension_id FROM #__extensions WHERE type="library" AND element = "'. $element .'"');
$result = $db->loadResult();
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('library', $result);
}
else
{
// abort the install, no upgrade possible
$this->parent->abort(JText::_('Library').' '. JText::_('Install').': '.JText::_('Library already installed'));
return false;
}
}
// Get the libraries description
$description = (string)$this->manifest->description;
if ($description) {
$this->parent->set('message', JText::_($description));
}
else {
$this->parent->set('message', '');
}
// Set the installation path
$group = (string)$this->manifest->libraryname;
if ( ! $group) {
$this->parent->abort(JText::_('Library').' '.JText::_('Install').': '.JText::_('No library file specified'));
return false;
}
else
{
$this->parent->setPath('extension_root', JPATH_ROOT.DS.'libraries'.DS.implode(DS,explode('/',$group)));
}
// 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::_('Library').' '.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($this->manifest->files, -1) === false)
{
// Install failed, roll back changes
$this->parent->abort();
return false;
}
// Parse optional tags
$this->parent->parseLanguages($this->manifest->languages);
$row = & JTable::getInstance('extension');
$row->name = $this->get('name');
$row->type = 'library';
$row->element = $this->get('element');
$row->folder = ''; // There is no folder for modules
$row->enabled = 1;
$row->protected = 0;
$row->access = 1;
$row->client_id = 0;
$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::_('Library').' '.JText::_('Install').': '.$db->stderr(true));
return false;
}
// Lastly, we will copy the manifest file to its appropriate place.
$manifest = Array();
$manifest['src'] = $this->parent->getPath('manifest');
$manifest['dest'] = JPATH_MANIFESTS.DS.'libraries'.DS.basename($this->parent->getPath('manifest'));
if (!$this->parent->copyFiles(array($manifest), true))
{
// Install failed, rollback changes
$this->parent->abort(JText::_('Library').' '.JText::_('Install').': '.JText::_('COULD_NOT_COPY_SETUP_FILE'));
return false;
}
return $row->get('extension_id');
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples