API16

JInstallerFile/install

From Joomla! Documentation

< API16:JInstallerFile
Revision as of 17:38, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Custom install method <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> <...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

[Edit Descripton]

Template:Description:JInstallerFile/install

Syntax[edit]

install()


Returns[edit]

boolean True on success

Defined in[edit]

libraries/joomla/installer/adapters/file.php

Importing[edit]

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

Source Body[edit]

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');
        $this->set('name', $name);

        // Set element
        $manifestPath = $this->parent->getPath('manifest');
        $element = split(DS,$manifestPath);
        $element = $element[count($element) - 1];
        $element = preg_replace('/\.xml/', '', $element);
        $this->set('element', $element);

        // Get the component description
        $description = (string)$this->manifest->description;
        if ($description) {
                $this->parent->set('message', JText::_($description));
        } else {
                $this->parent->set('message', '');
        }


        //Check if the extension by the same name is already installed
        if ($this->extensionExistsInSystem($name)) {
                // Package with same name already exists
                $this->parent->abort(JText::_('Files').' '.JText::_($this->route).': '.JText::_('Another extension with name already exists.'));
                return false;
        }


        //Populate File and Folder List to copy
        $this->populateFilesAndFolderList();

        //Now that we have folder list, lets start creating them
        foreach ($this->folderList as $folder)
        {
                if (!JFolder::exists($folder))
                {

                        if (!$created = JFolder::create($folder))
                        {
                                JError::raiseWarning(1, JText::_('Files').' '.JText::_('Install').': '.JText::_('Failed to find source directory').': "'.$folder.'"');
                                // if installation fails, rollback
                                $this->parent->abort();
                                return false;
                        }

                        /*
                         * Since we created a directory and will want to remove it if we have to roll back
                         * the installation due to some errors, lets add it to the installation step stack
                         */
                        if ($created) {
                                $this->parent->pushStep(array ('type' => 'folder', 'path' => $folder));
                        }
                }

        }

        //Now that we have file list , lets start copying them
        $this->parent->copyFiles($this->fileList);

        // Parse optional tags
        $this->parent->parseLanguages($this->manifest->languages);

        // Add an entry to the extension table with a whole heap of defaults
        $row = & JTable::getInstance('extension');
        $row->set('name', $this->get('name'));
        $row->set('type', 'file');
        $row->set('element', $this->get('element'));
        $row->set('folder', ''); // There is no folder for files so leave it blank
        $row->set('enabled', 1);
        $row->set('protected', 0);
        $row->set('access', 0);
        $row->set('client_id', 0);
        $row->set('params', '');
        $row->set('system_data', '');
        $row->set('manifest_cache', '');
        if (!$row->store())
        {
                // Install failed, roll back changes
                $this->parent->abort(JText::_('Files').' '.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.'files'.DS.basename($this->parent->getPath('manifest'));
        if (!$this->parent->copyFiles(array($manifest), true))
        {
                // Install failed, rollback changes
                $this->parent->abort(JText::_('File').' '.JText::_('Install').': '.JText::_('COULD_NOT_COPY_SETUP_FILE'));
                return false;
        }
        return true;
}

[Edit See Also] Template:SeeAlso:JInstallerFile/install

Examples[edit]

<CodeExamplesForm />