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/plugin.php

Documentation is available at plugin.php

  1. <?php
  2. /**
  3.  * @version        $Id: plugin.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.  * Plugin installer
  20.  *
  21.  * @package        Joomla.Framework
  22.  * @subpackage    Installer
  23.  * @since        1.5
  24.  */
  25. class JInstallerPlugin 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
  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.         /*
  75.          * Backward Compatability
  76.          * @todo Deprecate in future version
  77.          */
  78.         $type $this->manifest->attributes('type');
  79.  
  80.         // Set the installation path
  81.         $element =$this->manifest->getElementByPath('files');
  82.         if (is_a($element'JSimpleXMLElement'&& count($element->children())) {
  83.             $files =$element->children();
  84.             foreach ($files as $file{
  85.                 if ($file->attributes($type)) {
  86.                     $pname $file->attributes($type);
  87.                     break;
  88.                 }
  89.             }
  90.         }
  91.         $group $this->manifest->attributes('group');
  92.         if (!empty ($pname&& !empty($group)) {
  93.             $this->parent->setPath('extension_root'JPATH_ROOT.DS.'plugins'.DS.$group);
  94.         else {
  95.             $this->parent->abort('Plugin Install: '.JText::_('No plugin file specified'));
  96.             return false;
  97.         }
  98.  
  99.         /**
  100.          * ---------------------------------------------------------------------------------------------
  101.          * Filesystem Processing Section
  102.          * ---------------------------------------------------------------------------------------------
  103.          */
  104.  
  105.         // If the plugin directory does not exist, lets create it
  106.         $created false;
  107.         if (!file_exists($this->parent->getPath('extension_root'))) {
  108.             if (!$created JFolder::create($this->parent->getPath('extension_root'))) {
  109.                 $this->parent->abort('Plugin Install: '.JText::_('Failed to create directory').': "'.$this->parent->getPath('extension_root').'"');
  110.                 return false;
  111.             }
  112.         }
  113.  
  114.         /*
  115.          * If we created the plugin directory and will want to remove it if we
  116.          * have to roll back the installation, lets add it to the installation
  117.          * step stack
  118.          */
  119.         if ($created{
  120.             $this->parent->pushStep(array ('type' => 'folder''path' => $this->parent->getPath('extension_root')));
  121.         }
  122.  
  123.         // Copy all necessary files
  124.         if ($this->parent->parseFiles($element-1=== false{
  125.             // Install failed, roll back changes
  126.             $this->parent->abort();
  127.             return false;
  128.         }
  129.  
  130.         // Parse optional tags -- media and language files for plugins go in admin app
  131.         $this->parent->parseMedia($this->manifest->getElementByPath('media')1);
  132.         $this->parent->parseLanguages($this->manifest->getElementByPath('languages')1);
  133.  
  134.         /**
  135.          * ---------------------------------------------------------------------------------------------
  136.          * Database Processing Section
  137.          * ---------------------------------------------------------------------------------------------
  138.          */
  139.  
  140.         // Check to see if a plugin by the same name is already installed
  141.         $query 'SELECT `id`' .
  142.                 ' FROM `#__plugins`' .
  143.                 ' WHERE folder = '.$db->Quote($group.
  144.                 ' AND element = '.$db->Quote($pname);
  145.         $db->setQuery($query);
  146.         if (!$db->Query()) {
  147.             // Install failed, roll back changes
  148.             $this->parent->abort('Plugin Install: '.$db->stderr(true));
  149.             return false;
  150.         }
  151.         $id $db->loadResult();
  152.  
  153.         // Was there a module already installed with the same name?
  154.         if ($id{
  155.             // Install failed, roll back changes
  156.             $this->parent->abort('Plugin Install: '.JText::_('Plugin').' "'.$pname.'" '.JText::_('already exists!'));
  157.             return false;
  158.         else {
  159.             $row =JTable::getInstance('plugin');
  160.             $row->name $this->get('name');
  161.             $row->ordering 0;
  162.             $row->folder $group;
  163.             $row->iscore 0;
  164.             $row->access 0;
  165.             $row->client_id 0;
  166.             $row->element $pname;
  167.             $row->params $this->parent->getParams();
  168.  
  169.             // Editor plugins are published by default
  170.             if ($group == 'editors'{
  171.                 $row->published 1;
  172.             }
  173.  
  174.             if (!$row->store()) {
  175.                 // Install failed, roll back changes
  176.                 $this->parent->abort('Plugin Install: '.$db->stderr(true));
  177.                 return false;
  178.             }
  179.  
  180.             // Since we have created a plugin item, we add it to the installation step stack
  181.             // so that if we have to rollback the changes we can undo it.
  182.             $this->parent->pushStep(array ('type' => 'plugin''id' => $row->id));
  183.         }
  184.  
  185.         /**
  186.          * ---------------------------------------------------------------------------------------------
  187.          * Finalization and Cleanup Section
  188.          * ---------------------------------------------------------------------------------------------
  189.          */
  190.  
  191.         // Lastly, we will copy the manifest file to its appropriate place.
  192.         if (!$this->parent->copyManifest(-1)) {
  193.             // Install failed, rollback changes
  194.             $this->parent->abort('Plugin Install: '.JText::_('Could not copy setup file'));
  195.             return false;
  196.         }
  197.         return true;
  198.     }
  199.  
  200.     /**
  201.      * Custom uninstall method
  202.      *
  203.      * @access    public
  204.      * @param    int        $cid    The id of the plugin to uninstall
  205.      * @param    int        $clientId    The id of the client (unused)
  206.      * @return    boolean    True on success
  207.      * @since    1.5
  208.      */
  209.     function uninstall($id$clientId )
  210.     {
  211.         // Initialize variables
  212.         $row    null;
  213.         $retval true;
  214.         $db        =$this->parent->getDBO();
  215.  
  216.         // First order of business will be to load the module object table from the database.
  217.         // This should give us the necessary information to proceed.
  218.         $row JTable::getInstance('plugin');
  219.         $row->load((int) $id);
  220.  
  221.         // Is the plugin we are trying to uninstall a core one?
  222.         // Because that is not a good idea...
  223.         if ($row->iscore{
  224.             JError::raiseWarning(100'Plugin Uninstall: '.JText::sprintf('WARNCOREPLUGIN'$row->name)."<br />".JText::_('WARNCOREPLUGIN2'));
  225.             return false;
  226.         }
  227.  
  228.         // Get the plugin folder so we can properly build the plugin path
  229.         if (trim($row->folder== ''{
  230.             JError::raiseWarning(100'Plugin Uninstall: '.JText::_('Folder field empty, cannot remove files'));
  231.             return false;
  232.         }
  233.  
  234.         // Set the plugin root path
  235.         $this->parent->setPath('extension_root'JPATH_ROOT.DS.'plugins'.DS.$row->folder);
  236.  
  237.         // Because plugins don't have their own folders we cannot use the standard method of finding an installation manifest
  238.         $manifestFile JPATH_ROOT.DS.'plugins'.DS.$row->folder.DS.$row->element.'.xml';
  239.         if (file_exists($manifestFile))
  240.         {
  241.             $xml =JFactory::getXMLParser('Simple');
  242.  
  243.             // If we cannot load the xml file return null
  244.             if (!$xml->loadFile($manifestFile)) {
  245.                 JError::raiseWarning(100'Plugin Uninstall: '.JText::_('Could not load manifest file'));
  246.                 return false;
  247.             }
  248.  
  249.             /*
  250.              * Check for a valid XML root tag.
  251.              * @todo: Remove backwards compatability in a future version
  252.              * Should be 'install', but for backward compatability we will accept 'mosinstall'.
  253.              */
  254.             $root =$xml->document;
  255.             if ($root->name(!= 'install' && $root->name(!= 'mosinstall'{
  256.                 JError::raiseWarning(100'Plugin Uninstall: '.JText::_('Invalid manifest file'));
  257.                 return false;
  258.             }
  259.  
  260.             // Remove the plugin files
  261.             $this->parent->removeFiles($root->getElementByPath('images')-1);
  262.             $this->parent->removeFiles($root->getElementByPath('files')-1);
  263.             JFile::delete($manifestFile);
  264.  
  265.             // Remove all media and languages as well
  266.             $this->parent->removeFiles($root->getElementByPath('media'));
  267.             $this->parent->removeFiles($root->getElementByPath('languages')1);
  268.         else {
  269.             JError::raiseWarning(100'Plugin Uninstall: Manifest File invalid or not found');
  270.             return false;
  271.         }
  272.  
  273.         // Now we will no longer need the plugin object, so lets delete it
  274.         $row->delete($row->id);
  275.         unset ($row);
  276.  
  277.         // If the folder is empty, let's delete it
  278.         $files JFolder::files($this->parent->getPath('extension_root'));
  279.         if (!count($files)) {
  280.             JFolder::delete($this->parent->getPath('extension_root'));
  281.         }
  282.  
  283.         return $retval;
  284.     }
  285.  
  286.     /**
  287.      * Custom rollback method
  288.      *     - Roll back the plugin item
  289.      *
  290.      * @access    public
  291.      * @param    array    $arg    Installation step to rollback
  292.      * @return    boolean    True on success
  293.      * @since    1.5
  294.      */
  295.     function _rollback_plugin($arg)
  296.     {
  297.         // Get database connector object
  298.         $db =$this->parent->getDBO();
  299.  
  300.         // Remove the entry from the #__plugins table
  301.         $query 'DELETE' .
  302.                 ' FROM `#__plugins`' .
  303.                 ' WHERE id='.(int)$arg['id'];
  304.         $db->setQuery($query);
  305.         return ($db->query(!== false);
  306.     }
  307. }
  308. ?>

Documentation generated on Mon, 05 Mar 2007 21:19:06 +0000 by phpDocumentor 1.3.1