Source for file update.php

Documentation is available at update.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_joomlaupdate
  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. /**
  13.  * The Joomla! update controller for the Update view
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_joomlaupdate
  17.  * @since       2.5.4
  18.  */
  19. {
  20.     /**
  21.      * Performs the download of the update package
  22.      *
  23.      * @return  void 
  24.      *
  25.      * @since   2.5.4
  26.      */
  27.     public function download()
  28.     {
  29.         $options['format''{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
  30.         $options['text_file''joomla_update.php';
  31.         JLog::addLogger($optionsJLog::INFOarray('Update''databasequery''jerror'));
  32.         $user JFactory::getUser();
  33.         JLog::add(JText::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_START'$user->id$user->nameJVERSION)JLog::INFO'Update');
  34.  
  35.         $this->_applyCredentials();
  36.  
  37.         $model $this->getModel('Default');
  38.         $file $model->download();
  39.  
  40.         $message null;
  41.         $messageType null;
  42.  
  43.         if ($file)
  44.         {
  45.             JFactory::getApplication()->setUserState('com_joomlaupdate.file'$file);
  46.             $url 'index.php?option=com_joomlaupdate&task=update.install';
  47.             JLog::add(JText::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_FILE'$file)JLog::INFO'Update');
  48.         }
  49.         else
  50.         {
  51.             JFactory::getApplication()->setUserState('com_joomlaupdate.file'null);
  52.             $url 'index.php?option=com_joomlaupdate';
  53.             $message JText::_('COM_JOOMLAUPDATE_VIEW_UPDATE_DOWNLOADFAILED');
  54.         }
  55.  
  56.         $this->setRedirect($url$message$messageType);
  57.     }
  58.  
  59.     /**
  60.      * Start the installation of the new Joomla! version
  61.      *
  62.      * @return  void 
  63.      *
  64.      * @since   2.5.4
  65.      */
  66.     public function install()
  67.     {
  68.         $options['format''{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
  69.         $options['text_file''joomla_update.php';
  70.         JLog::addLogger($optionsJLog::INFOarray('Update''databasequery''jerror'));
  71.         JLog::add(JText::_('COM_JOOMLAUPDATE_UPDATE_LOG_INSTALL')JLog::INFO'Update');
  72.  
  73.         $this->_applyCredentials();
  74.  
  75.         $model $this->getModel('Default');
  76.  
  77.         $file JFactory::getApplication()->getUserState('com_joomlaupdate.file'null);
  78.         $model->createRestorationFile($file);
  79.  
  80.         $this->display();
  81.     }
  82.  
  83.     /**
  84.      * Finalise the upgrade by running the necessary scripts
  85.      *
  86.      * @return  void 
  87.      *
  88.      * @since   2.5.4
  89.      */
  90.     public function finalise()
  91.     {
  92.         $options['format''{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
  93.         $options['text_file''joomla_update.php';
  94.         JLog::addLogger($optionsJLog::INFOarray('Update''databasequery''jerror'));
  95.         JLog::add(JText::_('COM_JOOMLAUPDATE_UPDATE_LOG_FINALISE')JLog::INFO'Update');
  96.         $this->_applyCredentials();
  97.  
  98.         $model $this->getModel('Default');
  99.  
  100.         $model->finaliseUpgrade();
  101.  
  102.         $url 'index.php?option=com_joomlaupdate&task=update.cleanup';
  103.         $this->setRedirect($url);
  104.     }
  105.  
  106.     /**
  107.      * Clean up after ourselves
  108.      *
  109.      * @return  void 
  110.      *
  111.      * @since   2.5.4
  112.      */
  113.     public function cleanup()
  114.     {
  115.         $options['format''{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
  116.         $options['text_file''joomla_update.php';
  117.         JLog::addLogger($optionsJLog::INFOarray('Update''databasequery''jerror'));
  118.         JLog::add(JText::_('COM_JOOMLAUPDATE_UPDATE_LOG_CLEANUP')JLog::INFO'Update');
  119.         $this->_applyCredentials();
  120.  
  121.         $model $this->getModel('Default');
  122.  
  123.         $model->cleanUp();
  124.  
  125.         $url 'index.php?option=com_joomlaupdate&layout=complete';
  126.         $this->setRedirect($url);
  127.         JLog::add(JText::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_COMPLETE'JVERSION)JLog::INFO'Update');
  128.     }
  129.  
  130.     /**
  131.      * Purges updates.
  132.      *
  133.      * @return  void 
  134.      *
  135.      * @since    3.0
  136.      */
  137.     public function purge()
  138.     {
  139.         // Purge updates
  140.         // Check for request forgeries
  141.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  142.         $model $this->getModel('Default');
  143.         $model->purge();
  144.  
  145.         $url 'index.php?option=com_joomlaupdate';
  146.         $this->setRedirect($url$model->_message);
  147.     }
  148.  
  149.     /**
  150.      * Method to display a view.
  151.      *
  152.      * @param   boolean  $cachable   If true, the view output will be cached
  153.      * @param   array    $urlparams  An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  154.      *
  155.      * @return  JoomlaupdateControllerUpdate  This object to support chaining.
  156.      *
  157.      * @since    2.5.4
  158.      */
  159.     public function display($cachable false$urlparams array())
  160.     {
  161.         // Get the document object.
  162.         $document JFactory::getDocument();
  163.  
  164.         // Set the default view name and format from the Request.
  165.         $vName   $this->input->get('view''update');
  166.         $vFormat $document->getType();
  167.         $lName   $this->input->get('layout''default');
  168.  
  169.         // Get and render the view.
  170.         if ($view $this->getView($vName$vFormat))
  171.         {
  172.             // Get the model for the view.
  173.             $model $this->getModel('Default');
  174.  
  175.             // Push the model into the view (as default).
  176.             $view->setModel($modeltrue);
  177.             $view->setLayout($lName);
  178.  
  179.             // Push document object into the view.
  180.             $view->document $document;
  181.             $view->display();
  182.         }
  183.  
  184.         return $this;
  185.     }
  186.  
  187.     /**
  188.      * Applies FTP credentials to Joomla! itself, when required
  189.      *
  190.      * @return  void 
  191.      *
  192.      * @since    2.5.4
  193.      */
  194.     protected function _applyCredentials()
  195.     {
  196.         if (!JClientHelper::hasCredentials('ftp'))
  197.         {
  198.             $user JFactory::getApplication()->getUserStateFromRequest('com_joomlaupdate.ftp_user''ftp_user'null'raw');
  199.             $pass JFactory::getApplication()->getUserStateFromRequest('com_joomlaupdate.ftp_pass''ftp_pass'null'raw');
  200.  
  201.             if ($user != '' && $pass != '')
  202.             {
  203.                 // Add credentials to the session
  204.                 if (!JClientHelper::setCredentials('ftp'$user$pass))
  205.                 {
  206.                     JError::raiseWarning('SOME_ERROR_CODE'JText::_('JLIB_CLIENT_ERROR_HELPER_SETCREDENTIALSFROMREQUEST_FAILED'));
  207.                 }
  208.             }
  209.         }
  210.     }
  211. }

Documentation generated on Tue, 19 Nov 2013 15:16:08 +0100 by phpDocumentor 1.4.3