Actions

API16

JInstallerComponent/discover install

From Joomla! Documentation

< API16:JInstallerComponent
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.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Contents

Syntax

discover_install()


Defined in

libraries/joomla/installer/adapters/component.php

Importing

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

Source Body

function discover_install()
{
        // Need to find to find where the XML file is since we don't store this normally
        $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id);
        $short_element = str_replace('com_', '', $this->parent->extension->element);
        $manifestPath = $client->path . DS . 'components'. DS . $this->parent->extension->element . DS . $short_element . '.xml';
        $this->parent->manifest = $this->parent->isManifest($manifestPath);
        $this->parent->setPath('manifest', $manifestPath);
        $this->parent->setPath('source', $client->path . DS . 'components'. DS . $this->parent->extension->element);
        $this->parent->setPath('extension_root', $this->parent->getPath('source'));
 
        $manifest_details = JApplicationHelper::parseXMLInstallFile($this->parent->getPath('manifest'));
        $this->parent->extension->manifest_cache = serialize($manifest_details);
        $this->parent->extension->state = 0;
        $this->parent->extension->name = $manifest_details['name'];
        $this->parent->extension->enabled = 1;
        $this->parent->extension->params = $this->parent->getParams();
        try {
                $this->parent->extension->store();
        } catch(JException $e) {
                JError::raiseWarning(101, JText::_('Component').' '.JText::_('Discover Install').': '.JText::_('Failed to store extension details'));
                return false;
        }
 
        // now we need to run any SQL it has, languages, media or menu stuff
 
        // Get a database connector object
        $db = &$this->parent->getDbo();
 
        // Get the extension manifest object
        $this->manifest = $this->parent->getManifest();
 
        // Set the extensions name
        $name = strtolower(JFilterInput::getInstance()->clean((string)$this->manifest->name, 'cmd'));
        $check=substr($name, 0, 4);
        if ($check="com_") {
        $name = substr($name, 4); }
        $element = strtolower('com_'.$name);
        $this->set('name', $name);
        $this->set('element', $element);
 
        // Get the component description
        $description = (string)$this->manifest->description;
        if ($description) {
                $this->parent->set('message', JText::_((string)$description));
        } else {
                $this->parent->set('message', '');
        }
 
        // Set the installation target paths
        $this->parent->setPath('extension_site', JPath::clean(JPATH_SITE.DS."components".DS.$this->get('element')));
        $this->parent->setPath('extension_administrator', JPath::clean(JPATH_ADMINISTRATOR.DS."components".DS.$this->get('element')));
        $this->parent->setPath('extension_root', $this->parent->getPath('extension_administrator')); // copy this as its used as a common base
 
        // Make sure that we have an admin element
        if ( ! $this->manifest->administration) {
                JError::raiseWarning(1, JText::_('Component').' '.JText::_('Install').': '.JText::_('The XML file did not contain an administration element'));
                return false;
        }
 
        // If there is an manifest class file, lets load it; we'll copy it later (don't have dest yet)
        $manifestScript = (string)$this->manifest->scriptfile;
        if ($manifestScript) {
                $manifestScriptFile = $this->parent->getPath('source').DS.$manifestScript;
                if (is_file($manifestScriptFile)) {
                        // load the file
                        include_once $manifestScriptFile;
                }
 
                // Set the class name
                $classname = $element.'InstallerScript';
                if (class_exists($classname)) {
                        // create a new instance
                        $this->parent->manifestClass = new $classname($this);
                        // and set this so we can copy it later
                        $this->set('manifest_script', $manifestScript);
                        // Note: if we don't find the class, don't bother to copy the file
                }
        }
 
        // run preflight if possible (since we know we're not an update)
        ob_start();
        ob_implicit_flush(false);
        if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'preflight')) {
                $this->parent->manifestClass->preflight('discover_install', $this);
        }
        $msg = ob_get_contents(); // create msg object; first use here
        ob_end_clean();
 
        // Normally we would copy files and create directories, lets skip to the optional files
        // Note: need to dereference things!
        // Parse optional tags
        $this->parent->parseMedia($this->manifest->media);
        // We don't do language because 1.6 suggests moving to extension based languages
        //$this->parent->parseLanguages($this->manifest->languages);
        //$this->parent->parseLanguages($this->manifest->administration->languages, 1);
 
        /*
         * Let's run the install queries for the component
         *      If Joomla 1.5 compatible, with discreet sql files - execute appropriate
         *      file for utf-8 support or non-utf-8 support
         */
        // try for Joomla 1.5 type queries
        // second argument is the utf compatible version attribute
        $utfresult = $this->parent->parseSQLFiles($this->manifest->install->sql);
        if ($utfresult === false) {
                // Install failed, rollback changes
                $this->parent->abort(JText::_('Component').' '.JText::_('Install').': '.JText::_('SQLERRORORFILE')." ".$db->stderr(true));
                return false;
        }
 
        // Time to build the admin menus
        $this->_buildAdminMenus();
 
        /*
         * If we have an install script, lets include it, execute the custom
         * install method, and append the return value from the custom install
         * method to the installation message.
         */
        // start legacy support
        if ($this->get('install_script')) {
                if (is_file($this->parent->getPath('extension_administrator').DS.$this->get('install_script'))) {
                        ob_start();
                        ob_implicit_flush(false);
                        require_once $this->parent->getPath('extension_administrator').DS.$this->get('install_script');
                        if (function_exists('com_install')) {
                                if (com_install() === false) {
                                        $this->parent->abort(JText::_('Component').' '.JText::_('Install').': '.JText::_('Custom install routine failure'));
                                        return false;
                                }
                        }
                        $msg .= ob_get_contents(); // append messages
                        ob_end_clean();
                }
        }
        // end legacy support
 
        // Start Joomla! 1.6
        ob_start();
        ob_implicit_flush(false);
        if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'discover_install')) {
                $this->parent->manifestClass->install($this);
        }
        $msg .= ob_get_contents(); // append messages
        ob_end_clean();
 
        // Clobber any possible pending updates
        $update = &JTable::getInstance('update');
        $uid = $update->find(Array('element'=>$this->get('element'),
                                                        'type'=>'component',
                                                        'client_id'=>'',
                                                        'folder'=>''));
        if ($uid) {
                $update->delete($uid);
        }
 
        // And now we run the postflight
        ob_start();
        ob_implicit_flush(false);
        if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'postflight')) {
                $this->parent->manifestClass->postflight('discover_install', $this);
        }
        $msg .= ob_get_contents(); // append messages
        ob_end_clean();
        if ($msg != '') {
                $this->parent->set('extension_message', $msg);
        }
        return $this->parent->extension->extension_id;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />