Skip to content

Commit

Permalink
Add admin check to validate date custom fields
Browse files Browse the repository at this point in the history
Issue #27956
  • Loading branch information
dregad committed Feb 21, 2021
1 parent efd8d1f commit 65b5287
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
77 changes: 77 additions & 0 deletions admin/check/check_customfields_inc.php
@@ -0,0 +1,77 @@
<?php
# MantisBT - A PHP based bugtracking system

# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.

/**
* Custom Fields Checks
* @package MantisBT
* @copyright Copyright (C) 2021 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link https://mantisbt.org
*
* @uses check_api.php
* @uses config_api.php
* @uses constant_inc.php
*/

if( !defined( 'CHECK_CUSTOMFIELDS_INC_ALLOW' ) ) {
return;
}

# MantisBT Check API
require_once( 'check_api.php' );
require_api( 'config_api.php' );
require_api( 'constant_inc.php' );

check_print_section_header_row( 'Custom Fields' );

# Check for deprecated usage of {} in Date CF default values
$t_date_cf_with_bracket = array();
foreach( custom_field_get_ids() as $t_id ) {
/**
* @var int $v_id
* @var string $v_name
* @var int $v_type
* @var string|int $v_default_value
*/
extract( custom_field_get_definition( $t_id ), EXTR_PREFIX_ALL, 'v');

if( $v_type != CUSTOM_FIELD_TYPE_DATE ) {
continue;
}
if( preg_match( '/^{(.*)}$/', $v_default_value, $t_matches ) ) {
$t_date_cf_with_bracket[$v_name] = array( $v_id, $t_matches[1] );
}
}
if( $t_date_cf_with_bracket ) {
$t_manage_cf_link = '<a href="'
. helper_mantis_url( 'manage_custom_field_edit_page.php' )
. '?field_id=%d">Edit the Custom Field</a>';
ksort( $t_date_cf_with_bracket );
foreach( $t_date_cf_with_bracket as $t_name => list( $t_id, $t_new_value ) ) {
check_print_test_warn_row(
"Date Custom Field '$t_name' specifies its Default Value with deprecated curly brackets format.",
false,
array( false => "Use the same format, but without the '{}', i.e. '$t_new_value'. "
. sprintf( $t_manage_cf_link, $t_id )
)
);
}
} else {
check_print_test_warn_row(
'Deprecated usage of curly brackets in Date Custom Fields default value',
true,
''
);
}
7 changes: 6 additions & 1 deletion admin/check/index.php
Expand Up @@ -184,6 +184,11 @@ function mode_url( $p_all, $p_errors ) {
include( 'check_display_inc.php' );
}

if( !$g_failed_test ) {
define( 'CHECK_CUSTOMFIELDS_INC_ALLOW', true );
include( 'check_customfields_inc.php' );
}

if( !$g_failed_test ) {
define( 'CHECK_PLUGINS_INC_ALLOW', true );
include( 'check_plugins_inc.php' );
Expand All @@ -199,7 +204,7 @@ function mode_url( $p_all, $p_errors ) {

<?php if( $g_failed_test ) { ?>
<div class="alert alert-danger" id="check-notice-failed">
Some tests failed. Please review and correct these failed tests before using MantisBT.
Some tests failed. Please review, correct them and run the checks again before using MantisBT.
</div>
<?php } else if( $g_passed_test_with_warnings ) { ?>
<div class="alert alert-warning" id="check-notice-warnings">
Expand Down

0 comments on commit 65b5287

Please sign in to comment.