- md5
- 59211bc2210b6feef0158b843b737f07
- sha1
- fecc88aa17029f43ed3ecfd1c147490814f2ef02
- sha256
- 3e2a767656a68333fd9e122bd5b76c1d791507e3266da8f0b1a4e10151ba845d
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
<?php
/**
* @package Joomla.Administrator
* @subpackage com_installer
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access
defined('_JEXEC') or die;
// Import library dependencies
jimport('joomla.application.component.modellist');
jimport('joomla.updater.update');
/**
* @package Joomla.Administrator
* @subpackage com_installer
* @since 1.6
*/
class InstallerModelUpdate extends JModelList
{
/**
* Constructor.
*
* @param array An optional associative array of configuration settings.
* @see JController
* @since 1.6
*/
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'name',
'client_id',
'type',
'folder',
'extension_id',
'update_id',
'update_site_id',
);
}
parent::__construct($config);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
$app = JFactory::getApplication('administrator');
$this->setState('message', $app->getUserState('com_installer.message'));
$this->setState('extension_message', $app->getUserState('com_installer.extension_message'));
$app->setUserState('com_installer.message', '');
$app->setUserState('com_installer.extension_message', '');
parent::populateState('name', 'asc');
}
/**
* Method to get the database query
*
* @return JDatabaseQuery The database query
* @since 1.6
*/
protected function getListQuery()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
// grab updates ignoring new installs
$query->select('*')->from('#__updates')->where('extension_id != 0');
$query->order($this->getState('list.ordering').' '.$this->getState('list.direction'));
// Filter by extension_id
if ($eid = $this->getState('filter.extension_id')) {
$query->where($db->nq('extension_id') . ' = ' . $db->q((int) $eid));
} else {
$query->where($db->nq('extension_id').' != '.$db->q(0));
$query->where($db->nq('extension_id').' != '.$db->q(700));
}
return $query;
}
/**
* Finds updates for an extension.
*
* @param int Extension identifier to look for
* @return boolean Result
* @since 1.6
*/
public function findUpdates($eid=0, $cache_timeout = 0)
{
$updater = JUpdater::getInstance();
$results = $updater->findUpdates($eid, $cache_timeout);
return true;
}
/**
* Removes all of the updates from the table.
*
* @return boolean result of operation
* @since 1.6
*/
public function purge()
{
$db = JFactory::getDBO();
// Note: TRUNCATE is a DDL operation
// This may or may not mean depending on your database
$db->setQuery('TRUNCATE TABLE #__updates');
if ($db->Query()) {
// Reset the last update check timestamp
$query = $db->getQuery(true);
$query->update($db->nq('#__update_sites'));
$query->set($db->nq('last_check_timestamp').' = '.$db->q(0));
$db->setQuery($query);
$db->query();
$this->_message = JText::_('COM_INSTALLER_PURGED_UPDATES');
return true;
} else {
$this->_message = JText::_('COM_INSTALLER_FAILED_TO_PURGE_UPDATES');
return false;
}
}
/**
* Enables any disabled rows in #__update_sites table
*
* @return boolean result of operation
* @since 1.6
*/
public function enableSites()
{
$db = JFactory::getDBO();
$db->setQuery('UPDATE #__update_sites SET enabled = 1 WHERE enabled = 0');
if ($db->Query()) {
if ($rows = $db->getAffectedRows()) {
$this->_message .= JText::plural('COM_INSTALLER_ENABLED_UPDATES', $rows);
}
return true;
} else {
$this->_message .= JText::_('COM_INSTALLER_FAILED_TO_ENABLE_UPDATES');
return false;
}
}
/**
* Update function.
*
* Sets the "result" state with the result of the operation.
*
* @param Array[int] List of updates to apply
* @since 1.6
*/
public function update($uids)
{
$result = true;
foreach($uids as $uid) {
$update = new JUpdate();
$instance = JTable::getInstance('update');
$instance->load($uid);
$update->loadFromXML($instance->detailsurl);
// install sets state and enqueues messages
$res = $this->install($update);
if ($res) {
$instance->delete($uid);
}
$result = $res & $result;
}
// Set the final state
$this->setState('result', $result);
}
/**
* Handles the actual update installation.
*
* @param JUpdate An update definition
* @return boolean Result of install
* @since 1.6
*/
private function install($update)
{
$app = JFactory::getApplication();
if (isset($update->get('downloadurl')->_data)) {
$url = trim($update->downloadurl->_data);
} else {
JError::raiseWarning('', JText::_('COM_INSTALLER_INVALID_EXTENSION_UPDATE'));
return false;
}
$p_file = JInstallerHelper::downloadPackage($url);
// Was the package downloaded?
if (!$p_file) {
JError::raiseWarning('', JText::sprintf('COM_INSTALLER_PACKAGE_DOWNLOAD_FAILED', $url));
return false;
}
$config = JFactory::getConfig();
$tmp_dest = $config->get('tmp_path');
// Unpack the downloaded package file
$package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
// Get an installer instance
$installer = JInstaller::getInstance();
$update->set('type', $package['type']);
// Install the package
if (!$installer->update($package['dir'])) {
// There was an error updating the package
$msg = JText::sprintf('COM_INSTALLER_MSG_UPDATE_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_'.strtoupper($package['type'])));
$result = false;
} else {
// Package updated successfully
$msg = JText::sprintf('COM_INSTALLER_MSG_UPDATE_SUCCESS', JText::_('COM_INSTALLER_TYPE_TYPE_'.strtoupper($package['type'])));
$result = true;
}
// Quick change
$this->type = $package['type'];
// Set some model state values
$app->enqueueMessage($msg);
// TODO: Reconfigure this code when you have more battery life left
$this->setState('name', $installer->get('name'));
$this->setState('result', $result);
$app->setUserState('com_installer.message', $installer->message);
$app->setUserState('com_installer.extension_message', $installer->get('extension_message'));
// Cleanup the install files
if (!is_file($package['packagefile'])) {
$config = JFactory::getConfig();
$package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
}
JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
return $result;
}
}
The same content is in 11 releases, Joomla 2.5.18 to 2.5.28. See them all, or every version of this file.