Exemplo n.º 1
0
 /**
  * @dataProvider securityUpdateDataProvider
  * @param string $localVersion
  * @param array $versionInfo
  * @param bool $expectedResult
  */
 public function testSecurityUpdate($localVersion, $versionInfo, $expectedResult)
 {
     $vc = new CRM_Utils_VersionCheck();
     // These values are set by the constructor but for testing we override them
     $vc->localVersion = $localVersion;
     $vc->localMajorVersion = $vc->getMajorVersion($localVersion);
     $vc->setVersionInfo($versionInfo);
     $available = $vc->isNewerVersionAvailable();
     $this->assertEquals($available['upgrade'], $expectedResult);
 }
Exemplo n.º 2
0
 /**
  * Checks if new versions are available
  * @return array
  */
 public function checkVersion()
 {
     $messages = array();
     try {
         $vc = new CRM_Utils_VersionCheck();
         $vc->initialize();
     } catch (Exception $e) {
         $messages[] = new CRM_Utils_Check_Message('checkVersionError', ts('Directory %1 is not writable.  Please change your file permissions.', array(1 => dirname($vc->cacheFile))), ts('Directory not writable'), \Psr\Log\LogLevel::ERROR, 'fa-times-circle-o');
         return $messages;
     }
     // Show a notice if the version_check job is disabled
     if (empty($vc->cronJob['is_active'])) {
         $args = empty($vc->cronJob['id']) ? array('reset' => 1) : array('reset' => 1, 'action' => 'update', 'id' => $vc->cronJob['id']);
         $messages[] = new CRM_Utils_Check_Message('checkVersionDisabled', ts('The check for new versions of CiviCRM has been disabled. <a %1>Re-enable the scheduled job</a> to receive important security update notifications.', array(1 => 'href="' . CRM_Utils_System::url('civicrm/admin/job', $args) . '"')), ts('Update Check Disabled'), \Psr\Log\LogLevel::NOTICE, 'fa-times-circle-o');
     }
     if ($vc->isInfoAvailable) {
         $newerVersion = $vc->isNewerVersionAvailable();
         if ($newerVersion['version']) {
             $vInfo = array(1 => $newerVersion['version'], 2 => $vc->localVersion);
             // LTS = long-term support version
             if ($newerVersion['status'] == 'lts') {
                 $vInfo[1] .= ' ' . ts('(long-term support)');
             }
             if ($newerVersion['upgrade'] == 'security') {
                 // Security
                 $severity = \Psr\Log\LogLevel::CRITICAL;
                 $title = ts('CiviCRM Security Update Required');
                 $message = ts('New security release %1 is available. The site is currently running %2.', $vInfo);
             } elseif ($newerVersion['status'] == 'eol') {
                 // Warn about EOL
                 $severity = \Psr\Log\LogLevel::WARNING;
                 $title = ts('CiviCRM Update Needed');
                 $message = ts('New version %1 is available. The site is currently running %2, which has reached its end of life.', $vInfo);
             } else {
                 // For most new versions, just make them notice
                 $severity = \Psr\Log\LogLevel::NOTICE;
                 $title = ts('CiviCRM Update Available');
                 $message = ts('New version %1 is available. The site is currently running %2.', $vInfo);
             }
         } elseif (!empty($vc->cronJob['is_active'])) {
             $vNum = $vc->localVersion;
             // LTS = long-term support version
             if ($newerVersion['status'] == 'lts') {
                 $vNum .= ' ' . ts('(long-term support)');
             }
             $severity = \Psr\Log\LogLevel::INFO;
             $title = ts('CiviCRM Up-to-Date');
             $message = ts('CiviCRM version %1 is up-to-date.', array(1 => $vNum));
         }
         if (!empty($message)) {
             $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, $message, $title, $severity, 'fa-cloud-upload');
         }
     }
     return $messages;
 }