Skip to content

Commit

Permalink
updates for #4009 from RJelinek
Browse files Browse the repository at this point in the history
git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@2871 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
mantis committed Aug 20, 2004
1 parent 3721925 commit dbd2e96
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 18 deletions.
48 changes: 39 additions & 9 deletions admin/upgrades/0_18_inc.php
Expand Up @@ -8,7 +8,7 @@
# Changes applied to 0.18 database

# --------------------------------------------------------
# $Id: 0_18_inc.php,v 1.22 2004-08-14 15:26:20 thraxisp Exp $
# $Id: 0_18_inc.php,v 1.23 2004-08-20 23:02:40 prichards Exp $
# --------------------------------------------------------
?>
<?php
Expand Down Expand Up @@ -606,15 +606,45 @@ function upgrade_0_18_del_admin_override() {
return true;
}

$upgrades[] = new SQLUpgrade(
'0.18-bugnote-limit',
"Add email_bugnote_limit to user preference table",
"ALTER TABLE $t_user_pref_table ADD email_bugnote_limit INT( 2 ) NOT NULL AFTER email_on_new_minimum_severity" );
$upgrades[] = new SQLUpgrade(
'0.18-bugnote-limit',
'Add email_bugnote_limit to user preference table',
"ALTER TABLE $t_user_pref_table ADD email_bugnote_limit INT( 2 ) NOT NULL AFTER email_on_new_minimum_severity" );

$upgrades[] = new SQLUpgrade(
'0.18-bugnote-order',
"Add bugnote_order to user preference table",
"ALTER TABLE $t_user_pref_table ADD bugnote_order VARCHAR( 4 ) NOT NULL DEFAULT '" . config_get( 'default_bugnote_order' ) . "' AFTER redirect_delay" );
$upgrades[] = new SQLUpgrade(
'0.18-bugnote-order',
'Add bugnote_order to user preference table',
"ALTER TABLE $t_user_pref_table ADD bugnote_order VARCHAR( 4 ) NOT NULL DEFAULT '" . config_get( 'default_bugnote_order' ) . "' AFTER redirect_delay" );

$upgrades[] = new FunctionUpgrade(
'cb_ml_upgrade',
'Upgrade custom field types (checkbox, list, multilist) to support advanced filtering',
'upgrade_0_19_checkbox_list_multilist_upgrade' );

function upgrade_0_19_checkbox_list_multilist_upgrade() {
global $t_custom_field_string_table, $t_custom_field_table;
$t_checkbox = CUSTOM_FIELD_TYPE_CHECKBOX;
$t_multilist = CUSTOM_FIELD_TYPE_MULTILIST;
$query = "SELECT f.field_id, f.bug_id, f.value FROM $t_custom_field_string_table AS f
LEFT JOIN $t_custom_field_table as s ON f.field_id = s.id
WHERE (s.type = $t_checkbox) OR (s.type = $t_multilist)";
$result = db_query( $query );
$t_count = db_num_rows( $result );
for ( $i = 0; $i < $t_count; $i++ ) {
$t_row = db_fetch_array( $result );
$t_value = $t_row['value'];
if ( '' != $t_value ) {
$t_field_id = $t_row['field_id'];
$t_bug_id = $t_row['bug_id'];
$query = "UPDATE $t_custom_field_string_table
SET value = '|$t_value|'
WHERE (field_id = $t_field_id) AND (bug_id = $t_bug_id)";
db_query( $query );
}
}

return true;
}

return $upgrades;
?>
47 changes: 41 additions & 6 deletions core/custom_field_api.php
Expand Up @@ -6,7 +6,7 @@
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: custom_field_api.php,v 1.38 2004-08-03 23:45:57 prichards Exp $
# $Id: custom_field_api.php,v 1.39 2004-08-20 23:00:39 prichards Exp $
# --------------------------------------------------------

