[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/plugins/extension/joomla/ -> joomla.php (source)

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  // No direct access.
   8  defined('_JEXEC') or die;
   9  
  10  /**
  11   * Joomla! master extension plugin.
  12   *
  13   * @package        Joomla.Plugin
  14   * @subpackage    Extension.Joomla
  15   * @since        1.6
  16   */
  17  class plgExtensionJoomla extends JPlugin
  18  {
  19      /**
  20       * @var        integer Extension Identifier
  21       * @since    1.6
  22       */
  23      private $eid = 0;
  24  
  25      /**
  26       * @var        JInstaller Installer object
  27       * @since    1.6
  28       */
  29      private $installer = null;
  30  
  31      /**
  32       * Constructor
  33       *
  34       * @access      protected
  35       * @param       object  $subject The object to observe
  36       * @param       array   $config  An array that holds the plugin configuration
  37       * @since       1.5
  38       */
  39  	public function __construct(& $subject, $config)
  40      {
  41          parent::__construct($subject, $config);
  42          $this->loadLanguage();
  43      }
  44  
  45      /**
  46       * Adds an update site to the table if it doesn't exist.
  47       *
  48       * @param    string    The friendly name of the site
  49       * @param    string    The type of site (e.g. collection or extension)
  50       * @param    string    The URI for the site
  51       * @param    boolean    If this site is enabled
  52       * @since    1.6
  53       */
  54  	private function addUpdateSite($name, $type, $location, $enabled)
  55      {
  56          $dbo = JFactory::getDBO();
  57          // look if the location is used already; doesn't matter what type
  58          // you can't have two types at the same address, doesn't make sense
  59          $query = $dbo->getQuery(true);
  60          $query->select('update_site_id')->from('#__update_sites')->where('location = '. $dbo->Quote($location));
  61          $dbo->setQuery($query);
  62          $update_site_id = (int)$dbo->loadResult();
  63  
  64          // if it doesn't exist, add it!
  65          if (!$update_site_id)
  66          {
  67              $query->clear();
  68              $query->insert('#__update_sites');
  69              $query->columns(array($dbo->quoteName('name'), $dbo->quoteName('type'), $dbo->quoteName('location'), $dbo->quoteName('enabled')));
  70              $query->values($dbo->quote($name) . ', ' . $dbo->quote($type) . ', ' . $dbo->quote($location) . ', ' . (int) $enabled);
  71              $dbo->setQuery($query);
  72              if ($dbo->query())
  73              {
  74                  // link up this extension to the update site
  75                  $update_site_id = $dbo->insertid();
  76              }
  77          }
  78  
  79          // check if it has an update site id (creation might have faileD)
  80          if ($update_site_id)
  81          {
  82              $query->clear();
  83              // look for an update site entry that exists
  84              $query->select('update_site_id')->from('#__update_sites_extensions');
  85              $query->where('update_site_id = '. $update_site_id)->where('extension_id = '. $this->eid);
  86              $dbo->setQuery($query);
  87              $tmpid = (int)$dbo->loadResult();
  88              if(!$tmpid)
  89              {
  90                  // link this extension to the relevant update site
  91                  $query->clear();
  92                  $query->insert('#__update_sites_extensions');
  93                  $query->columns(array($dbo->quoteName('update_site_id'), $dbo->quoteName('extension_id')));
  94                  $query->values($update_site_id . ', ' . $this->eid);
  95                  $dbo->setQuery($query);
  96                  $dbo->query();
  97              }
  98          }
  99      }
 100  
 101      /**
 102       * Handle post extension install update sites
 103       *
 104       * @param    JInstaller    Installer object
 105       * @param    int            Extension Identifier
 106       * @since    1.6
 107       */
 108  	public function onExtensionAfterInstall($installer, $eid)
 109      {
 110          if ($eid)
 111          {
 112              $this->installer = $installer;
 113              $this->eid = $eid;
 114  
 115              // After an install we only need to do update sites
 116              $this->processUpdateSites();
 117          }
 118      }
 119  
 120      /**
 121       * Handle extension uninstall
 122       *
 123       * @param    JInstaller    Installer instance
 124       * @param    int            extension id
 125       * @param    int            installation result
 126       * @since    1.6
 127       */
 128  	public function onExtensionAfterUninstall($installer, $eid, $result)
 129      {
 130          if ($eid)
 131          {
 132              // wipe out any update_sites_extensions links
 133              $db = JFactory::getDBO();
 134              $query = $db->getQuery(true);
 135              $query->delete()->from('#__update_sites_extensions')->where('extension_id = '. $eid);
 136              $db->setQuery($query);
 137              $db->Query();
 138  
 139              // delete any unused update sites
 140              $query->clear();
 141              $query->select('update_site_id')->from('#__update_sites_extensions');
 142              $db->setQuery($query);
 143              $results = $db->loadColumn();
 144  
 145              if(is_array($results))
 146              {
 147                  // so we need to delete the update sites and their associated updates
 148                  $updatesite_delete = $db->getQuery(true);
 149                  $updatesite_delete->delete()->from('#__update_sites');
 150                  $updatesite_query = $db->getQuery(true);
 151                  $updatesite_query->select('update_site_id')->from('#__update_sites');
 152  
 153                  // if we get results back then we can exclude them
 154                  if(count($results))
 155                  {
 156                      $updatesite_query->where('update_site_id NOT IN ('. implode(',', $results) .')');
 157                      $updatesite_delete->where('update_site_id NOT IN ('. implode(',', $results) .')');
 158                  }
 159                  // so lets find what update sites we're about to nuke and remove their associated extensions
 160                  $db->setQuery($updatesite_query);
 161                  $update_sites_pending_delete = $db->loadColumn();
 162                  if(is_array($update_sites_pending_delete) && count($update_sites_pending_delete))
 163                  {
 164                      // nuke any pending updates with this site before we delete it
 165                      // TODO: investigate alternative of using a query after the delete below with a query and not in like above
 166                      $query->clear();
 167                      $query->delete()->from('#__updates')->where('update_site_id IN ('. implode(',', $update_sites_pending_delete) .')');
 168                      $db->setQuery($query);
 169                      $db->query();
 170                  }
 171  
 172                  // note: this might wipe out the entire table if there are no extensions linked
 173                  $db->setQuery($updatesite_delete);
 174                  $db->query();
 175  
 176              }
 177  
 178              // last but not least we wipe out any pending updates for the extension
 179              $query->clear();
 180              $query->delete()->from('#__updates')->where('extension_id = '. $eid);
 181              $db->setQuery($query);
 182              $db->query();
 183          }
 184      }
 185  
 186      /**
 187       * After update of an extension
 188       *
 189       * @param    JInstaller    Installer object
 190       * @param    int            Extension identifier
 191       * @since    1.6
 192       */
 193  	public function onExtensionAfterUpdate($installer, $eid)
 194      {
 195          if ($eid) {
 196              $this->installer = $installer;
 197              $this->eid = $eid;
 198  
 199              // handle any update sites
 200              $this->processUpdateSites();
 201          }
 202      }
 203  
 204      /**
 205       * Processes the list of update sites for an extension.
 206       *
 207       * @since    1.6
 208       */
 209  	private function processUpdateSites()
 210      {
 211          $manifest        = $this->installer->getManifest();
 212          $updateservers    = $manifest->updateservers;
 213  
 214          if($updateservers) {
 215              $children = $updateservers->children();
 216          } else {
 217              $children = array();
 218          }
 219  
 220          if (count($children))
 221          {
 222              foreach ($children as $child)
 223              {
 224                  $attrs = $child->attributes();
 225                  $this->addUpdateSite($attrs['name'], $attrs['type'], $child, true);
 226              }
 227          }
 228          else
 229          {
 230              $data = (string)$updateservers;
 231  
 232              if (strlen($data))
 233              {
 234                  //     we have a single entry in the update server line, let us presume this is an extension line
 235                  $this->addUpdateSite(JText::_('PLG_EXTENSION_JOOMLA_UNKNOWN_SITE'), 'extension', $data, true);
 236              }
 237          }
 238      }
 239  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1