<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.6 |
+ | CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
- * $Id: $
- *
+ * @copyright CiviCRM LLC (c) 2004-2015
*/
class CRM_Utils_VersionCheck {
const
protected $cacheFile;
/**
- * Class constructor
+ * Class constructor.
*/
public function __construct() {
global $civicrm_root;
}
/**
- * Static instance provider
+ * Static instance provider.
*
* Method providing static instance of CRM_Utils_VersionCheck,
* as in Singleton pattern
}
/**
- * Finds the release info for a minor version
+ * Finds the release info for a minor version.
* @param string $version
* @return array|null
*/
return "$a.$b";
}
- /**
- * @return bool
- */
- public function isSecurityUpdateAvailable() {
- $thisVersion = $this->getReleaseInfo($this->localVersion);
- $localVersionDate = CRM_Utils_Array::value('date', $thisVersion, 0);
- foreach ($this->versionInfo as $majorVersion) {
- foreach ($majorVersion['releases'] as $release) {
- if (!empty($release['security']) && $release['date'] > $localVersionDate
- && version_compare($this->localVersion, $release['version']) < 0
- ) {
- if (!$this->ignoreDate || $this->ignoreDate < $release['date']) {
- return TRUE;
- }
- }
- }
- }
- }
/**
* Get the latest version number if it's newer than the local one
*
- * @return string|null
- * Returns version number of the latest release if it is greater than the local version
+ * @return array
+ * Returns version number of the latest release if it is greater than the local version,
+ * along with the type of upgrade (regular/security) needed and the status of the major
+ * version
*/
public function isNewerVersionAvailable() {
- $newerVersion = NULL;
+ $return = array(
+ 'version' => NULL,
+ 'upgrade' => NULL,
+ 'status' => NULL,
+ );
+
if ($this->versionInfo && $this->localVersion) {
- foreach ($this->versionInfo as $majorVersionNumber => $majorVersion) {
- $release = $this->checkBranchForNewVersion($majorVersion);
- if ($release) {
- // If we have a release with the same majorVersion as local, return it
- if ($majorVersionNumber == $this->localMajorVersion) {
- return $release;
- }
- // Search outside the local majorVersion (excluding non-stable)
- elseif ($majorVersion['status'] != 'testing') {
- // We found a new release but don't return yet, keep searching newer majorVersions
- $newerVersion = $release;
- }
+ if (isset($this->versionInfo[$this->localMajorVersion])) {
+ switch (CRM_Utils_Array::value('status', $this->versionInfo[$this->localMajorVersion])) {
+ case 'stable':
+ case 'lts':
+ case 'testing':
+ // look for latest version in this major version
+ $releases = $this->checkBranchForNewVersion($this->versionInfo[$this->localMajorVersion]);
+ if ($releases['newest']) {
+ $return['version'] = $releases['newest'];
+
+ // check for intervening security releases
+ $return['upgrade'] = ($releases['security']) ? 'security' : 'regular';
+ }
+ break;
+
+ case 'eol':
+ default:
+ // look for latest version ever
+ foreach ($this->versionInfo as $majorVersionNumber => $majorVersion) {
+ if ($majorVersionNumber < $this->localMajorVersion || $majorVersion['status'] == 'testing') {
+ continue;
+ }
+ $releases = $this->checkBranchForNewVersion($this->versionInfo[$majorVersionNumber]);
+
+ if ($releases['newest']) {
+ $return['version'] = $releases['newest'];
+
+ // check for intervening security releases
+ $return['upgrade'] = ($releases['security'] || $return['upgrade'] == 'security') ? 'security' : 'regular';
+ }
+ }
+ }
+ $return['status'] = $this->versionInfo[$this->localMajorVersion]['status'];
+ }
+ else {
+ // Figure if the version is really old or really new
+ $wayOld = TRUE;
+
+ foreach ($this->versionInfo as $majorVersionNumber => $majorVersion) {
+ $wayOld = ($this->localMajorVersion < $majorVersionNumber);
+ }
+
+ if ($wayOld) {
+ $releases = $this->checkBranchForNewVersion($majorVersion);
+
+ $return = array(
+ 'version' => $releases['newest'],
+ 'upgrade' => 'security',
+ 'status' => 'eol',
+ );
}
}
}
- return $newerVersion;
+
+ return $return;
}
/**
* @return null|string
*/
private function checkBranchForNewVersion($majorVersion) {
- $newerVersion = NULL;
+ $newerVersion = array(
+ 'newest' => NULL,
+ 'security' => NULL,
+ );
if (!empty($majorVersion['releases'])) {
foreach ($majorVersion['releases'] as $release) {
if (version_compare($this->localVersion, $release['version']) < 0) {
if (!$this->ignoreDate || $this->ignoreDate < $release['date']) {
- $newerVersion = $release['version'];
+ $newerVersion['newest'] = $release['version'];
+ if (CRM_Utils_Array::value('security', $release)) {
+ $newerVersion['security'] = $release['version'];
+ }
}
}
}
}
/**
- * Alert the site admin of new versions of CiviCRM
- * Show the message once a day
- */
- public function versionAlert() {
- $versionAlertSetting = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'versionAlert', NULL, 1);
- $securityAlertSetting = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'securityUpdateAlert', NULL, 3);
- $settingsUrl = CRM_Utils_System::url('civicrm/admin/setting/misc', 'reset=1', FALSE, NULL, FALSE, FALSE, TRUE);
- if (CRM_Core_Permission::check('administer CiviCRM') && $securityAlertSetting > 1 && $this->isSecurityUpdateAvailable()) {
- $session = CRM_Core_Session::singleton();
- if ($session->timer('version_alert', 24 * 60 * 60)) {
- $msg = ts('This version of CiviCRM requires a security update.') .
- '<ul>
- <li><a href="https://civicrm.org/advisory">' . ts('Read advisory') . '</a></li>
- <li><a href="https://civicrm.org/download">' . ts('Download now') . '</a></li>
- <li><a class="crm-setVersionCheckIgnoreDate" href="' . $settingsUrl . '">' . ts('Suppress this message') . '</a></li>
- </ul>';
- $session->setStatus($msg, ts('Security Alert'), 'alert');
- CRM_Core_Resources::singleton()
- ->addScriptFile('civicrm', 'templates/CRM/Admin/Form/Setting/versionCheckOptions.js');
- }
- }
- elseif (CRM_Core_Permission::check('administer CiviCRM') && $versionAlertSetting > 1) {
- $newerVersion = $this->isNewerVersionAvailable();
- if ($newerVersion) {
- $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 => $newerVersion)) .
- '<ul>
- <li><a href="https://civicrm.org/download">' . ts('Download now') . '</a></li>
- <li><a class="crm-setVersionCheckIgnoreDate" href="' . $settingsUrl . '">' . ts('Suppress this message') . '</a></li>
- </ul>';
- $session->setStatus($msg, ts('Update Available'), 'info');
- CRM_Core_Resources::singleton()
- ->addScriptFile('civicrm', 'templates/CRM/Admin/Form/Setting/versionCheckOptions.js');
- }
- }
- }
- }
-
- /**
- * Collect info about the site to be sent as pingback data
+ * Collect info about the site to be sent as pingback data.
*/
private function getSiteStats() {
$config = CRM_Core_Config::singleton();
'uf' => $config->userFramework,
'lang' => $config->lcMessages,
'co' => $config->defaultContactCountry,
- 'ufv' => $config->userFrameworkVersion,
+ 'ufv' => $config->userSystem->getVersion(),
'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*'),
+ 'communityMessagesUrl' => Civi::settings()->get('communityMessagesUrl'),
);
$this->getPayProcStats();
$this->getEntityStats();
}
/**
- * Get active payment processor types
+ * Get active payment processor types.
*/
private function getPayProcStats() {
$dao = new CRM_Financial_DAO_PaymentProcessor();
}
/**
- * Fetch counts from entity tables
+ * Fetch counts from entity tables.
* Add info to the 'entities' array
*/
private function getEntityStats() {
}
/**
- * Save version info to file
+ * Save version info to file.
* @param string $contents
*/
private function writeCacheFile($contents) {