$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -686,7 +686,7 @@ function custom_field_get_value( $p_field_id, $p_bug_id ) {
custom_field_ensure_exists( $p_field_id );

$t_custom_field_table = config_get( 'mantis_custom_field_table' );
$query = "SELECT access_level_r, default_value
$query = "SELECT access_level_r, default_value, type
FROM $t_custom_field_table
WHERE id='$c_field_id'";
$result = db_query( $query );
Expand All @@ -707,7 +707,7 @@ function custom_field_get_value( $p_field_id, $p_bug_id ) {
$result = db_query( $query );

if( db_num_rows( $result ) > 0 ) {
return db_result( $result );
return custom_field_database_to_value( db_result( $result ) , $row['type'] );
} else {
return $t_default_value;
}
Expand Down Expand Up @@ -750,7 +750,7 @@ function custom_field_get_all_linked_fields( $p_bug_id ) {
$t_custom_field_table = config_get( 'mantis_custom_field_table' );
$t_custom_field_string_table = config_get( 'mantis_custom_field_string_table' );

$query = "SELECT f.name, f.type, f.access_level_r, f.default_value, s.value
$query = "SELECT f.name, f.type, f.access_level_r, f.default_value, f.type, s.value
FROM $t_custom_field_project_table AS p, $t_custom_field_table AS f
LEFT JOIN $t_custom_field_string_table AS s
ON p.field_id=s.field_id AND s.bug_id='$c_bug_id'
Expand All @@ -769,7 +769,7 @@ function custom_field_get_all_linked_fields( $p_bug_id ) {
if( is_null( $row['value'] ) ) {
$t_value = $row['default_value'];
} else {
$t_value = $row['value'];
$t_value = custom_field_database_to_value( $row['value'], $row['type'] );
}

$t_custom_fields[$row['name']] = array( 'type' => $row['type'],
Expand Down Expand Up @@ -913,13 +913,46 @@ function custom_field_distinct_values( $p_field_id, $p_project_id = ALL_PROJECTS
# Data Modification
#===================================

# --------------------
# Convert the value to save it into the database, depending of the type
# return value for database
function custom_field_value_to_database( $p_value, $p_type ) {
switch ($p_type) {
case CUSTOM_FIELD_TYPE_MULTILIST:
case CUSTOM_FIELD_TYPE_CHECKBOX:
if ( '' == $p_value ) {
$result = '';
} else {
$result = '|' . $p_value . '|';
}
break;
default:
$result = $p_value;
}
return $result;
}

# --------------------
# Convert the database-value to value, depending of the type
# return value for further operation
function custom_field_database_to_value( $p_value, $p_type ) {
switch ($p_type) {
case CUSTOM_FIELD_TYPE_MULTILIST:
case CUSTOM_FIELD_TYPE_CHECKBOX:
$result = str_replace( '||', '', '|' . $p_value . '|' );
break;
default:
$result = $p_value;
}
return $result;
}

# --------------------
# Set the value of a custom field for a given bug
# return true on success, false on failure
function custom_field_set_value( $p_field_id, $p_bug_id, $p_value ) {
$c_field_id = db_prepare_int( $p_field_id );
$c_bug_id = db_prepare_int( $p_bug_id );
$c_value = db_prepare_string( $p_value );

custom_field_ensure_exists( $p_field_id );

Expand All @@ -940,6 +973,8 @@ function custom_field_set_value( $p_field_id, $p_bug_id, $p_value ) {
$t_length_max = $row['length_max'];
$t_default_value = $row['default_value'];

$c_value = db_prepare_string( custom_field_value_to_database( $p_value, $t_type ) );

# check for valid value
if ( !is_blank( $t_valid_regexp ) ) {
if ( !ereg( $t_valid_regexp, $p_value ) ) {
Expand Down
18 changes: 15 additions & 3 deletions core/filter_api.php
Expand Up @@ -6,7 +6,7 @@
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: filter_api.php,v 1.54 2004-08-08 15:19:37 prichards Exp $
# $Id: filter_api.php,v 1.55 2004-08-20 23:00:39 prichards Exp $
# --------------------------------------------------------

$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -418,6 +418,7 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
$t_any_found = true;
}
if ( !$t_any_found ) {
$t_def = custom_field_get_definition( $t_cfid );
$t_table_name = $t_custom_field_string_table . '_' . $t_cfid;
array_push( $t_join_clauses, "LEFT JOIN $t_custom_field_string_table as $t_table_name ON $t_table_name.bug_id = $t_bug_table.id" );
foreach( $t_filter['custom_fields'][$t_cfid] as $t_filter_member ) {
Expand All @@ -432,8 +433,19 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
$t_custom_where_clause .= ' OR ';
}

$t_custom_where_clause .= "( $t_table_name.field_id = $t_cfid AND $t_table_name.value = '";
$t_custom_where_clause .= db_prepare_string( trim( $t_filter_member ) ) . "' )";
$t_custom_where_clause .= "( $t_table_name.field_id = $t_cfid AND $t_table_name.value ";
switch( $t_def['type'] ) {
case CUSTOM_FIELD_TYPE_MULTILIST:
case CUSTOM_FIELD_TYPE_CHECKBOX:
$t_custom_where_clause .= "LIKE '%";
$t_custom_where_clause_closing = "%' )";
break;
default:
$t_custom_where_clause .= "= '";
$t_custom_where_clause_closing = "' )";
}
$t_custom_where_clause .= db_prepare_string( trim( $t_filter_member ) );
$t_custom_where_clause .= $t_custom_where_clause_closing;
}
}
if ( !is_blank( $t_custom_where_clause ) ) {
Expand Down

0 comments on commit dbd2e96

Please sign in to comment.