Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/installer/adapters/component.php

Documentation is available at component.php

  1. <?php
  2. /**
  3.  * @version        $Id: component.php 6138 2007-01-02 03:44:18Z eddiea $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    Installer
  6.  * @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7.  * @license        GNU/GPL, see LICENSE.php
  8.  *  Joomla! is free software. This version may have been modified pursuant
  9.  *  to the GNU General Public License, and as distributed it includes or
  10.  *  is derivative of works licensed under the GNU General Public License or
  11.  *  other free or open source software licenses.
  12.  *  See COPYRIGHT.php for copyright notices and details.
  13.  */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * Component installer
  20.  *
  21.  * @package        Joomla.Framework
  22.  * @subpackage    Installer
  23.  * @since        1.5
  24.  */
  25. class JInstallerComponent extends JObject
  26. {
  27.     /**
  28.      * Constructor
  29.      *
  30.      * @access    protected
  31.      * @param    object    $parent    Parent object [JInstaller instance]
  32.      * @return    void 
  33.      * @since    1.5
  34.      */
  35.     function __construct(&$parent)
  36.     {
  37.         $this->parent =$parent;
  38.     }
  39.  
  40.     /**
  41.      * Custom install method for components
  42.      *
  43.      * @access    public
  44.      * @return    boolean    True on success
  45.      * @since    1.5
  46.      */
  47.     function install()
  48.     {
  49.         // Get a database connector object
  50.         $db =$this->parent->getDBO();
  51.  
  52.         // Get the extension manifest object
  53.         $manifest =$this->parent->getManifest();
  54.         $this->manifest =$manifest->document;
  55.  
  56.         /**
  57.          * ---------------------------------------------------------------------------------------------
  58.          * Manifest Document Setup Section
  59.          * ---------------------------------------------------------------------------------------------
  60.          */
  61.  
  62.         // Set the component name
  63.         $name =$this->manifest->getElementByPath('name');
  64.         $this->set('name'$name->data());
  65.  
  66.         // Get the component description
  67.         $description $this->manifest->getElementByPath('description');
  68.         if (is_a($description'JSimpleXMLElement')) {
  69.             $this->parent->set('message'$this->get('name').'<p>'.$description->data().'</p>');
  70.         else {
  71.             $this->parent->set('message'$this->get('name'));
  72.         }
  73.  
  74.         // Get some important manifest elements
  75.         $this->adminElement        =$this->manifest->getElementByPath('administration');
  76.         $this->installElement    =$this->manifest->getElementByPath('install');
  77.         $this->uninstallElement    =$this->manifest->getElementByPath('uninstall');
  78.  
  79.         // Set the installation target paths
  80.         $this->parent->setPath('extension_site'JPath::clean(JPATH_SITE.DS."components".DS.strtolower("com_".str_replace(" """$this->get('name')))));
  81.         $this->parent->setPath('extension_administrator'JPath::clean(JPATH_ADMINISTRATOR.DS."components".DS.strtolower("com_".str_replace(" """$this->get('name')))));
  82.  
  83.         /**
  84.          * ---------------------------------------------------------------------------------------------
  85.          * Filesystem Processing Section
  86.          * ---------------------------------------------------------------------------------------------
  87.          */
  88.  
  89.         /*
  90.          * If the component site or admin directory already exists, then we will assume that the component is already
  91.          * installed or another component is using that directory.
  92.          */
  93.         if ((file_exists($this->parent->getPath('extension_site')) || file_exists($this->parent->getPath('extension_administrator'))) && !$this->parent->getOverwrite()) {
  94.             JError::raiseWarning(1'Component Install: '.JText::_('Another component is already using directory').': "'.$this->parent->getPath('extension_site').'"');
  95.             return false;
  96.         }
  97.  
  98.         // If the component directory does not exist, lets create it
  99.         $created false;
  100.         if (!file_exists($this->parent->getPath('extension_site'))) {
  101.             if (!$created JFolder::create($this->parent->getPath('extension_site'))) {
  102.                 JError::raiseWarning(1'Component Install: '.JText::_('Failed to create directory').': "'.$this->parent->getPath('extension_site').'"');
  103.                 return false;
  104.             }
  105.         }
  106.  
  107.         /*
  108.          * Since we created the component directory and will want to remove it if we have to roll back
  109.          * the installation, lets add it to the installation step stack
  110.          */
  111.         if ($created{
  112.             $this->parent->pushStep(array ('type' => 'folder''path' => $this->parent->getPath('extension_site')));
  113.         }
  114.  
  115.         // If the component admin directory does not exist, lets create it
  116.         $created false;
  117.         if (!file_exists($this->parent->getPath('extension_administrator'))) {
  118.             if (!$created JFolder::create($this->parent->getPath('extension_administrator'))) {
  119.                 JError::raiseWarning(1'Component Install: '.JText::_('Failed to create directory').': "'.$this->parent->getPath('extension_administrator').'"');
  120.                 // Install failed, rollback any changes
  121.                 $this->parent->abort();
  122.                 return false;
  123.             }
  124.         }
  125.  
  126.         /*
  127.          * Since we created the component admin directory and we will want to remove it if we have to roll
  128.          * back the installation, lets add it to the installation step stack
  129.          */
  130.         if ($created{
  131.             $this->parent->pushStep(array ('type' => 'folder''path' => $this->parent->getPath('extension_administrator')));
  132.         }
  133.  
  134.         // Find files to copy
  135.         foreach ($this->manifest->children(as $child)
  136.         {
  137.             if (is_a($child'JSimpleXMLElement'&& $child->name(== 'files'{
  138.                 if ($this->parent->parseFiles($child=== false{
  139.                     // Install failed, rollback any changes
  140.                     $this->parent->abort();
  141.                     return false;
  142.                 }
  143.             }
  144.         }
  145.         foreach ($this->adminElement->children(as $child)
  146.         {
  147.             if (is_a($child'JSimpleXMLElement'&& $child->name(== 'files'{
  148.                 if ($this->parent->parseFiles($child1=== false{
  149.                     // Install failed, rollback any changes
  150.                     $this->parent->abort();
  151.                     return false;
  152.                 }
  153.             }
  154.         }
  155.  
  156.         // Parse optional tags
  157.         $this->parent->parseMedia($this->manifest->getElementByPath('media'));
  158.         $this->parent->parseMedia($this->manifest->getElementByPath('administration/media')1);
  159.         $this->parent->parseLanguages($this->manifest->getElementByPath('languages'));
  160.         $this->parent->parseLanguages($this->manifest->getElementByPath('administration/languages')1);
  161.  
  162.         // Parse deprecated tags
  163.         $this->parent->parseFiles($this->manifest->getElementByPath('images'));
  164.         $this->parent->parseFiles($this->manifest->getElementByPath('administration/images')1);
  165.  
  166.         // If there is an install file, lets copy it.
  167.         $installScriptElement =$this->manifest->getElementByPath('installfile');
  168.         if (is_a($installScriptElement'JSimpleXMLElement')) {
  169.             // Make sure it hasn't already been copied (this would be an error in the xml install file)
  170.             if (!file_exists($this->parent->getPath('extension_administrator').DS.$installScriptElement->data()))
  171.             {
  172.                 $path['src']    $this->parent->getPath('source').DS.$installScriptElement->data();
  173.                 $path['dest']    $this->parent->getPath('extension_administrator').DS.$installScriptElement->data();
  174.                 if (!$this->parent->copyFiles(array ($path))) {
  175.                     // Install failed, rollback changes
  176.                     $this->parent->abort('Component Install: '.JText::_('Could not copy PHP install file.'));
  177.                     return false;
  178.                 }
  179.             }
  180.             $this->set('install.script'$installScriptElement->data());
  181.         }
  182.  
  183.         // If there is an uninstall file, lets copy it.
  184.         $uninstallScriptElement =$this->manifest->getElementByPath('uninstallfile');
  185.         if (is_a($uninstallScriptElement'JSimpleXMLElement')) {
  186.             // Make sure it hasn't already been copied (this would be an error in the xml install file)
  187.             if (!file_exists($this->parent->getPath('extension_administrator').DS.$uninstallScriptElement->data()))
  188.             {
  189.                 $path['src']    $this->parent->getPath('source').DS.$uninstallScriptElement->data();
  190.                 $path['dest']    $this->parent->getPath('extension_administrator').DS.$uninstallScriptElement->data();
  191.                 if (!$this->parent->copyFiles(array ($path))) {
  192.                     // Install failed, rollback changes
  193.                     $this->parent->abort('Component Install: '.JText::_('Could not copy PHP uninstall file.'));
  194.                     return false;
  195.                 }
  196.             }
  197.         }
  198.  
  199.         /**
  200.          * ---------------------------------------------------------------------------------------------
  201.          * Database Processing Section
  202.          * ---------------------------------------------------------------------------------------------
  203.          */
  204.  
  205.         /*
  206.          * Let's run the install queries for the component
  207.          *    If backward compatibility is required - run queries in xml file
  208.          *    If Joomla 1.5 compatible, with discreet sql files - execute appropriate
  209.          *    file for utf-8 support or non-utf-8 support
  210.          */
  211.         $result $this->parent->parseQueries($this->manifest->getElementByPath('install/queries'));
  212.         if ($result === false{
  213.             // Install failed, rollback changes
  214.             $this->parent->abort('Component Install: '.JText::_('SQL Error')." ".$db->stderr(true));
  215.             return false;
  216.         elseif ($result === 0{
  217.             // no backward compatibility queries found - try for Joomla 1.5 type queries
  218.             // second argument is the utf compatible version attribute
  219.             $utfresult $this->parent->parseSQLFiles($this->manifest->getElementByPath('install/sql'));
  220.             if ($utfresult === false{
  221.                 // Install failed, rollback changes
  222.                 $this->parent->abort('Component Install: '.JText::_('SQLERRORORFILE')." ".$db->stderr(true));
  223.                 return false;
  224.             }
  225.         }
  226.         
  227.         // Time to build the admin menus
  228.         $this->_buildAdminMenus();
  229.  
  230.         /**
  231.          * ---------------------------------------------------------------------------------------------
  232.          * Custom Installation Script Section
  233.          * ---------------------------------------------------------------------------------------------
  234.          */
  235.  
  236.         /*
  237.          * If we have an install script, lets include it, execute the custom
  238.          * install method, and append the return value from the custom install
  239.          * method to the installation message.
  240.          */
  241.         if ($this->get('install.script')) {
  242.             if (is_file($this->parent->getPath('extension_administrator').DS.$this->get('install.script'))) {
  243.                 ob_start();
  244.                 ob_implicit_flush(false);
  245.                 require_once ($this->parent->getPath('extension_administrator').DS.$this->get('install.script'));
  246.                 if (function_exists('com_install')) {
  247.                     if (com_install(=== false{
  248.                         $this->parent->abort('Component Install: '.JText::_('Custom install routine failure'));
  249.                         return false;
  250.                     }
  251.                 }
  252.                 $msg ob_get_contents();
  253.                 ob_end_clean();
  254.                 if ($msg != ''{
  255.                     $this->parent ->set('extension.message'$msg);
  256.                 }
  257.             }
  258.         }
  259.  
  260.         /**
  261.          * ---------------------------------------------------------------------------------------------
  262.          * Finalization and Cleanup Section
  263.          * ---------------------------------------------------------------------------------------------
  264.          */
  265.  
  266.         // Lastly, we will copy the manifest file to its appropriate place.
  267.         if (!$this->parent->copyManifest()) {
  268.             // Install failed, rollback changes
  269.             $this->parent->abort('Component Install: '.JText::_('Could not copy setup file'));
  270.             return false;
  271.         }
  272.         return true;
  273.     }
  274.  
  275.     /**
  276.      * Custom uninstall method for components
  277.      *
  278.      * @access    public
  279.      * @param    int        $cid    The id of the component to uninstall
  280.      * @param    int        $clientId    The id of the client (unused)
  281.      * @return    mixed    Return value for uninstall method in component uninstall file
  282.      * @since    1.0
  283.      */
  284.     function uninstall($id$clientId)
  285.     {
  286.         // Initialize variables
  287.         $db =$this->parent->getDBO();
  288.         $row    null;
  289.         $retval    true;
  290.  
  291.         // First order of business will be to load the component object table from the database.
  292.         // This should give us the necessary information to proceed.
  293.         $row JTable::getInstance('component');
  294.         $row->load($id);
  295.  
  296.         // Is the component we are trying to uninstall a core one?
  297.         // Because that is not a good idea...
  298.         if ($row->iscore{
  299.             JError::raiseWarning(100'Component Uninstall: '.JText::sprintf('WARNCORECOMPONENT'$row->name)."<br />".JText::_('WARNCORECOMPONENT2'));
  300.             return false;
  301.         }
  302.  
  303.         // Get the admin and site paths for the component
  304.         $this->parent->setPath('extension_administrator'JPath::clean(JPATH_ADMINISTRATOR.DS.'components'.DS.$row->option));
  305.         $this->parent->setPath('extension_site'JPath::clean(JPATH_SITE.DS.'components'.DS.$row->option));
  306.  
  307.         /**
  308.          * ---------------------------------------------------------------------------------------------
  309.          * Manifest Document Setup Section
  310.          * ---------------------------------------------------------------------------------------------
  311.          */
  312.  
  313.         // Find and load the XML install file for the component
  314.         $this->parent->setPath('source'$this->parent->getPath('extension_administrator'));
  315.  
  316.         // Get the package manifest objecct
  317.         $manifest =$this->parent->getManifest();
  318.         if (!is_a($manifest'JSimpleXML')) {
  319.             // Make sure we delete the folders if no manifest exists
  320.             JFolder::delete($this->parent->getPath('extension_administrator'));
  321.             JFolder::delete($this->parent->getPath('extension_site'));
  322.             JError::raiseWarning(100'Component Uninstall: Package manifest file invalid or not found');
  323.             return false;
  324.         }
  325.  
  326.         // Get the root node of the manifest document
  327.         $this->manifest =$manifest->document;
  328.  
  329.         /**
  330.          * ---------------------------------------------------------------------------------------------
  331.          * Custom Uninstallation Script Section
  332.          * ---------------------------------------------------------------------------------------------
  333.          */
  334.  
  335.         // Now lets load the uninstall file if there is one and execute the uninstall function if it exists.
  336.         $uninstallfileElement =$this->manifest->getElementByPath('uninstallfile');
  337.         if (is_a($uninstallfileElement'JSimpleXMLElement')) {
  338.             // Element exists, does the file exist?
  339.             if (is_file($this->parent->getPath('extension_administrator').DS.$uninstallfileElement->data())) {
  340.                 ob_start();
  341.                 ob_implicit_flush(false);
  342.                 require_once ($this->parent->getPath('extension_administrator').DS.$uninstallfileElement->data());
  343.                 if (function_exists('com_uninstall')) {
  344.                     if (com_uninstall(=== false{
  345.                         JError::raiseWarning(100'Component Uninstall: '.JText::_('Custom Uninstall script unsuccessful'));
  346.                         $retval false;
  347.                     }
  348.                 }
  349.                 $msg ob_get_contents();
  350.                 ob_end_clean();
  351.                 if ($msg != ''{
  352.                     $this->parent->set('extension.message'$msg);
  353.                 }
  354.             }
  355.         }
  356.  
  357.         /**
  358.          * ---------------------------------------------------------------------------------------------
  359.          * Database Processing Section
  360.          * ---------------------------------------------------------------------------------------------
  361.          */
  362.  
  363.         /*
  364.          * Let's run the uninstall queries for the component
  365.          *    If backward compatibility is required - run queries in xml file
  366.          *    If Joomla 1.5 compatible, with discreet sql files - execute appropriate
  367.          *    file for utf-8 support or non-utf support
  368.          */
  369.         $result $this->parent->parseQueries($this->manifest->getElementByPath('uninstall/queries'));
  370.         if ($result === false{
  371.             // Install failed, rollback changes
  372.             JError::raiseWarning(100'Component Uninstall: '.JText::_('SQL Error')." ".$db->stderr(true));
  373.             $retval false;
  374.         elseif ($result === 0{
  375.             // no backward compatibility queries found - try for Joomla 1.5 type queries
  376.             // second argument is the utf compatible version attribute
  377.             $utfresult $this->parent->parseSQLFiles($this->manifest->getElementByPath('uninstall/sql'));
  378.             if ($utfresult === false{
  379.                 // Install failed, rollback changes
  380.                 JError::raiseWarning(100'Component Uninstall: '.JText::_('SQLERRORORFILE')." ".$db->stderr(true));
  381.                 $retval false;
  382.             }
  383.         }
  384.  
  385.         $this->_removeAdminMenus($row);
  386.  
  387.         /**
  388.          * ---------------------------------------------------------------------------------------------
  389.          * Filesystem Processing Section
  390.          * ---------------------------------------------------------------------------------------------
  391.          */
  392.  
  393.         // Let's remove language files and media in the JROOT/images/ folder that are
  394.         // associated with the component we are uninstalling
  395.         $this->parent->removeFiles($this->manifest->getElementByPath('media'));
  396.         $this->parent->removeFiles($this->manifest->getElementByPath('media')1);
  397.         $this->parent->removeFiles($this->manifest->getElementByPath('languages'));
  398.         $this->parent->removeFiles($this->manifest->getElementByPath('administration/languages')1);
  399.  
  400.         // Now we need to delete the installation directories.  This is the final step in uninstalling the component.
  401.         if (trim($row->option)) {
  402.             // Delete the component site directory
  403.             if (is_dir($this->parent->getPath('extension_site'))) {
  404.                 if (!JFolder::delete($this->parent->getPath('extension_site'))) {
  405.                     JError::raiseWarning(100'Component Uninstall: '.JText::_('Unable to remove the component site directory'));
  406.                     $retval false;
  407.                 }
  408.             }
  409.  
  410.             // Delete the component admin directory
  411.             if (is_dir($this->parent->getPath('extension_administrator'))) {
  412.                 if (!JFolder::delete($this->parent->getPath('extension_administrator'))) {
  413.                     JError::raiseWarning(100'Component Uninstall: '.JText::_('Unable to remove the component admin directory'));
  414.                     $retval false;
  415.                 }
  416.             }
  417.             return $retval;
  418.         else {
  419.             // No component option defined... cannot delete what we don't know about
  420.             JError::raiseWarning(100'Component Uninstall: Option field empty, cannot remove files');
  421.             return false;
  422.         }
  423.     }
  424.  
  425.     /**
  426.      * Method to build menu database entries for a component
  427.      *
  428.      * @access    private
  429.      * @return    boolean    True if successful
  430.      * @since    1.5
  431.      */
  432.     function _buildAdminMenus()
  433.     {
  434.         // Get database connector object
  435.         $db =$this->parent->getDBO();
  436.  
  437.         // Initialize variables
  438.         $option strtolower("com_".str_replace(" """$this->get('name')));
  439.  
  440.         // If a component exists with this option in the table than we don't need to add menus
  441.         $query 'SELECT id' .
  442.                 ' FROM #__components' .
  443.                 ' WHERE `option` = '.$db->Quote($option);
  444.  
  445.         $db->setQuery($query);
  446.         $exists $db->loadResult();
  447.         
  448.         // Check if menu items exist
  449.         if ($exists{
  450.             
  451.             // Don't do anything if overwrite has not been enabled
  452.             if $this->parent->getOverwrite() ) {
  453.                 return true;
  454.             }
  455.             
  456.             // Remove existing menu items if overwrite has been enabled
  457.             if $option {
  458.                 
  459.                 $sql 'DELETE FROM #__components WHERE `option` = '.$db->Quote($option);
  460.  
  461.                 $db->setQuery($sql);
  462.                 if (!$db->query()) {
  463.                     JError::raiseWarning(100'Component Install: '.$db->stderr(true));
  464.                 }
  465.             
  466.         }
  467.  
  468.         // Ok, now its time to handle the menus.  Start with the component root menu, then handle submenus.
  469.         $menuElement $this->adminElement->getElementByPath('menu');
  470.         if (is_a($menuElement'JSimpleXMLElement')) {
  471.  
  472.             $db_name $menuElement->data();
  473.             $db_link "option=".$option;
  474.             $db_menuid 0;
  475.             $db_parent 0;
  476.             $db_admin_menu_link "option=".$option;
  477.             $db_admin_menu_alt $menuElement->data();
  478.             $db_option $option;
  479.             $db_ordering 0;
  480.             $db_admin_menu_img ($menuElement->attributes('img')) $menuElement->attributes('img''js/ThemeOffice/component.png';
  481.             $db_iscore 0;
  482.             $db_params $this->parent->getParams();
  483.             $db_enabled 1;
  484.  
  485.             $query 'INSERT INTO #__components' .
  486.                     ' VALUES( "", "'.$db_name.'", "'.$db_link.'", '.$db_menuid.', '.$db_parent.', "'.$db_admin_menu_link.'", "'.$db_admin_menu_alt.'", "'.$db_option.'", '.$db_ordering.', "'.$db_admin_menu_img.'", '.$db_iscore.', "'.$db_params.'", "'.$db_enabled.'" )';
  487.             $db->setQuery($query);
  488.             if (!$db->query()) {
  489.                 // Install failed, rollback changes
  490.                 $this->parent->abort('Component Install: '.$db->stderr(true));
  491.                 return false;
  492.             }
  493.             $menuid $db->insertid();
  494.  
  495.             /*
  496.              * Since we have created a menu item, we add it to the installation step stack
  497.              * so that if we have to rollback the changes we can undo it.
  498.              */
  499.             $this->parent->pushStep(array ('type' => 'menu''id' => $menuid));
  500.         else {
  501.  
  502.             /*
  503.              * No menu element was specified so lets first see if we have an admin menu entry for this component
  504.              * if we do.. then we obviously don't want to create one -- we'll just attach sub menus to that one.
  505.              */
  506.             $query 'SELECT id' .
  507.                     ' FROM #__components' .
  508.                     ' WHERE `option` = '.$db->Quote($option.
  509.                     ' AND parent = 0';
  510.             $db->setQuery($query);
  511.             $menuid $db->loadResult();
  512.  
  513.             if (!$menuid{
  514.                 // No menu entry, lets just enter a component entry to the table.
  515.                 $db_name $this->get('name');
  516.                 $db_link "";
  517.                 $db_menuid 0;
  518.                 $db_parent 0;
  519.                 $db_admin_menu_link "";
  520.                 $db_admin_menu_alt $this->get('name');
  521.                 $db_option $option;
  522.                 $db_ordering 0;
  523.                 $db_admin_menu_img "";
  524.                 $db_iscore 0;
  525.                 $db_params $this->parent->getParams();
  526.                 $db_enabled 1;
  527.  
  528.                 $query 'INSERT INTO #__components' .
  529.                         ' VALUES( "", "'.$db_name.'", "'.$db_link.'", '.$db_menuid.', '.$db_parent.', "'.$db_admin_menu_link.'", "'.$db_admin_menu_alt.'", "'.$db_option.'", '.$db_ordering.', "'.$db_admin_menu_img.'", '.$db_iscore.', "'.$db_params.'", "'.$db_enabled.'" )';
  530.                 $db->setQuery($query);
  531.                 if (!$db->query()) {
  532.                     // Install failed, rollback changes
  533.                     $this->parent->abort('Component Install: '.$db->stderr(true));
  534.                     return false;
  535.                 }
  536.                 $menuid $db->insertid();
  537.  
  538.                 /*
  539.                  * Since we have created a menu item, we add it to the installation step stack
  540.                  * so that if we have to rollback the changes we can undo it.
  541.                  */
  542.                 $this->parent->pushStep(array ('type' => 'menu''id' => $menuid));
  543.             }
  544.         }
  545.  
  546.         /*
  547.          * Process SubMenus
  548.          */
  549.  
  550.         // Initialize submenu ordering value
  551.         $ordering 0;
  552.         $submenu $this->adminElement->getElementByPath('submenu');
  553.         if (!is_a($submenu'JSimpleXMLElement'|| !count($submenu->children())) {
  554.             return true;
  555.         }
  556.         foreach ($submenu->children(as $child)
  557.         {
  558.             if (is_a($child'JSimpleXMLElement'&& $child->name(== 'menu'{
  559.  
  560.                 $com =JTable::getInstance('component');
  561.                 $com->name $child->data();
  562.                 $com->link '';
  563.                 $com->menuid 0;
  564.                 $com->parent $menuid;
  565.                 $com->iscore 0;
  566.                 $com->admin_menu_alt $child->data();
  567.                 $com->option $option;
  568.                 $com->ordering $ordering ++;
  569.  
  570.                 // Set the sub menu link
  571.                 if ($child->attributes("link")) {
  572.                     $com->admin_menu_link str_replace('&amp;''&'$child->attributes("link"));
  573.                 else {
  574.                     $request array();
  575.                     if ($child->attributes('act')) {
  576.                         $request['act='.$child->attributes('act');
  577.                     }
  578.                     if ($child->attributes('task')) {
  579.                         $request['task='.$child->attributes('task');
  580.                     }
  581.                     if ($child->attributes('controller')) {
  582.                         $request['controller='.$child->attributes('controller');
  583.                     }
  584.                     if ($child->attributes('view')) {
  585.                         $request['view='.$child->attributes('view');
  586.                     }
  587.                     if ($child->attributes('layout')) {
  588.                         $request['layout='.$child->attributes('layout');
  589.                     }
  590.                     if ($child->attributes('sub')) {
  591.                         $request['sub='.$child->attributes('sub');
  592.                     }
  593.                     $qstring (count($request)) '&'.implode('&',$request'';
  594.                     $com->admin_menu_link "option=".$option.$qstring;
  595.                 }
  596.  
  597.                 // Set the sub menu image
  598.                 if ($child->attributes("img")) {
  599.                     $com->admin_menu_img $child->attributes("img");
  600.                 else {
  601.                     $com->admin_menu_img "js/ThemeOffice/component.png";
  602.                 }
  603.  
  604.                 // Store the submenu
  605.                 if (!$com->store()) {
  606.                     // Install failed, rollback changes
  607.                     $this->parent->abort('Component Install: '.JText::_('SQL Error')." ".$db->stderr(true));
  608.                     return false;
  609.                 }
  610.  
  611.                 /*
  612.                  * Since we have created a menu item, we add it to the installation step stack
  613.                  * so that if we have to rollback the changes we can undo it.
  614.                  */
  615.                 $this->parent->pushStep(array ('type' => 'menu''id' => $com->id));
  616.             }
  617.         }
  618.     }
  619.  
  620.     /**
  621.      * Method to remove admin menu references to a component
  622.      *
  623.      * @access    private
  624.      * @param    object    $component    Component table object
  625.      * @return    boolean    True if successful
  626.      * @since    1.5
  627.      */
  628.     function _removeAdminMenus(&$row)
  629.     {
  630.         // Get database connector object
  631.         $db =$this->parent->getDBO();
  632.         $retval true;
  633.  
  634.         // Delete the submenu items
  635.         $sql 'DELETE ' .
  636.                 ' FROM #__components ' .
  637.                 'WHERE parent = '.(int)$row->id;
  638.  
  639.         $db->setQuery($sql);
  640.         if (!$db->query()) {
  641.             JError::raiseWarning(100'Component Uninstall: '.$db->stderr(true));
  642.             $retval false;
  643.         }
  644.  
  645.         // Next, we will delete the component object
  646.         if (!$row->delete($row->id)) {
  647.             JError::raiseWarning(100'Component Uninstall: '.JText::_('Unable to delete the component from the database'));
  648.             $retval false;
  649.         }
  650.         return $retval;
  651.     }
  652.  
  653.     /**
  654.      * Custom rollback method
  655.      *     - Roll back the component menu item
  656.      *
  657.      * @access    public
  658.      * @param    array    $arg    Installation step to rollback
  659.      * @return    boolean    True on success
  660.      * @since    1.5
  661.      */
  662.     function _rollback_menu($arg)
  663.     {
  664.         // Get database connector object
  665.         $db =$this->parent->getDBO;
  666.  
  667.         // Remove the entry from the #__components table
  668.         $query 'DELETE ' .
  669.                 ' FROM `#__components` ' .
  670.                 ' WHERE id='.(int)$arg['id'];
  671.         $db->setQuery($query);
  672.         return ($db->query(!== false);
  673.     }
  674. }
  675. ?>

Documentation generated on Mon, 05 Mar 2007 20:54:42 +0000 by phpDocumentor 1.3.1