Difference between revisions of "JInstallerPackage/install"
From Joomla! Documentation
< API16:JInstallerPackage
(New page: ===Description===
Custom install method
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>...) |
m (removing red link to edit, no existant pages) |
||
Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Syntax=== | ===Syntax=== | ||
Line 151: | Line 151: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
Line 166: | Line 166: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API16]] |
Revision as of 22:02, 13 May 2013
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 install method
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
install()
Returns[edit]
boolean True on success
Defined in[edit]
libraries/joomla/installer/adapters/package.php
Importing[edit]
jimport( 'joomla.installer.adapters.package' );
Source Body[edit]
function install()
{
// Get the extension manifest object
$this->manifest = $this->parent->getManifest();
// Set the extensions name
$name = (string)$this->manifest->packagename;
$name = JFilterInput::getInstance()->clean($name, 'cmd');
$this->set('name', $name);
// Get the component 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->packagename;
if (!empty($group))
{
// TODO: Remark this location
$this->parent->setPath('extension_root', JPATH_ROOT.DS.'libraries'.DS.implode(DS,explode('/',$group)));
}
else
{
$this->parent->abort(JText::_('Package').' '.JText::_('Install').': '.JText::_('No package 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::_('Package').' '.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')));
}
if ($folder = (string)$this->manifest->files->attributes()->folder) {
$source = $this->parent->getPath('source').DS.$folder;
}
else {
$source = $this->parent->getPath('source');
}
// Install all necessary files
if (count($this->manifest->files->children()))
{
foreach ($this->manifest->files->children() as $child)
{
$file = $source.DS.$child;
jimport('joomla.installer.helper');
if (is_dir($file))
{
// if its actually a directory then fill it up
$package = Array();
$package['dir'] = $file;
$package['type'] = JInstallerHelper::detectType($file);
}
else { // if its an archive
$package = JInstallerHelper::unpack($file);
}
$tmpInstaller = new JInstaller();
if (!$tmpInstaller->install($package['dir']))
{
$this->parent->abort(JText::_('Package').' '.JText::_('Install').': '.JText::_('There was an error installing an extension:') . basename($file));
return false;
}
}
}
else
{
$this->parent->abort(JText::_('Package').' '.JText::_('Install').': '.JText::_('There were no files to install!').print_r($this->manifest->files->children(), true));
return false;
}
// Parse optional tags
$this->parent->parseLanguages($this->manifest->languages);
$row = & JTable::getInstance('extension');
$row->name = $this->get('name');
$row->type = 'package';
$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::_('Package').' '.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.'packages'.DS.basename($this->parent->getPath('manifest'));
if (!$this->parent->copyFiles(array($manifest), true))
{
// Install failed, rollback changes
$this->parent->abort(JText::_('Package').' '.JText::_('Install').': '.JText::_('COULD_NOT_COPY_SETUP_FILE'));
return false;
}
return true;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
<CodeExamplesForm />