| [ 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 jimport('joomla.application.component.modellist'); 14 jimport('joomla.updater.update'); 15 16 /** 17 * @package Joomla.Administrator 18 * @subpackage com_installer 19 * @since 1.6 20 */ 21 class InstallerModelUpdate extends JModelList 22 { 23 /** 24 * Constructor. 25 * 26 * @param array An optional associative array of configuration settings. 27 * @see JController 28 * @since 1.6 29 */ 30 public function __construct($config = array()) 31 { 32 if (empty($config['filter_fields'])) { 33 $config['filter_fields'] = array( 34 'name', 35 'client_id', 36 'type', 37 'folder', 38 'extension_id', 39 'update_id', 40 'update_site_id', 41 ); 42 } 43 44 parent::__construct($config); 45 } 46 47 /** 48 * Method to auto-populate the model state. 49 * 50 * Note. Calling getState in this method will result in recursion. 51 * 52 * @since 1.6 53 */ 54 protected function populateState($ordering = null, $direction = null) 55 { 56 $app = JFactory::getApplication('administrator'); 57 $this->setState('message', $app->getUserState('com_installer.message')); 58 $this->setState('extension_message', $app->getUserState('com_installer.extension_message')); 59 $app->setUserState('com_installer.message', ''); 60 $app->setUserState('com_installer.extension_message', ''); 61 parent::populateState('name', 'asc'); 62 } 63 64 /** 65 * Method to get the database query 66 * 67 * @return JDatabaseQuery The database query 68 * @since 1.6 69 */ 70 protected function getListQuery() 71 { 72 $db = $this->getDbo(); 73 $query = $db->getQuery(true); 74 // grab updates ignoring new installs 75 $query->select('*')->from('#__updates')->where('extension_id != 0'); 76 $query->order($this->getState('list.ordering').' '.$this->getState('list.direction')); 77 78 // Filter by extension_id 79 if ($eid = $this->getState('filter.extension_id')) { 80 $query->where($db->nq('extension_id') . ' = ' . $db->q((int) $eid)); 81 } else { 82 $query->where($db->nq('extension_id').' != '.$db->q(0)); 83 $query->where($db->nq('extension_id').' != '.$db->q(700)); 84 } 85 86 return $query; 87 } 88 89 /** 90 * Finds updates for an extension. 91 * 92 * @param int Extension identifier to look for 93 * @return boolean Result 94 * @since 1.6 95 */ 96 public function findUpdates($eid=0, $cache_timeout = 0) 97 { 98 $updater = JUpdater::getInstance(); 99 $results = $updater->findUpdates($eid, $cache_timeout); 100 return true; 101 } 102 103 /** 104 * Removes all of the updates from the table. 105 * 106 * @return boolean result of operation 107 * @since 1.6 108 */ 109 public function purge() 110 { 111 $db = JFactory::getDBO(); 112 // Note: TRUNCATE is a DDL operation 113 // This may or may not mean depending on your database 114 $db->setQuery('TRUNCATE TABLE #__updates'); 115 if ($db->Query()) { 116 // Reset the last update check timestamp 117 $query = $db->getQuery(true); 118 $query->update($db->nq('#__update_sites')); 119 $query->set($db->nq('last_check_timestamp').' = '.$db->q(0)); 120 $db->setQuery($query); 121 $db->query(); 122 123 $this->_message = JText::_('COM_INSTALLER_PURGED_UPDATES'); 124 return true; 125 } else { 126 $this->_message = JText::_('COM_INSTALLER_FAILED_TO_PURGE_UPDATES'); 127 return false; 128 } 129 } 130 131 /** 132 * Enables any disabled rows in #__update_sites table 133 * 134 * @return boolean result of operation 135 * @since 1.6 136 */ 137 public function enableSites() 138 { 139 $db = JFactory::getDBO(); 140 $db->setQuery('UPDATE #__update_sites SET enabled = 1 WHERE enabled = 0'); 141 if ($db->Query()) { 142 if ($rows = $db->getAffectedRows()) { 143 $this->_message .= JText::plural('COM_INSTALLER_ENABLED_UPDATES', $rows); 144 } 145 return true; 146 } else { 147 $this->_message .= JText::_('COM_INSTALLER_FAILED_TO_ENABLE_UPDATES'); 148 return false; 149 } 150 } 151 152 /** 153 * Update function. 154 * 155 * Sets the "result" state with the result of the operation. 156 * 157 * @param Array[int] List of updates to apply 158 * @since 1.6 159 */ 160 public function update($uids) 161 { 162 $result = true; 163 foreach($uids as $uid) { 164 $update = new JUpdate(); 165 $instance = JTable::getInstance('update'); 166 $instance->load($uid); 167 $update->loadFromXML($instance->detailsurl); 168 // install sets state and enqueues messages 169 $res = $this->install($update); 170 171 if ($res) { 172 $instance->delete($uid); 173 } 174 175 $result = $res & $result; 176 } 177 178 // Set the final state 179 $this->setState('result', $result); 180 } 181 182 /** 183 * Handles the actual update installation. 184 * 185 * @param JUpdate An update definition 186 * @return boolean Result of install 187 * @since 1.6 188 */ 189 private function install($update) 190 { 191 $app = JFactory::getApplication(); 192 if (isset($update->get('downloadurl')->_data)) { 193 $url = $update->downloadurl->_data; 194 } else { 195 JError::raiseWarning('', JText::_('COM_INSTALLER_INVALID_EXTENSION_UPDATE')); 196 return false; 197 } 198 199 $p_file = JInstallerHelper::downloadPackage($url); 200 201 // Was the package downloaded? 202 if (!$p_file) { 203 JError::raiseWarning('', JText::sprintf('COM_INSTALLER_PACKAGE_DOWNLOAD_FAILED', $url)); 204 return false; 205 } 206 207 $config = JFactory::getConfig(); 208 $tmp_dest = $config->get('tmp_path'); 209 210 // Unpack the downloaded package file 211 $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file); 212 213 // Get an installer instance 214 $installer = JInstaller::getInstance(); 215 $update->set('type', $package['type']); 216 217 // Install the package 218 if (!$installer->update($package['dir'])) { 219 // There was an error updating the package 220 $msg = JText::sprintf('COM_INSTALLER_MSG_UPDATE_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_'.strtoupper($package['type']))); 221 $result = false; 222 } else { 223 // Package updated successfully 224 $msg = JText::sprintf('COM_INSTALLER_MSG_UPDATE_SUCCESS', JText::_('COM_INSTALLER_TYPE_TYPE_'.strtoupper($package['type']))); 225 $result = true; 226 } 227 228 // Quick change 229 $this->type = $package['type']; 230 231 // Set some model state values 232 $app->enqueueMessage($msg); 233 234 // TODO: Reconfigure this code when you have more battery life left 235 $this->setState('name', $installer->get('name')); 236 $this->setState('result', $result); 237 $app->setUserState('com_installer.message', $installer->message); 238 $app->setUserState('com_installer.extension_message', $installer->get('extension_message')); 239 240 // Cleanup the install files 241 if (!is_file($package['packagefile'])) { 242 $config = JFactory::getConfig(); 243 $package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile']; 244 } 245 246 JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']); 247 248 return $result; 249 } 250 }
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 |