Skip to content

Commit

Permalink
Fixed #7774: custom fields not stored correctly in bug history.
Browse files Browse the repository at this point in the history
  • Loading branch information
vboctor committed Apr 1, 2007
1 parent ea1685e commit 6955dbf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
16 changes: 12 additions & 4 deletions core/custom_field_api.php
@@ -1,12 +1,12 @@
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2004 Mantis Team - mantisbt-dev@lists.sourceforge.net
# Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: custom_field_api.php,v 1.57.12.1 2007-03-06 07:00:33 vboctor Exp $
# $Id: custom_field_api.php,v 1.57.12.2 2007-04-01 08:00:38 vboctor Exp $
# --------------------------------------------------------

$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -586,12 +586,20 @@ function custom_field_delete_all_values( $p_bug_id ) {
# --------------------
# Get the id of the custom field with the specified name.
# false is returned if no custom field found with the specified name.
function custom_field_get_id_from_name( $p_field_name ) {
function custom_field_get_id_from_name( $p_field_name, $p_truncated_length = null ) {
$t_custom_field_table = config_get( 'mantis_custom_field_table' );

$c_field_name = db_prepare_string( $p_field_name );

$query = "SELECT id FROM $t_custom_field_table WHERE name = '$c_field_name'";
if ( ( null === $p_truncated_length ) || ( strlen( $c_field_name ) != $p_truncated_length ) ) {
$query = "SELECT id FROM $t_custom_field_table WHERE name = '$c_field_name'";
} else {
# @@@ 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 );

if ( db_num_rows( $t_result ) == 0 ) {
Expand Down
12 changes: 6 additions & 6 deletions core/history_api.php
Expand Up @@ -6,7 +6,7 @@
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: history_api.php,v 1.34.10.1 2007-04-01 07:06:21 vboctor Exp $
# $Id: history_api.php,v 1.34.10.2 2007-04-01 08:00:38 vboctor Exp $
# --------------------------------------------------------

### History API ###
Expand Down Expand Up @@ -81,10 +81,10 @@ function history_get_events( $p_bug_id ) {
# Retrieves the history events for the specified bug id and returns it in an array
# The array is indexed from 0 to N-1. The second dimension is: 'date', 'username',
# 'note', 'change'.
function history_get_events_array( $p_bug_id ) {
function history_get_events_array( $p_bug_id, $p_user_id = null ) {
$t_normal_date_format = config_get( 'normal_date_format' );

$raw_history = history_get_raw_events_array( $p_bug_id );
$raw_history = history_get_raw_events_array( $p_bug_id, $p_user_id );
$raw_history_count = count( $raw_history );
$history = array();

Expand All @@ -108,7 +108,7 @@ function history_get_raw_events_array( $p_bug_id, $p_user_id = null ) {
$t_history_order = config_get( 'history_order' );
$c_bug_id = db_prepare_int( $p_bug_id );

$t_user_id = ( ( null === $p_user_id ) ? auth_get_current_user_id() : $p_userid );
$t_user_id = ( ( null === $p_user_id ) ? auth_get_current_user_id() : $p_user_id );

# grab history and display by date_modified then field_name
# @@@ by MASC I guess it's better by id then by field_name. When we have more history lines with the same
Expand All @@ -133,8 +133,8 @@ function history_get_raw_events_array( $p_bug_id, $p_user_id = null ) {
extract( $row, EXTR_PREFIX_ALL, 'v' );

// check that the item should be visible to the user
// custom fields
$t_field_id = custom_field_get_id_from_name( $v_field_name );
// 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.
$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;
Expand Down

0 comments on commit 6955dbf

Please sign in to comment.