[Rt-commit] r2064 - in rt/branches/3.4-RELEASE: . lib/RT lib/t/regression

jesse at bestpractical.com jesse at bestpractical.com
Mon Jan 10 23:54:10 EST 2005


Author: jesse
Date: Mon Jan 10 23:54:09 2005
New Revision: 2064

Added:
   rt/branches/3.4-RELEASE/lib/t/regression/14merge.t
Modified:
   rt/branches/3.4-RELEASE/   (props changed)
   rt/branches/3.4-RELEASE/lib/RT/Ticket_Overlay.pm
Log:
 r2669 at hualien:  jesse | 2005-01-11T06:23:33.161490Z
 Merging tickets with the same link could cause postgres to complain. Fixed. merged.
 
 
 


Modified: rt/branches/3.4-RELEASE/lib/RT/Ticket_Overlay.pm
==============================================================================
--- rt/branches/3.4-RELEASE/lib/RT/Ticket_Overlay.pm	(original)
+++ rt/branches/3.4-RELEASE/lib/RT/Ticket_Overlay.pm	Mon Jan 10 23:54:09 2005
@@ -2720,8 +2720,15 @@
         elsif ($link->Base eq $MergeInto->URI) {
             $link->Delete;
         } else {
-            $link->SetTarget($MergeInto->URI);
-            $link->SetLocalTarget($MergeInto->id);
+            # First, make sure the link doesn't already exist. then move it over.
+            my $tmp = RT::Link->new($RT::SystemUser);
+            $tmp->LoadByCols(Base => $link->Base, Type => $link->Type, LocalTarget => $MergeInto->id);
+            if ($tmp->id)   {
+                    $link->Delete;
+            } else { 
+                $link->SetTarget($MergeInto->URI);
+                $link->SetLocalTarget($MergeInto->id);
+            }
             $old_seen{$link->Base."-".$link->Type} =1;
         }
 
@@ -2737,9 +2744,16 @@
         if ($link->Target eq $MergeInto->URI) {
             $link->Delete;
         } else {
-            $link->SetBase($MergeInto->URI);
-            $link->SetLocalBase($MergeInto->id);
-             $old_seen{$link->Type."-".$link->Target} =1;
+            # First, make sure the link doesn't already exist. then move it over.
+            my $tmp = RT::Link->new($RT::SystemUser);
+            $tmp->LoadByCols(Target => $link->Target, Type => $link->Type, LocalBase => $MergeInto->id);
+            if ($tmp->id)   {
+                    $link->Delete;
+            } else { 
+                $link->SetBase($MergeInto->URI);
+                $link->SetLocalBase($MergeInto->id);
+                $old_seen{$link->Type."-".$link->Target} =1;
+            }
         }
 
     }

Added: rt/branches/3.4-RELEASE/lib/t/regression/14merge.t
==============================================================================
--- (empty file)
+++ rt/branches/3.4-RELEASE/lib/t/regression/14merge.t	Mon Jan 10 23:54:09 2005
@@ -0,0 +1,31 @@
+
+use Test::More  tests => '6';
+use RT;
+RT::LoadConfig();
+RT::Init();
+
+# when you try to merge duplicate links on postgres, eveyrything goes to hell due to referential integrity constraints.
+
+
+my $t = RT::Ticket->new($RT::SystemUser);
+$t->Create(Subject => 'Main', Queue => 'general');
+
+ok ($t->id);
+my $t2 = RT::Ticket->new($RT::SystemUser);
+$t2->Create(Subject => 'Second', Queue => 'general');
+ok ($t2->id);
+
+my $t3 = RT::Ticket->new($RT::SystemUser);
+$t3->Create(Subject => 'Third', Queue => 'general');
+
+ok ($t3->id);
+
+my ($id,$val);
+($id,$val) = $t->AddLink(Type => 'DependsOn', Target => $t3->id);
+ok($id,$val);
+($id,$val) = $t2->AddLink(Type => 'DependsOn', Target => $t3->id);
+ok($id,$val);
+
+
+($id,$val) = $t->MergeInto($t2->id);
+ok($id,$val);


More information about the Rt-commit mailing list