Source for file discover.php

Documentation is available at discover.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_installer
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. require_once __DIR__ . '/extension.php';
  13.  
  14. /**
  15.  * Installer Discover Model
  16.  *
  17.  * @package     Joomla.Administrator
  18.  * @subpackage  com_installer
  19.  * @since       1.6
  20.  */
  21. {
  22.     /**
  23.      * Method to auto-populate the model state.
  24.      *
  25.      * Note. Calling getState in this method will result in recursion.
  26.      *
  27.      * @param   string  $ordering   An optional ordering field.
  28.      * @param   string  $direction  An optional direction (asc|desc).
  29.      *
  30.      * @return  void 
  31.      *
  32.      * @since   3.1
  33.      */
  34.     protected function populateState($ordering null$direction null)
  35.     {
  36.         $app JFactory::getApplication();
  37.  
  38.         // Load the filter state.
  39.         $search $this->getUserStateFromRequest($this->context . '.filter.search''filter_search');
  40.         $this->setState('filter.search'$search);
  41.  
  42.         $clientId $this->getUserStateFromRequest($this->context . '.filter.client_id''filter_client_id''');
  43.         $this->setState('filter.client_id'$clientId);
  44.  
  45.         $categoryId $this->getUserStateFromRequest($this->context . '.filter.type''filter_type''');
  46.         $this->setState('filter.type'$categoryId);
  47.  
  48.         $group $this->getUserStateFromRequest($this->context . '.filter.group''filter_group''');
  49.         $this->setState('filter.group'$group);
  50.  
  51.         $this->setState('message'$app->getUserState('com_installer.message'));
  52.         $this->setState('extension_message'$app->getUserState('com_installer.extension_message'));
  53.         $app->setUserState('com_installer.message''');
  54.         $app->setUserState('com_installer.extension_message''');
  55.  
  56.         parent::populateState('name''asc');
  57.     }
  58.  
  59.     /**
  60.      * Method to get the database query.
  61.      *
  62.      * @return  JDatabaseQuery  the database query
  63.      *
  64.      * @since   3.1
  65.      */
  66.     protected function getListQuery()
  67.     {
  68.         $type   $this->getState('filter.type');
  69.         $client $this->getState('filter.client_id');
  70.         $group  $this->getState('filter.group');
  71.  
  72.         $query JFactory::getDbo()->getQuery(true)
  73.             ->select('*')
  74.             ->from('#__extensions')
  75.             ->where('state=-1');
  76.  
  77.         if ($type)
  78.         {
  79.             $query->where('type=' $this->_db->quote($type));
  80.         }
  81.  
  82.         if ($client != '')
  83.         {
  84.             $query->where('client_id=' . (int) $client);
  85.         }
  86.  
  87.         if ($group != '' && in_array($typearray('plugin''library''')))
  88.         {
  89.             $query->where('folder=' $this->_db->quote($group == '*' '' $group));
  90.         }
  91.  
  92.         // Filter by search in id
  93.         $search $this->getState('filter.search');
  94.  
  95.         if (!empty($search&& stripos($search'id:'=== 0)
  96.         {
  97.             $query->where('extension_id = ' . (int) substr($search3));
  98.         }
  99.  
  100.         return $query;
  101.     }
  102.  
  103.     /**
  104.      * Discover extensions.
  105.      *
  106.      * Finds uninstalled extensions
  107.      *
  108.      * @return  void 
  109.      *
  110.      * @since   1.6
  111.      */
  112.     public function discover()
  113.     {
  114.         // Purge the list of discovered extensions
  115.         $this->purge();
  116.  
  117.         $installer    JInstaller::getInstance();
  118.         $results    $installer->discover();
  119.  
  120.         // Get all templates, including discovered ones
  121.         $db JFactory::getDbo();
  122.         $query $db->getQuery(true)
  123.             ->select('extension_id, element, folder, client_id, type')
  124.             ->from('#__extensions');
  125.  
  126.         $db->setQuery($query);
  127.         $installedtmp $db->loadObjectList();
  128.         $extensions array();
  129.  
  130.         foreach ($installedtmp as $install)
  131.         {
  132.             $key implode(':'array($install->type$install->element$install->folder$install->client_id));
  133.             $extensions[$key$install;
  134.         }
  135.  
  136.         unset($installedtmp);
  137.  
  138.         foreach ($results as $result)
  139.         {
  140.             // Check if we have a match on the element
  141.             $key implode(':'array($result->type$result->element$result->folder$result->client_id));
  142.  
  143.             if (!array_key_exists($key$extensions))
  144.             {
  145.                 // Put it into the table
  146.                 $result->store();
  147.             }
  148.         }
  149.     }
  150.  
  151.     /**
  152.      * Installs a discovered extension.
  153.      *
  154.      * @return  void 
  155.      *
  156.      * @since   1.6
  157.      */
  158.     public function discover_install()
  159.     {
  160.         $app       JFactory::getApplication();
  161.         $installer JInstaller::getInstance();
  162.         $eid       JRequest::getVar('cid'0);
  163.  
  164.         if (is_array($eid|| $eid)
  165.         {
  166.             if (!is_array($eid))
  167.             {
  168.                 $eid array($eid);
  169.             }
  170.  
  171.             JArrayHelper::toInteger($eid);
  172.             $failed false;
  173.  
  174.             foreach ($eid as $id)
  175.             {
  176.                 $result $installer->discover_install($id);
  177.  
  178.                 if (!$result)
  179.                 {
  180.                     $failed true;
  181.                     $app->enqueueMessage(JText::_('COM_INSTALLER_MSG_DISCOVER_INSTALLFAILED'': ' $id);
  182.                 }
  183.             }
  184.  
  185.             $this->setState('action''remove');
  186.             $this->setState('name'$installer->get('name'));
  187.             $app->setUserState('com_installer.message'$installer->message);
  188.             $app->setUserState('com_installer.extension_message'$installer->get('extension_message'));
  189.  
  190.             if (!$failed)
  191.             {
  192.                 $app->enqueueMessage(JText::_('COM_INSTALLER_MSG_DISCOVER_INSTALLSUCCESSFUL'));
  193.             }
  194.         }
  195.         else
  196.         {
  197.             $app->enqueueMessage(JText::_('COM_INSTALLER_MSG_DISCOVER_NOEXTENSIONSELECTED'));
  198.         }
  199.     }
  200.  
  201.     /**
  202.      * Cleans out the list of discovered extensions.
  203.      *
  204.      * @return  bool True on success
  205.      *
  206.      * @since   1.6
  207.      */
  208.     public function purge()
  209.     {
  210.         $db        JFactory::getDbo();
  211.         $query    $db->getQuery(true)
  212.             ->delete('#__extensions')
  213.             ->where('state = -1');
  214.         $db->setQuery($query);
  215.  
  216.         if ($db->execute())
  217.         {
  218.             $this->_message JText::_('COM_INSTALLER_MSG_DISCOVER_PURGEDDISCOVEREDEXTENSIONS');
  219.  
  220.             return true;
  221.         }
  222.         else
  223.         {
  224.             $this->_message JText::_('COM_INSTALLER_MSG_DISCOVER_FAILEDTOPURGEEXTENSIONS');
  225.  
  226.             return false;
  227.         }
  228.     }
  229. }

Documentation generated on Tue, 19 Nov 2013 15:01:31 +0100 by phpDocumentor 1.4.3