Skip to content

Commit

Permalink
Define constants for Plugin Priority
Browse files Browse the repository at this point in the history
Previously, these values were hardcoded.

Note that the priority for the MantisCore pseudo-plugin is now set to
HIGHEST instead of 3 previously. This avoids creating another constant,
considering that it makes sense to load this first anyway.

As suggested by @atrol in [[1]].

[1]: #1700 (comment)
  • Loading branch information
dregad committed Sep 23, 2020
1 parent fe3a91c commit 9ffd549
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions core/constant_inc.php
Expand Up @@ -233,6 +233,10 @@
define( 'CONFIRMATION_TYPE_WARNING', 1 );
define( 'CONFIRMATION_TYPE_FAILURE', 2 );

# Plugin management
define( 'PLUGIN_PRIORITY_LOW', 1 );
define( 'PLUGIN_PRIORITY_HIGH', 5 );

# error messages
define( 'ERROR_PHP', -1 );
define( 'ERROR_GENERIC', 0 );
Expand Down
4 changes: 2 additions & 2 deletions core/plugin_api.php
Expand Up @@ -95,8 +95,8 @@ function plugin_pop_current() {
function plugin_get_force_installed() {
$t_forced_plugins = config_get_global( 'plugins_force_installed' );

# MantisCore pseudo-plugin is force-installed by definition, with priority 3
$t_forced_plugins['MantisCore'] = 3;
# MantisCore pseudo-plugin is force-installed by definition
$t_forced_plugins['MantisCore'] = PLUGIN_PRIORITY_HIGH;

return $t_forced_plugins;
}
Expand Down
8 changes: 5 additions & 3 deletions core/print_api.php
Expand Up @@ -1262,12 +1262,14 @@ function print_custom_field_projects_list( $p_field_id ) {
* @return void
*/
function print_plugin_priority_list( $p_priority ) {
if( $p_priority < 1 || $p_priority > 5 ) {
if( $p_priority < PLUGIN_PRIORITY_LOW || $p_priority > PLUGIN_PRIORITY_HIGH ) {
echo '<option value="', $p_priority, '" selected="selected">', $p_priority, '</option>';
}

for( $i = 5;$i >= 1;$i-- ) {
echo '<option value="', $i, '" ', check_selected( $p_priority, $i ), ' >', $i, '</option>';
for( $i = PLUGIN_PRIORITY_HIGH; $i >= PLUGIN_PRIORITY_LOW; $i-- ) {
echo '<option value="', $i, '"';
check_selected( $p_priority, $i );
echo '>', $i, '</option>';
}
}

Expand Down
2 changes: 1 addition & 1 deletion manage_plugin_update.php
Expand Up @@ -64,7 +64,7 @@
}

$f_priority = gpc_get_int( 'priority_'.$t_basename, 3 );
if( $f_priority < 1 || $f_priority > 5 ) {
if( $f_priority < PLUGIN_PRIORITY_LOW || $f_priority > PLUGIN_PRIORITY_HIGH ) {
error_parameters( 'priority_' . $t_basename );
trigger_error( ERROR_INVALID_FIELD_VALUE, ERROR );
}
Expand Down

0 comments on commit 9ffd549

Please sign in to comment.