Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix for #9979: Function gpc_isset always return false for a custom da…
…te field

  - add special check for custom date fields
  • Loading branch information
thraxisp committed Dec 31, 2008
1 parent 5c0213e commit 01e68c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
5 changes: 1 addition & 4 deletions bug_report.php
Expand Up @@ -98,12 +98,9 @@
$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug_data->project_id );
foreach( $t_related_custom_field_ids as $t_id ) {
$t_def = custom_field_get_definition( $t_id );
$t_cf_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL );
if ( $t_def['require_report'] && ( !gpc_isset( "custom_field_$t_id" ) || empty( $t_cf_value ) ) ) {
if ( $t_def['require_report'] && !gpc_isset_custom_field( $t_id, $t_def['type'] ) ) {
error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
} else if ( empty( $t_cf_value ) ) {
$t_cf_value = $t_def['default_value'];
}
if ( !custom_field_validate( $t_id, $t_cf_value ) ) {
error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
Expand Down
5 changes: 2 additions & 3 deletions bug_update.php
Expand Up @@ -132,14 +132,13 @@
continue;
}

$t_cf_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL );
if ( $t_def['require_' . $t_custom_status_label] && ( !gpc_isset( "custom_field_$t_id" ) || empty( $t_cf_value ) ) ) {
if ( $t_def['require_' . $t_custom_status_label] && !gpc_isset_custom_field( $t_id, $t_def['type'] ) ) {
error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}

# Only update the field if it is posted
if ( !gpc_isset( "custom_field_$t_id" ) ) {
if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) ) {
continue;
}

Expand Down
18 changes: 17 additions & 1 deletion core/gpc_api.php
Expand Up @@ -120,6 +120,23 @@ function gpc_get_bool( $p_var_name, $p_default = false ) {
# ===================================
# Custom Field Functions
# ===================================
# see if a custom field variable is set. Uses gpc_isset().
function gpc_isset_custom_field( $p_var_name, $p_custom_field_type ) {
switch ($p_custom_field_type ) {
case CUSTOM_FIELD_TYPE_DATE:
// date field is three dropdowns that default to 0
// Dropdowns are always present, so check if they are set
return gpc_isset( "custom_field_" . $p_var_name . "_day" ) &&
gpc_get_int( "custom_field_" . $p_var_name . "_day", 0 ) != 0 &&
gpc_isset( "custom_field_" . $p_var_name . "_month" ) &&
gpc_get_int( "custom_field_" . $p_var_name . "_month", 0 ) != 0 &&
gpc_isset( "custom_field_" . $p_var_name . "_year" ) &&
gpc_get_int( "custom_field_" . $p_var_name . "_year", 0 ) != 0 ;
default:
return gpc_isset( "custom_field_" . $p_var_name);
}
}

# Retrieve a custom field variable. Uses gpc_get().
# If you pass in *no* default, an error will be triggered if
# the variable does not exist
Expand All @@ -136,7 +153,6 @@ function gpc_get_custom_field( $p_var_name, $p_custom_field_type, $p_default = n
if( is_array( $t_values ) ) {
return implode( '|', $t_values );
} else {
echo 'not an array';
return '';
}
break;
Expand Down

0 comments on commit 01e68c3

Please sign in to comment.