Example #1
0
 public function autoupdate()
 {
     $return = array('message' => '');
     // First of all let's check if there are any updates
     $updateInfo = (object) $this->getUpdates(true);
     // There are no updates, there's no point in continuing
     if (!$updateInfo->hasUpdate) {
         return array('message' => array("No available updates found"));
     }
     $return['message'][] = "Update detected, version: " . $updateInfo->version;
     // Ok, an update is found, what should I do?
     $autoupdate = F0FUtilsConfigHelper::getComponentConfigurationValue($this->component, 'autoupdateCli', 1);
     // Let's notifiy the user
     if ($autoupdate == 1 || $autoupdate == 2) {
         $email = F0FUtilsConfigHelper::getComponentConfigurationValue($this->component, 'notificationEmail');
         if (!$email) {
             $return['message'][] = "There isn't an email for notifications, no notification will be sent.";
         } else {
             // Ok, I can send it out, but before let's check if the user set any frequency limit
             $numfreq = F0FUtilsConfigHelper::getComponentConfigurationValue($this->component, 'notificationFreq', 1);
             $freqtime = F0FUtilsConfigHelper::getComponentConfigurationValue($this->component, 'notificationTime', 'day');
             $lastSend = $this->getLastSend();
             $shouldSend = false;
             if (!$numfreq) {
                 $shouldSend = true;
             } else {
                 $check = strtotime('-' . $numfreq . ' ' . $freqtime);
                 if ($lastSend < $check) {
                     $shouldSend = true;
                 } else {
                     $return['message'][] = "Frequency limit hit, I won't send any email";
                 }
             }
             if ($shouldSend) {
                 if ($this->doSendNotificationEmail($updateInfo->version, $email)) {
                     $return['message'][] = "E-mail(s) correctly sent";
                 } else {
                     $return['message'][] = "An error occurred while sending e-mail(s). Please double check your settings";
                 }
                 $this->setLastSend();
             }
         }
     }
     // Let's download and install the latest version
     if ($autoupdate == 1 || $autoupdate == 3) {
         // DO NOT REMOVE THIS. Since we have a plural class name (AdmintoolsModelCpanels) in a singular file (cpanel.php)
         // we have to do this trick in order to load the correct file
         $t = F0FModel::getTmpInstance('Cpanel', 'AdmintoolsModel');
         if (F0FModel::getTmpInstance('Cpanels', 'AdmintoolsModel')->needsDownloadID()) {
             $return['message'][] = "You have to enter the DownloadID in order to update your pro version";
         } else {
             $return['message'][] = $this->doUpdateComponent();
         }
     }
     return $return;
 }
Example #2
0
 /**
  * Load all available updates without going through JUpdate
  *
  * @param   bool  $force  Should I forcibly reload the updates from the server?
  *
  * @return  array
  */
 protected function loadUpdatesClassic($force = false)
 {
     // Is the cache busted? If it is I set $force = true to make sure I download fresh updates
     if (!$force) {
         // Get the cache timeout. On older Joomla! installations it will always default to 6 hours.
         $timeout = 3600 * F0FUtilsConfigHelper::getComponentConfigurationValue('com_installer', 'cachetimeout', '6');
         // Do I need to check for updates?
         $lastCheck = $this->getCommonParameter('lastcheck', 0);
         $now = time();
         if ($now - $lastCheck >= $timeout) {
             $force = true;
         }
     }
     // Get the cached JSON-encoded updates list
     $rawUpdates = $this->getCommonParameter('allUpdates', '');
     // Am I forced to reload the XML file (explicitly or because the cache is busted)?
     if ($force) {
         // Set the timestamp
         $now = time();
         $this->setCommonParameter('lastcheck', $now);
         // Get all available updates
         $updateHelper = new F0FUtilsUpdateExtension();
         $updates = $updateHelper->getUpdatesFromExtension($this->updateSite);
         // Save the raw updates list in the database
         $rawUpdates = json_encode($updates);
         $this->setCommonParameter('allUpdates', $rawUpdates);
     }
     // Decode the updates list
     $updates = json_decode($rawUpdates, true);
     // Walk through the updates and find the ones compatible with our Joomla! and PHP version
     $compatibleUpdates = array();
     // Get the Joomla! version family (e.g. 2.5)
     $jVersion = JVERSION;
     $jVersionParts = explode('.', $jVersion);
     $jVersionShort = $jVersionParts[0] . '.' . $jVersionParts[1];
     // Get the PHP version family (e.g. 5.6)
     $phpVersion = PHP_VERSION;
     $phpVersionParts = explode('.', $phpVersion);
     $phpVersionShort = $phpVersionParts[0] . '.' . $phpVersionParts[1];
     foreach ($updates as $update) {
         // No platform?
         if (!isset($update['targetplatform'])) {
             continue;
         }
         // Wrong platform?
         if ($update['targetplatform']['name'] != 'joomla') {
             continue;
         }
         // Get the target Joomla! version
         $targetJoomlaVersion = $update['targetplatform']['version'];
         $targetVersionParts = explode('.', $targetJoomlaVersion);
         $targetVersionShort = $targetVersionParts[0] . '.' . $targetVersionParts[1];
         // The target version MUST be in the same Joomla! branch
         if ($jVersionShort != $targetVersionShort) {
             continue;
         }
         // If the target version is major.minor.revision we must make sure our current JVERSION is AT LEAST equal to that.
         if (version_compare($targetJoomlaVersion, JVERSION, 'gt')) {
             continue;
         }
         // Do I have target PHP versions?
         if (isset($update['ars-phpcompat'])) {
             $phpCompatible = false;
             foreach ($update['ars-phpcompat'] as $entry) {
                 // Get the target PHP version family
                 $targetPHPVersion = $entry['@attributes']['version'];
                 $targetPHPVersionParts = explode('.', $targetPHPVersion);
                 $targetPHPVersionShort = $targetPHPVersionParts[0] . '.' . $targetPHPVersionParts[1];
                 // The target PHP version MUST be in the same PHP branch
                 if ($phpVersionShort != $targetPHPVersionShort) {
                     continue;
                 }
                 // If the target version is major.minor.revision we must make sure our current PHP_VERSION is AT LEAST equal to that.
                 if (version_compare($targetPHPVersion, PHP_VERSION, 'gt')) {
                     continue;
                 }
                 $phpCompatible = true;
                 break;
             }
             if (!$phpCompatible) {
                 continue;
             }
         }
         // All checks pass. Add this update to the list of compatible updates.
         $compatibleUpdates[] = $update;
     }
     return $compatibleUpdates;
 }