| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Administrator 4 * @subpackage com_installer 5 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 */ 8 9 // No direct access. 10 defined('_JEXEC') or die; 11 12 // Import library dependencies 13 require_once dirname(__FILE__) . '/extension.php'; 14 15 /** 16 * Installer Manage Model 17 * 18 * @package Joomla.Administrator 19 * @subpackage com_installer 20 * @since 1.6 21 */ 22 class InstallerModelDiscover extends InstallerModel 23 { 24 protected $_context = 'com_installer.discover'; 25 26 /** 27 * Method to auto-populate the model state. 28 * 29 * Note. Calling getState in this method will result in recursion. 30 * 31 * @since 1.6 32 */ 33 protected function populateState($ordering = null, $direction = null) 34 { 35 $app = JFactory::getApplication(); 36 $this->setState('message', $app->getUserState('com_installer.message')); 37 $this->setState('extension_message', $app->getUserState('com_installer.extension_message')); 38 $app->setUserState('com_installer.message', ''); 39 $app->setUserState('com_installer.extension_message', ''); 40 parent::populateState('name', 'asc'); 41 } 42 43 /** 44 * Method to get the database query. 45 * 46 * @return JDatabaseQuery the database query 47 * @since 1.6 48 */ 49 protected function getListQuery() 50 { 51 $db = JFactory::getDBO(); 52 $query = $db->getQuery(true); 53 $query->select('*'); 54 $query->from('#__extensions'); 55 $query->where('state=-1'); 56 return $query; 57 } 58 59 /** 60 * Discover extensions. 61 * 62 * Finds uninstalled extensions 63 * 64 * @since 1.6 65 */ 66 function discover() 67 { 68 $installer = JInstaller::getInstance(); 69 $results = $installer->discover(); 70 71 // Get all templates, including discovered ones 72 $query = 'SELECT extension_id, element, folder, client_id, type FROM #__extensions'; 73 $dbo = JFactory::getDBO(); 74 $dbo->setQuery($query); 75 $installedtmp = $dbo->loadObjectList(); 76 $extensions = array(); 77 78 foreach($installedtmp as $install) 79 { 80 $key = implode(':', array($install->type, $install->element, $install->folder, $install->client_id)); 81 $extensions[$key] = $install; 82 } 83 unset($installedtmp); 84 85 86 foreach($results as $result) { 87 // check if we have a match on the element 88 $key = implode(':', array($result->type, $result->element, $result->folder, $result->client_id)); 89 if(!array_key_exists($key, $extensions)) 90 { 91 $result->store(); // put it into the table 92 } 93 } 94 } 95 96 /** 97 * Installs a discovered extension. 98 * 99 * @since 1.6 100 */ 101 function discover_install() 102 { 103 $app = JFactory::getApplication(); 104 $installer = JInstaller::getInstance(); 105 $eid = JRequest::getVar('cid', 0); 106 if (is_array($eid) || $eid) { 107 if (!is_array($eid)) { 108 $eid = array($eid); 109 } 110 JArrayHelper::toInteger($eid); 111 $app = JFactory::getApplication(); 112 $failed = false; 113 foreach($eid as $id) { 114 $result = $installer->discover_install($id); 115 if (!$result) { 116 $failed = true; 117 $app->enqueueMessage(JText::_('COM_INSTALLER_MSG_DISCOVER_INSTALLFAILED').': '. $id); 118 } 119 } 120 $this->setState('action', 'remove'); 121 $this->setState('name', $installer->get('name')); 122 $app->setUserState('com_installer.message', $installer->message); 123 $app->setUserState('com_installer.extension_message', $installer->get('extension_message')); 124 if (!$failed) { 125 $app->enqueueMessage(JText::_('COM_INSTALLER_MSG_DISCOVER_INSTALLSUCCESSFUL')); 126 } 127 } else { 128 $app->enqueueMessage(JText::_('COM_INSTALLER_MSG_DISCOVER_NOEXTENSIONSELECTED')); 129 } 130 } 131 132 /** 133 * Cleans out the list of discovered extensions. 134 * 135 * @since 1.6 136 */ 137 function purge() 138 { 139 $db = JFactory::getDBO(); 140 $query = $db->getQuery(true); 141 $query->delete(); 142 $query->from('#__extensions'); 143 $query->where('state = -1'); 144 $db->setQuery((string)$query); 145 if ($db->Query()) { 146 $this->_message = JText::_('COM_INSTALLER_MSG_DISCOVER_PURGEDDISCOVEREDEXTENSIONS'); 147 return true; 148 } else { 149 $this->_message = JText::_('COM_INSTALLER_MSG_DISCOVER_FAILEDTOPURGEEXTENSIONS'); 150 return false; 151 } 152 } 153 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |