Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mantisbt/mantisbt
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6e18aaa726ff
Choose a base ref
...
head repository: mantisbt/mantisbt
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: df691e9a2bb2
Choose a head ref
  • 4 commits
  • 5 files changed
  • 1 contributor

Commits on Sep 1, 2012

  1. Improve comments for custom field length check

    Function custom_field_get_id_from_name() contains code to check for
    truncated custom fields names. This dates back to when the history
    table's field_name column was only 32 chars long, whereas the custom
    field's size is 64.
    
    Even though the history's field_name size has been increased to 64 since
    1.1.0a4 (see issue #8002), the check must be maintained to ensure
    compatibility with upgraded legacy systems.
    
    The fix ce3450a implemented in master
    branch cannot be applied here as it contains a schema update. Instead,
    comments have been reworded and obsolete reference to old schema
    removed.
    
    Fixes #14650
    dregad committed Sep 1, 2012
    Copy the full SHA
    b5abce1 View commit details
  2. Fix SQL error when sorting by custom field containing special char

    Incorrect behavior is due to unnecessarily escaping of special chars by
    calling db_prepare_string() on the custom field's name before attempting
    to retrieve it's id with custom_field_get_id_from_name(). This causes a
    double-escaping which prevents a match.
    
    Even though this is not strictly necessary to fix the issue at hand,
    this commit also replaces db_query() call by db_query_bound() in
    custom_field_get_id_from_name().
    
    Fixes #12170
    dregad committed Sep 1, 2012
    Copy the full SHA
    6a7db34 View commit details
  3. Add optional param to columns_get_standard() to return all columns

    The default behavior is to exclude the fields which are not "active" due
    to config settings. The new parameter lets caller override that to
    return all standard columns (ie. excluding custom fields).
    dregad committed Sep 1, 2012
    Copy the full SHA
    fe539b0 View commit details
  4. Install helper api - new function install_set_log_queries()

    The new function is used by install/upgrade callback functions to ensure
    that only the relevant queries are logged. This avoids code duplication
    in each function.
    
    Backported to admin/install_functions.php from master
    dregad committed Sep 1, 2012
    Copy the full SHA
    df691e9 View commit details
Showing with 62 additions and 58 deletions.
  1. +33 −37 admin/install_functions.php
  2. +8 −6 core/columns_api.php
  3. +15 −12 core/custom_field_api.php
  4. +1 −1 core/filter_api.php
  5. +5 −2 core/history_api.php
70 changes: 33 additions & 37 deletions admin/install_functions.php
Original file line number Diff line number Diff line change
@@ -23,23 +23,38 @@
* @link http://www.mantisbt.org
*/

/**
* Set the value of $g_db_log_queries as specified
* This is used by install callback functions to ensure that only the relevant
* queries are logged
* @global int $g_db_log_queries
* @param int $p_new_state new value to set $g_db_log_queries to (defaults to OFF)
* @return int old value of $g_db_log_queries
*/
function install_set_log_queries( $p_new_state = OFF ) {
global $g_db_log_queries;

$t_log_queries = $g_db_log_queries;

if ( $g_db_log_queries !== $p_new_state ) {
$g_db_log_queries = $p_new_state;
}

# Return the old value of $g_db_log_queries
return $t_log_queries;
}

/**
* Migrate the legacy category data to the new category_id-based schema.
*/
function install_category_migrate() {
global $g_db_log_queries;

$t_bug_table = db_get_table( 'mantis_bug_table' );
$t_category_table = db_get_table( 'mantis_category_table' );
$t_project_category_table = db_get_table( 'mantis_project_category_table' );

// disable query logging (even if it's enabled in config for this)
if ( $g_db_log_queries !== 0 ) {
$t_log_queries = $g_db_log_queries;
$g_db_log_queries = 0;
} else {
$t_log_queries = null;
}
# Disable query logging even if enabled in config, due to possibility of mass spam
$t_log_queries = install_set_log_queries();

$query = "SELECT project_id, category, user_id FROM $t_project_category_table ORDER BY project_id, category";
$t_category_result = db_query_bound( $query );
@@ -87,26 +102,18 @@ function install_category_migrate() {
}
}

// re-enabled query logging if we disabled it
if ( $t_log_queries !== null ) {
$g_db_log_queries = $t_log_queries;
}
# Re-enable query logging if we disabled it
install_set_log_queries( $t_log_queries );

# return 2 because that's what ADOdb/DataDict does when things happen properly
return 2;
}

function install_date_migrate( $p_data) {
// $p_data[0] = tablename, [1] id column, [2] = old column, [3] = new column
global $g_db_log_queries;

// disable query logging (even if it's enabled in config for this)
if ( $g_db_log_queries !== 0 ) {
$t_log_queries = $g_db_log_queries;
$g_db_log_queries = 0;
} else {
$t_log_queries = null;
}
# Disable query logging even if enabled in config, due to possibility of mass spam
$t_log_queries = install_set_log_queries();

$t_table = db_get_table( $p_data[0] );
$t_id_column = $p_data[1];
@@ -179,10 +186,8 @@ function install_date_migrate( $p_data) {
db_query_bound( $query, $t_values );
}

// re-enabled query logging if we disabled it
if ( $t_log_queries !== null ) {
$g_db_log_queries = $t_log_queries;
}
# Re-enable query logging if we disabled it
install_set_log_queries( $t_log_queries );

# return 2 because that's what ADOdb/DataDict does when things happen properly
return 2;
@@ -198,15 +203,8 @@ function install_date_migrate( $p_data) {
* one possible value that can be assigned to a radio field.
*/
function install_correct_multiselect_custom_fields_db_format() {
global $g_db_log_queries;

# Disable query logging due to possibility of mass spam.
if ( $g_db_log_queries !== 0 ) {
$t_log_queries = $g_db_log_queries;
$g_db_log_queries = 0;
} else {
$t_log_queries = null;
}
# Disable query logging even if enabled in config, due to possibility of mass spam
$t_log_queries = install_set_log_queries();

$t_value_table = db_get_table( 'mantis_custom_field_string_table' );
$t_field_table = db_get_table( 'mantis_custom_field_table' );
@@ -252,10 +250,8 @@ function install_correct_multiselect_custom_fields_db_format() {
$t_update_result = db_query_bound( $t_update_query );
}

# Re-enable query logging if we disabled it.
if ( $t_log_queries !== null ) {
$g_db_log_queries = $t_log_queries;
}
# Re-enable query logging if we disabled it
install_set_log_queries( $t_log_queries );

# Return 2 because that's what ADOdb/DataDict does when things happen properly
return 2;
14 changes: 8 additions & 6 deletions core/columns_api.php
Original file line number Diff line number Diff line change
@@ -74,8 +74,10 @@ function columns_filter_disabled( $p_columns ) {

/**
* Get a list of standard columns.
* @param bool $p_enabled_columns_only default true, if false returns all columns regardless of config settings
* @return array of column names
*/
function columns_get_standard() {
function columns_get_standard( $p_enabled_columns_only = true ) {
$t_reflection = new ReflectionClass('BugData');
$t_columns = $t_reflection->getDefaultProperties();

@@ -85,21 +87,21 @@ function columns_get_standard() {
# Overdue icon column (icons appears if an issue is beyond due_date)
$t_columns['overdue'] = null;

if( OFF == config_get( 'enable_profiles' ) ) {
if( $p_enabled_columns_only && OFF == config_get( 'enable_profiles' ) ) {
unset( $t_columns['os'] );
unset( $t_columns['os_build'] );
unset( $t_columns['platform'] );
}

if( config_get( 'enable_eta' ) == OFF ) {
if( $p_enabled_columns_only && config_get( 'enable_eta' ) == OFF ) {
unset( $t_columns['eta'] );
}

if( config_get( 'enable_projection' ) == OFF ) {
if( $p_enabled_columns_only && config_get( 'enable_projection' ) == OFF ) {
unset( $t_columns['projection'] );
}

if( config_get( 'enable_product_build' ) == OFF ) {
if( $p_enabled_columns_only && config_get( 'enable_product_build' ) == OFF ) {
unset( $t_columns['build'] );
}

@@ -109,7 +111,7 @@ function columns_get_standard() {
unset( $t_columns['sticky'] );
unset( $t_columns['loading'] );

return array_keys($t_columns);
return array_keys( $t_columns );
}

/**
27 changes: 15 additions & 12 deletions core/custom_field_api.php
Original file line number Diff line number Diff line change
@@ -777,19 +777,22 @@ function custom_field_get_id_from_name( $p_field_name, $p_truncated_length = nul

$t_custom_field_table = db_get_table( 'mantis_custom_field_table' );

$c_field_name = db_prepare_string( $p_field_name );

if(( null === $p_truncated_length ) || ( utf8_strlen( $c_field_name ) != $p_truncated_length ) ) {
$query = "SELECT id FROM $t_custom_field_table WHERE name = '$c_field_name'";
if(( null === $p_truncated_length ) || ( utf8_strlen( $p_field_name ) != $p_truncated_length ) ) {
$query = "SELECT id FROM $t_custom_field_table WHERE name = " . db_param();
$c_field_name = $p_field_name;
} else {
/** @todo This is to handle the case where we only have a truncated part of the name. This happens in the case where
* we are getting the custom field name from the history logs, since history is 32 and custom field name is 64.
* This fix will handle entries already in the database, future entries should be handled by making the field name max lengths match.
*/
$query = "SELECT id FROM $t_custom_field_table WHERE name LIKE '$c_field_name%'";
}

$t_result = db_query( $query, 1 );
# This is to handle the case where we potentially only have a
# truncated part of the custom field name. This happens when we
# are getting the field from the history logs (as the history's
# field_name column used to be 32 while custom field name is 64).
# This is needed to handle legacy database entries, as any
# history record created after 1.1.0a4 has the correct field
# size (see #8002)
$query = "SELECT id FROM $t_custom_field_table WHERE name LIKE " . db_param();
$c_field_name = $p_field_name . '%';
}

$t_result = db_query_bound( $query, $c_field_name );

if( db_num_rows( $t_result ) == 0 ) {
return false;
2 changes: 1 addition & 1 deletion core/filter_api.php
Original file line number Diff line number Diff line change
@@ -907,7 +907,7 @@ function filter_get_query_sort_data( &$p_filter, $p_show_sticky, $p_query_clause

$t_count = count( $t_sort_fields );
for( $i = 0;$i < $t_count;$i++ ) {
$c_sort = db_prepare_string( $t_sort_fields[$i] );
$c_sort = $t_sort_fields[$i];
$c_dir = 'DESC' == $t_dir_fields[$i] ? 'DESC' : 'ASC';

if( !in_array( $t_sort_fields[$i], array_slice( $t_sort_fields, $i + 1 ) ) ) {
7 changes: 5 additions & 2 deletions core/history_api.php
Original file line number Diff line number Diff line change
@@ -172,9 +172,12 @@ function history_get_raw_events_array( $p_bug_id, $p_user_id = null ) {

if ( $v_type == NORMAL_TYPE ) {
if ( !in_array( $v_field_name, $t_standard_fields ) ) {
# check that the item should be visible to the user

// check that the item should be visible to the user
// custom fields - we are passing 32 here to notify the API that the custom field name is truncated by the history column from 64 to 32 characters.
# We are passing 32 here to notify the custom field API
# that legacy history entries for field names longer than
# 32 chars created when the db column was of that size were
# truncated (no longer the case since 1.1.0a4, see #8002)
$t_field_id = custom_field_get_id_from_name( $v_field_name, 32 );
if( false !== $t_field_id && !custom_field_has_read_access( $t_field_id, $p_bug_id, $t_user_id ) ) {
continue;