Merge pull request #3476 from eileenmcnaughton/CRM-14838
[civicrm-core.git] / CRM / Utils / VersionCheck.php
index b6a7e1e0e10b4304764b7417a62d6d1bab70011f..bea90d1e17e09f280b4319c25fa108efc9964912 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -41,8 +41,8 @@ class CRM_Utils_VersionCheck {
     LOCALFILE_NAME = 'civicrm-version.php',
     // relative to $config->uploadDir
     CACHEFILE_NAME = 'latest-version-cache.txt',
-    // cachefile expiry time (in seconds) - a week
-    CACHEFILE_EXPIRE = 604800;
+    // cachefile expiry time (in seconds) - one day
+    CACHEFILE_EXPIRE = 86400;
 
   /**
    * We only need one instance of this object, so we use the
@@ -90,7 +90,7 @@ class CRM_Utils_VersionCheck {
       require_once ($localfile);
       if (function_exists('civicrmVersion')) {
         $info = civicrmVersion();
-        $this->localVersion = $info['version'];
+        $this->localVersion = trim($info['version']);
       }
     }
     if ($config->versionCheck) {
@@ -99,7 +99,7 @@ class CRM_Utils_VersionCheck {
       // if there's a cachefile and it's not stale use it to
       // read the latestVersion, else read it from the Internet
       if (file_exists($cachefile) && (filemtime($cachefile) > $expiryTime)) {
-        $this->latestVersion = file_get_contents($cachefile);
+        $this->latestVersion = trim(file_get_contents($cachefile));
       }
       else {
         $siteKey = md5(defined('CIVICRM_SITE_KEY') ? CIVICRM_SITE_KEY : '');
@@ -113,6 +113,7 @@ class CRM_Utils_VersionCheck {
           'ufv' => $config->userFrameworkVersion,
           'PHP' => phpversion(),
           'MySQL' => CRM_CORE_DAO::singleValueQuery('SELECT VERSION()'),
+          'communityMessagesUrl' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'communityMessagesUrl', NULL, '*default*'),
         );
 
         // Add usage stats
@@ -160,20 +161,12 @@ class CRM_Utils_VersionCheck {
    * Get the latest version number if it's newer than the local one
    *
    * @return string|null
-   * Returns the newer version's number or null if the versions are equal
+   * Returns the newer version's number, or null if the versions are equal
    */
   public function newerVersion() {
     if ($this->latestVersion) {
-      $local = array_pad(explode('.', $this->localVersion), 3, 0);
-      $latest = array_pad(explode('.', $this->latestVersion), 3, 0);
-
-      for ($i = 0; $i < 3; $i++) {
-        if ($local[$i] > $latest[$i]) {
-          return NULL;
-        }
-        elseif ($local[$i] < $latest[$i]) {
-          return $this->latestVersion;
-        }
+      if (version_compare($this->localVersion, $this->latestVersion) < 0) {
+        return $this->latestVersion;
       }
     }
     return NULL;
@@ -184,7 +177,8 @@ class CRM_Utils_VersionCheck {
    * Show the message once a day
    */
   public function versionAlert() {
-    if (CRM_Core_Permission::check('administer CiviCRM') && $this->newerVersion()) {
+    if (CRM_Core_Permission::check('administer CiviCRM') && $this->newerVersion()
+    && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'versionAlert', NULL, TRUE)) {
       $session = CRM_Core_Session::singleton();
       if ($session->timer('version_alert', 24 * 60 * 60)) {
         $msg = ts('A newer version of CiviCRM is available: %1', array(1 => $this->latestVersion))
@@ -230,7 +224,7 @@ class CRM_Utils_VersionCheck {
       'CRM_Contribute_DAO_ContributionProduct' => NULL,
       'CRM_Contribute_DAO_Widget' => 'is_active = 1',
       'CRM_Core_DAO_Discount' => NULL,
-      'CRM_Price_DAO_SetEntity' => NULL,
+      'CRM_Price_DAO_PriceSetEntity' => NULL,
       'CRM_Core_DAO_UFGroup' => 'is_active = 1',
       'CRM_Event_DAO_Event' => 'is_active = 1',
       'CRM_Event_DAO_Participant' => 'is_test = 0',
@@ -301,6 +295,9 @@ class CRM_Utils_VersionCheck {
     if (!preg_match('/^\d+\.\d+\.\d+$/', $this->latestVersion)) {
       $this->latestVersion = NULL;
     }
+    else {
+      $this->latestVersion = trim($this->latestVersion);
+    }
     ini_restore('default_socket_timeout');
   }