Skip to content

Commit

Permalink
Fix MantisCore plugin dependencies
Browse files Browse the repository at this point in the history
In issue #17360, we introduced setting a default maximum version for
MantisCore to avoid compatibility issues by disabling plugins which have
not been updated for a new Mantis release, with a break on every minor
version (x.Y.z).

With 2.0 and the decision to only introduce breaking changes on major
versions (X.y.z), this code has to be changed.

Fixes #22171
  • Loading branch information
dregad committed Jan 25, 2017
1 parent b840255 commit 574dfa2
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions core/plugin_api.php
Expand Up @@ -494,38 +494,20 @@ 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.
# Set maximum dependency for MantisCore if none is specified.
# This effectively disables plugins which have not been specifically
# designed for a new major Mantis release to force authors to review
# their code, adapt it if necessary, and release a new version of the
# plugin with updated dependencies.
if( $p_base_name == 'MantisCore' && strpos( $p_required, '<' ) === false ) {
$t_version_core = substr(
$t_plugin_version,
0,
strpos( $t_plugin_version, '.', strpos( $t_plugin_version, '.' ) + 1 )
);
$t_version_core = utf8_substr( $t_plugin_version, 0, strpos( $t_plugin_version, '.' ) );
$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 ) {
# Add current major version as maximum
$t_required_array[] = '<' . $t_version_core;
}
}
Expand Down

0 comments on commit 574dfa2

Please sign in to comment.