From 2e97d61e89008db1194cf2b2957036966c946e06 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 7 Nov 2012 19:38:25 +0000 Subject: [PATCH] Use version_compare(), unregister only registered filters: - The old version comparison is not really safe, so better use version_compare() with third parameter (compare operator) - Now only registered extensions will be unregistered, as this would needlessly delete filter cache file --- inc/extensions-functions.php | 15 +++++++-------- inc/filter-functions.php | 2 +- inc/wrapper-functions.php | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php index 2d399daf11..013babf309 100644 --- a/inc/extensions-functions.php +++ b/inc/extensions-functions.php @@ -998,15 +998,14 @@ function doDeactivateExtension ($ext_name, $inRebuild = FALSE) { // Checks whether the extension is older than given function isExtensionOlder ($ext_name, $ext_ver) { - // Get current extension version - $currVersion = getExtensionVersion($ext_name); - - // Remove all dots from both versions - $currVersion = str_replace('.', '', $currVersion); - $ext_ver = str_replace('.', '', $ext_ver); + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) { + // Determine it + $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = (version_compare(getExtensionVersion($ext_name), $ext_ver, '<') === TRUE); + } // END - if - // Now compare both and return the result - return ($currVersion < $ext_ver); + // Return cache + return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver]; } // Creates a new task for updated extension diff --git a/inc/filter-functions.php b/inc/filter-functions.php index 5a74891427..8a11ac1067 100644 --- a/inc/filter-functions.php +++ b/inc/filter-functions.php @@ -263,7 +263,7 @@ function unregisterFilter ($F, $L, $filterName, $filterFunction, $force = FALSE, } // END - if // Shall we remove? (default, not while just showing an extension removal) - if ($isDryRun === FALSE) { + if (($isDryRun === FALSE) && (isset($GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction]))) { // Mark for filter removal //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'F=' . $F . ',L=' . $L . ',filterName=' . $filterName . ',filterFunction=' . $filterFunction . ' - REMOVE!'); $GLOBALS['cache_array']['filter']['chains'][$filterName][$filterFunction] = 'R'; diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index e0569e68e6..3cb8113529 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -756,35 +756,35 @@ function redirectToDereferedUrl ($url) { } // Wrapper function for checking if extension is installed and newer or same version -function isExtensionInstalledAndNewer ($ext_name, $version) { +function isExtensionInstalledAndNewer ($ext_name, $ext_ver) { // Is an cache entry found? - if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) { + if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) { // Determine it - $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version)); + $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '>=') === TRUE)); } else { // Cache hits should be incremented twice incrementStatsEntry('cache_hits', 2); } // Return it - //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version])); - return $GLOBALS[__FUNCTION__][$ext_name][$version]; + //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])); + return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver]; } // Wrapper function for checking if extension is installed and older than given version -function isExtensionInstalledAndOlder ($ext_name, $version) { +function isExtensionInstalledAndOlder ($ext_name, $ext_ver) { // Is an cache entry found? - if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) { + if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) { // Determine it - $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version))); + $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $ext_ver))); } else { // Cache hits should be incremented twice incrementStatsEntry('cache_hits', 2); } // Return it - //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version])); - return $GLOBALS[__FUNCTION__][$ext_name][$version]; + //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])); + return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver]; } // Set username -- 2.39.2