From: Coleman Watts Date: Thu, 10 Dec 2015 01:12:05 +0000 (-0500) Subject: CRM-17637 - VersionCheck - refactor & centralize lookup of scheduled job X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b864507b51dae9f1eca33f7bc5fe30d6c941205f;p=civicrm-core.git CRM-17637 - VersionCheck - refactor & centralize lookup of scheduled job --- diff --git a/CRM/Utils/Check/Env.php b/CRM/Utils/Check/Env.php index 9a6241ef99..9e2d829882 100644 --- a/CRM/Utils/Check/Env.php +++ b/CRM/Utils/Check/Env.php @@ -288,16 +288,11 @@ class CRM_Utils_Check_Env { */ public function checkVersion() { $messages = array(); + $vc = new CRM_Utils_VersionCheck(); - // See if the version_check job is enabled - $jobs = civicrm_api3('Job', 'get', array( - 'sequential' => 1, - 'api_action' => "version_check", - 'api_entity' => "job", - )); - $jobEnabled = !empty($jobs['values'][0]['is_active']); - if (!$jobEnabled) { - $args = empty($josb['id']) ? array('reset' => 1) : array('reset' => 1, 'action' => 'update', 'id' => $jobs['id']); + // 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. Re-enable the scheduled job to receive important security update notifications.', array(1 => 'href="' . CRM_Utils_System::url('civicrm/admin/job', $args) . '"')), @@ -307,10 +302,8 @@ class CRM_Utils_Check_Env { ); } - $vc = new CRM_Utils_VersionCheck(); - $newerVersion = $vc->isNewerVersionAvailable(); - if ($vc->isInfoAvailable) { + $newerVersion = $vc->isNewerVersionAvailable(); if ($newerVersion['version']) { $vInfo = array( 1 => $newerVersion['version'], @@ -340,7 +333,7 @@ class CRM_Utils_Check_Env { $message = ts('New version %1 is available. The site is currently running %2.', $vInfo); } } - elseif ($jobEnabled) { + elseif (!empty($vc->cronJob['is_active'])) { $vNum = $vc->localVersion; // LTS = long-term support version if ($newerVersion['status'] == 'lts') { diff --git a/CRM/Utils/VersionCheck.php b/CRM/Utils/VersionCheck.php index f0e956a5d7..443151420d 100644 --- a/CRM/Utils/VersionCheck.php +++ b/CRM/Utils/VersionCheck.php @@ -33,8 +33,6 @@ class CRM_Utils_VersionCheck { const PINGBACK_URL = 'http://latest.civicrm.org/stable.php?format=json', - // relative to $civicrm_root - LOCALFILE_NAME = '[civicrm.root]/civicrm-version.php', // relative to $config->uploadDir CACHEFILE_NAME = '[civicrm.files]/persist/version-info-cache.json'; @@ -64,6 +62,11 @@ class CRM_Utils_VersionCheck { */ public $isInfoAvailable; + /** + * @var array + */ + public $cronJob = array(); + /** * Pingback params * @@ -82,16 +85,10 @@ class CRM_Utils_VersionCheck { * Class constructor. */ public function __construct() { - // Populate local version - $localFile = Civi::paths()->getPath(self::LOCALFILE_NAME); - if (file_exists($localFile)) { - require_once $localFile; - } - if (function_exists('civicrmVersion')) { - $info = civicrmVersion(); - $this->localVersion = trim($info['version']); - $this->localMajorVersion = $this->getMajorVersion($this->localVersion); - } + $this->localVersion = CRM_Utils_System::version(); + $this->localMajorVersion = $this->getMajorVersion($this->localVersion); + + $this->getJob(); // Populate remote $versionInfo from cache file $this->cacheFile = Civi::paths()->getPath(self::CACHEFILE_NAME); @@ -394,4 +391,16 @@ class CRM_Utils_VersionCheck { fclose($fp); } + /** + * Lookup version_check scheduled job + */ + private function getJob() { + $jobs = civicrm_api3('Job', 'get', array( + 'sequential' => 1, + 'api_action' => "version_check", + 'api_entity' => "job", + )); + $this->cronJob = CRM_Utils_Array::value(0, $jobs['values'], array()); + } + }