diff options
author | mattab <matthieu.aubry@gmail.com> | 2016-10-02 23:26:40 +0300 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2016-10-02 23:26:40 +0300 |
commit | 75871fcb80678b03f30f978d9183668bd4ceaf2b (patch) | |
tree | 2fd820e2ad73287f9355a7f48d7dcf716d47938e | |
parent | f42860f4b00797d65471746d7f0e65e50fc67012 (diff) |
Warn users (in all admin pages) when the PHP version is not recent enough to upgrade Piwik to latest major version
-rw-r--r-- | core/Plugin/ControllerAdmin.php | 54 | ||||
-rw-r--r-- | lang/en.json | 3 |
2 files changed, 41 insertions, 16 deletions
diff --git a/core/Plugin/ControllerAdmin.php b/core/Plugin/ControllerAdmin.php index e503a615e6..d172051edf 100644 --- a/core/Plugin/ControllerAdmin.php +++ b/core/Plugin/ControllerAdmin.php @@ -153,6 +153,42 @@ abstract class ControllerAdmin extends Controller Notification\Manager::notify('ControllerAdmin_EacceleratorIsUsed', $notification); } + /** + * PHP Version required by the next major Piwik version + * @return string + */ + private static function getNextRequiredMinimumPHP() + { + return '5.5.9'; + } + + private static function isUsingPhpVersionCompatibleWithNextPiwik() + { + return version_compare( PHP_VERSION, self::getNextRequiredMinimumPHP(), '>=' ); + } + + private static function notifyWhenPhpVersionIsNotCompatibleWithNextMajorPiwik() + { + if(self::isUsingPhpVersionCompatibleWithNextPiwik()) { + return; + } + + $youMustUpgradePHP = Piwik::translate('General_YouMustUpgradePhpVersionToReceiveLatestPiwik'); + $message = Piwik::translate('General_PiwikCannotBeUpgradedBecausePhpIsTooOld') + . ' ' + . sprintf(Piwik::translate('General_PleaseUpgradeYourPhpVersionSoYourPiwikDataStaysSecure'), self::getNextRequiredMinimumPHP()) + ; + + $notification = new Notification($message); + $notification->title = $youMustUpgradePHP; + $notification->priority = Notification::PRIORITY_LOW; + $notification->context = Notification::CONTEXT_WARNING; + $notification->type = Notification::TYPE_TRANSIENT; + $notification->flags = Notification::FLAG_NO_CLEAR; + NotificationManager::notify('DeprecatedPHPVersionCheck', $notification); + } + + private static function notifyWhenPhpVersionIsEOL() { $deprecatedMajorPhpVersion = null; @@ -167,9 +203,7 @@ abstract class ControllerAdmin extends Controller return; } - $nextRequiredMinimumPHP = '5.5'; - - $message = Piwik::translate('General_WarningPiwikWillStopSupportingPHPVersion', array($deprecatedMajorPhpVersion, $nextRequiredMinimumPHP)) + $message = Piwik::translate('General_WarningPiwikWillStopSupportingPHPVersion', array($deprecatedMajorPhpVersion, self::getNextRequiredMinimumPHP())) . "\n " . Piwik::translate('General_WarningPhpVersionXIsTooOld', $deprecatedMajorPhpVersion); @@ -243,10 +277,8 @@ abstract class ControllerAdmin extends Controller $view->isSuperUser = Piwik::hasUserSuperUserAccess(); self::notifyAnyInvalidPlugin(); - - self::checkPhpVersion($view); - self::notifyWhenPhpVersionIsEOL(); + self::notifyWhenPhpVersionIsNotCompatibleWithNextMajorPiwik(); self::notifyWhenDebugOnDemandIsEnabled('debug'); self::notifyWhenDebugOnDemandIsEnabled('debug_on_demand'); @@ -271,16 +303,6 @@ abstract class ControllerAdmin extends Controller return "Piwik " . Version::VERSION; } - /** - * Check if the current PHP version is >= 5.3. If not, a warning is displayed - * to the user. - */ - private static function checkPhpVersion($view) - { - $view->phpVersion = PHP_VERSION; - $view->phpIsNewEnough = version_compare($view->phpVersion, '5.3.0', '>='); - } - private static function isPhpVersion53() { return strpos(PHP_VERSION, '5.3') === 0; diff --git a/lang/en.json b/lang/en.json index a9856cc425..bbe45c2a77 100644 --- a/lang/en.json +++ b/lang/en.json @@ -395,6 +395,9 @@ "Warning": "Warning", "WarningPhpVersionXIsTooOld": "The PHP version %s you are using has reached its End of Life (EOL). You are strongly urged to upgrade to a current version, as using this version may expose you to security vulnerabilities and bugs that have been fixed in more recent versions of PHP.", "WarningPiwikWillStopSupportingPHPVersion": "Piwik will stop supporting PHP %1$s in the next major version. Upgrade your PHP to at least PHP %2$s, before it's too late!", + "YouMustUpgradePhpVersionToReceiveLatestPiwik": "You must upgrade your PHP version in order to receive the latest Piwik update.", + "PiwikCannotBeUpgradedBecausePhpIsTooOld": "Piwik cannot be upgraded to the latest major version because your PHP version is too old.", + "PleaseUpgradeYourPhpVersionSoYourPiwikDataStaysSecure": "Please upgrade your PHP version to at least PHP %s so your Piwik analytics data stays secure.", "WarningFileIntegrityNoManifest": "File integrity check could not be performed due to missing manifest.inc.php.", "WarningFileIntegrityNoManifestDeployingFromGit": "If you are deploying Piwik from Git, this message is normal.", "WarningFileIntegrityNoMd5file": "File integrity check could not be completed due to missing md5_file() function.", |