From f5882b33c2796918e75e12ae94e45e4a1661da21 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Wed, 23 Jul 2014 01:00:05 +0200 Subject: [PATCH 1/4] Plugin dependency fail with new Mantis release If the plugin's minimum dependency for MantisCore is unspecified or lower than the current release (i.e. the plugin does not specifically list the current core version as supported) and the plugin does not define a maximum dependency, we add one with the current version's minor release (i.e. for 1.3.1 we would add '<1.3'). The purpose of this is to avoid compatibility issues by disabling plugins which have not been updated for a new Mantis release; authors have to revise their code (if necessary), and release a new version of the plugin with updated dependencies. Fixes #17360 --- core/plugin_api.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/core/plugin_api.php b/core/plugin_api.php index bdc9ef2925..41b8a65e7c 100644 --- a/core/plugin_api.php +++ b/core/plugin_api.php @@ -555,6 +555,42 @@ function plugin_dependency( $p_base_name, $p_required, $p_initialized = false ) $t_required_array = explode( ',', $p_required ); + # If the plugin's minimum dependency for MantisCore is unspecified or + # lower than the current release (i.e. the plugin does not specifically + # list the current core version as supported) and the plugin does not + # define a maximum dependency, we add one with the current version's + # minor release (i.e. for 1.3.1 we would add '<1.3'). + # The purpose of this is to avoid compatibility issues by disabling + # plugins which have not been updated for a new Mantis release; authors + # have to revise their code (if necessary), and release a new version + # of the plugin with updated dependencies. + # To indicate compatibility (e.g. with release 1.3), one can either: + # 1. update the minimum required version (i.e. plugin only works with + # 1.3; 1.2-compatible code is maintained separately): + # $this->requires = array( 'MantisCore' => '1.3' ); + # 2. add the new release as a 2nd minimum version (i.e. the plugin is + # compatible with both versions): + # $this->requires = array( 'MantisCore' => '1.2, 1.3' ); + # 3. add a maximum version higher than the new release: + # $this->requires = array( 'MantisCore' => '1.2, <2.0' ); + # Note that this may cause the plugin to face compatibility issues + # if and when a version 1.4 is released. + if( $p_base_name == 'MantisCore' && strpos( $p_required, '<' ) === false ) { + $t_version_core = substr( + MANTIS_VERSION, + 0, + strpos( MANTIS_VERSION, '.', strpos( MANTIS_VERSION, '.' ) + 1 ) + ); + $t_is_current_core_supported = false; + foreach( $t_required_array as $t_version_required ) { + $t_is_current_core_supported = $t_is_current_core_supported + || version_compare( trim( $t_version_required ), $t_version_core, ">=" ); + } + if( !$t_is_current_core_supported ) { + $t_required_array[] = '<' . $t_version_core; + } + } + foreach( $t_required_array as $t_required ) { $t_required = trim( $t_required ); $t_maximum = false; From ab9ff88cc1acea208bda2fc31b5b858e486405e3 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Wed, 23 Jul 2014 01:04:47 +0200 Subject: [PATCH 2/4] Rename variables to improve code readability --- core/plugin_api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/plugin_api.php b/core/plugin_api.php index 41b8a65e7c..4a3c591dd9 100644 --- a/core/plugin_api.php +++ b/core/plugin_api.php @@ -608,10 +608,10 @@ function plugin_dependency( $p_base_name, $p_required, $p_initialized = false ) } } - $t_version1 = plugin_version_array( $g_plugin_cache[$p_base_name]->version ); - $t_version2 = plugin_version_array( $t_required ); + $t_version_installed = plugin_version_array( $g_plugin_cache[$p_base_name]->version ); + $t_version_required = plugin_version_array( $t_required ); - $t_check = plugin_version_check( $t_version1, $t_version2, $t_maximum ); + $t_check = plugin_version_check( $t_version_installed, $t_version_required, $t_maximum ); if( $t_check < 1 ) { return $t_check; From 50d9df3dd756c45f9e4e2c59a38d2911fa0dcf63 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Wed, 23 Jul 2014 01:05:40 +0200 Subject: [PATCH 3/4] Code optimization The plugin's base name and cache will not change between iterations, so we improve performance by moving $t_version_installed's initialization outside of the foreach loop. --- core/plugin_api.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/plugin_api.php b/core/plugin_api.php index 4a3c591dd9..2dc35b41ab 100644 --- a/core/plugin_api.php +++ b/core/plugin_api.php @@ -591,6 +591,8 @@ function plugin_dependency( $p_base_name, $p_required, $p_initialized = false ) } } + $t_version_installed = plugin_version_array( $g_plugin_cache[$p_base_name]->version ); + foreach( $t_required_array as $t_required ) { $t_required = trim( $t_required ); $t_maximum = false; @@ -608,7 +610,6 @@ function plugin_dependency( $p_base_name, $p_required, $p_initialized = false ) } } - $t_version_installed = plugin_version_array( $g_plugin_cache[$p_base_name]->version ); $t_version_required = plugin_version_array( $t_required ); $t_check = plugin_version_check( $t_version_installed, $t_version_required, $t_maximum ); From bc8e9a59374c1cd30523759af1298262127c1eed Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sat, 9 Aug 2014 01:07:05 +0200 Subject: [PATCH 4/4] Coding guidelines --- core/plugin_api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/plugin_api.php b/core/plugin_api.php index 2dc35b41ab..982b78bc3e 100644 --- a/core/plugin_api.php +++ b/core/plugin_api.php @@ -584,7 +584,7 @@ function plugin_dependency( $p_base_name, $p_required, $p_initialized = false ) $t_is_current_core_supported = false; foreach( $t_required_array as $t_version_required ) { $t_is_current_core_supported = $t_is_current_core_supported - || version_compare( trim( $t_version_required ), $t_version_core, ">=" ); + || version_compare( trim( $t_version_required ), $t_version_core, '>=' ); } if( !$t_is_current_core_supported ) { $t_required_array[] = '<' . $t_version_core;