Actions

API16

JInstallerPackage/install

From Joomla! Documentation

< API16:JInstallerPackage
Revision as of 22:02, 13 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
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/package.php

Importing

jimport( 'joomla.installer.adapters.package' );

Source Body

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

<CodeExamplesForm />