View Issue Details

IDProjectCategoryView StatusLast Update
0004122mantisbtrelationshipspublic2004-08-29 02:35
Reportervboctor Assigned Tomasc  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version0.19.0a2 
Fixed in Version0.19.0rc1 
Summary0004122: Upgrade script seems to swap the duplicate relationship
Description

When upgrading the bugtracker database, it seems that the upgrade scripts marked A as duplicate of B rather than B as duplicate of A. Assuming that B was resolved as duplicate with duplicate id set to A.

If the problem is reproduced, you may need a script to swap the duplicate relationships in the bugtracker database!

TagsNo tags attached.
Attached Files
0_18_inc.zip (3,006 bytes)
swap_duplicate_id.phps (1,611 bytes)   
<?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
	# This program is distributed under the terms and conditions of the GPL
	# See the README and LICENSE files for details

	# Changes applied to 0.18 database

	# --------------------------------------------------------
	# $Id: 0_18_inc.php,v 1.12 2004/07/15 21:51:16 vboctor Exp $
	# --------------------------------------------------------
?>
<?php
	require_once( 'db_table_names_inc.php' );

	$upgrades = array();

	$query = "SELECT id, duplicate_id
			   FROM $t_bug_table
			   WHERE duplicate_id != '';";
	$result = db_query( $query );
	$t_count = db_num_rows( $result );

	for ( $i = 0 ; $i < $t_count ; $i++ ) {
		$t_bug = db_fetch_array( $result );
		$t_bug_id = $t_bug['id'];
		$t_duplicate_bug_id = $t_bug['duplicate_id'];

		$query = "SELECT id
					FROM $t_bug_relationship_table
					WHERE
						relationship_type = '" . BUG_DUPLICATE . "' and
						source_bug_id = '$t_duplicate_bug_id' and
						destination_bug_id = '$t_bug_id';";
		$result2 = db_query( $query );
		$t_count2 = db_num_rows( $result2 );

		if( $t_count2 != 1 ) {
			continue;
		}

		$t_relationship = db_fetch_array( $result2 );
		$t_relationship_id = $t_relationship['id'];

		$query = "UPDATE $t_bug_relationship_table
			SET source_bug_id = '$t_bug_id',
			destination_bug_id = '$t_duplicate_bug_id'
			WHERE id='$t_relationship_id'";
		db_query( $query );
	}

	echo 'done.';
?>
swap_duplicate_id.phps (1,611 bytes)   

Activities

masc

masc

2004-07-18 13:30

reporter   ~0006122

Reproduced. There was a double error: I swapped the meaning in the italian lang files of the relationship and then I swapped the meaning in the upgrade script.
Find attached the script fixed.
I also attached the new definition strings (the meaning sounds clearer):

$s_duplicate_of = "duplicate of";
$s_has_duplicate = "is duplicated by";
$s_related_to = "related to";
$s_dependant_on = "parent of";
$s_blocks = "child of";

Marcello

vboctor

vboctor

2004-07-18 17:20

manager   ~0006128

I applied your patch. Can you please also attach a script that would go through all existing duplicate relationships in the database and swap them? We need this to run on this installation and users may need it to fix their relationships after they upgrade to 0.19.0a2.

Following are the strings I used in 0.19.0a2 release:
$s_duplicate_of = "duplicate of";
$s_has_duplicate = "has duplicate";
$s_related_to = "related to";
$s_dependant_on = "parent of";
$s_blocks = "child of";

masc

masc

2004-07-19 02:11

reporter   ~0006130

Updated the file 0_18_inc.php with the script to swap the values (id relationship-4).

vboctor

vboctor

2004-07-19 07:10

manager   ~0006135

I uploaded a standalone version of your script. For it to run successfully, it must be placed in the admin/ folder.

I am not sure whether we should add this as a step in the upgrade script or not. My worries are:

  • We have fixed the swap problem in CVS, hence, if a user applies it from CVS, then this step will end up causing a problem.
  • If a user has upgraded to 0.19.0a2, then added some duplicate defects, then upgrades to next version, then we will also swap these valid new duplicate issues.
masc

masc

2004-07-19 07:33

reporter   ~0006140

Victor,
the script searchs only the duplicated bugs (looking at the duplicate_id field) that have a swapped relationship (i.e. when they are sources instead of destinations in the relationship), and then it swaps source and destination.
It means we can run the script safety. It doesn't care the "right" relationship (the relationship added after the fix in the upgrade script).

vboctor

vboctor

2004-07-19 07:52

manager   ~0006142

ok, I committed your patch to the upgrade script.

Related Changesets

MantisBT: master 35cf1f8e

2004-07-18 18:20

vboctor


Details Diff
Fix 0004122: Upgrade script seems to swap the duplicate relationship (masc)

git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@2727 <a class="text" href="/?p=mantisbt.git;a=object;h=f5dc347c">f5dc347c</a>-c33d-0410-90a0-b07cc1902cb9
Affected Issues
0004122
mod - doc/ChangeLog Diff File
mod - admin/upgrades/0_18_inc.php Diff File