Exemplo n.º 1
0
 public function update($uids)
 {
     $result = true;
     foreach ($uids as $uid) {
         $update = new JUpdate();
         $instance = JTable::getInstance('update');
         $instance->load($uid);
         $update->loadFromXML($instance->detailsurl);
         $update->set('extra_query', $instance->extra_query);
         // 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);
 }
Exemplo n.º 2
0
 /**
  * Handles the actual update installation.
  *
  * @param   JUpdate  $update  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 = $update->downloadurl->_data;
         $extra_query = $update->get('extra_query');
         if ($extra_query) {
             if (strpos($url, '?') === false) {
                 $url .= '?';
             } else {
                 $url .= '&';
             }
             $url .= $extra_query;
         }
     } 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;
 }
Exemplo n.º 3
0
 public function doInstallUpdate($update_row)
 {
     // Load
     $this->out('Loading update #' . $update_row->update_id . '...');
     $update = new JUpdate();
     $updateRow = JTable::getInstance('update');
     $updateRow->load($update_row->update_id);
     $update->loadFromXml($updateRow->detailsurl, $this->installer->params->get('minimum_stability', JUpdater::STABILITY_STABLE, 'int'));
     $update->set('extra_query', $updateRow->extra_query);
     // Download
     $tmpPath = $this->config->get('tmp_path');
     if (!is_writeable($tmpPath)) {
         $tmpPath = JPATH_BASE . '/tmp';
     }
     $url = $update->downloadurl->_data;
     if ($extra_query = $update->get('extra_query')) {
         $url .= strpos($url, '?') === false ? '?' : '&';
         $url .= $extra_query;
     }
     $this->out(' - Download ' . $url);
     $p_file = JInstallerHelper::downloadPackage($url);
     if ($p_file) {
         $filePath = $tmpPath . '/' . $p_file;
     } else {
         $this->out(' - Download Failed, Attempting alternate download method...');
         $urlFile = preg_replace('/^.*\\/(.*?)$/', '$1', $url);
         $filePath = $tmpPath . '/' . $urlFile;
         if ($fileHandle = @fopen($filePath, 'w+')) {
             $curl = curl_init($url);
             curl_setopt_array($curl, [CURLOPT_URL => $url, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_BINARYTRANSFER => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FILE => $fileHandle, CURLOPT_TIMEOUT => 50, CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)']);
             $response = curl_exec($curl);
             if ($response === false) {
                 $this->out(' - Download Failed: ' . curl_error($curl));
                 return false;
             }
         } else {
             $this->out(' - Download Failed, Error writing ' . $filePath);
             return false;
         }
     }
     // Catch Error
     if (!is_file($filePath)) {
         $this->out(' - Download Failed/ File not found');
         return false;
     }
     // Extracting Package
     $this->out(' - Extracting Package...');
     $package = JInstallerHelper::unpack($filePath);
     if (!$package) {
         $this->out(' - Extract Failed');
         JInstallerHelper::cleanupInstall($filePath);
         return false;
     }
     // Install the package
     $this->out(' - Installing ' . $package['dir'] . '...');
     $installer = JInstaller::getInstance();
     $update->set('type', $package['type']);
     if (!$installer->update($package['dir'])) {
         $this->out(' - Update Error');
         $result = false;
     } else {
         $this->out(' - Update Success');
         $result = true;
     }
     // Cleanup the install files
     $this->out(' - Cleanup');
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     // Complete
     return $result;
 }