delete match_set_point's starting with leaf nodes to avoid foreign key constraints...
authorberick <berick@esilibrary.com>
Tue, 3 May 2011 18:42:09 +0000 (14:42 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 6 Jul 2011 18:50:51 +0000 (14:50 -0400)
Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm

index 1d69eb4..0820cb0 100644 (file)
@@ -1420,8 +1420,15 @@ sub match_set_update_tree {
         {"order_by" => {"vmsp" => "id DESC"}}
     ]) or return $e->die_event;
 
-    foreach (@$existing) {
-        $e->delete_vandelay_match_set_point($_) or return $e->die_event;
+    # delete points, working up from leaf points to the root
+    while(@$existing) {
+        for my $point (shift @$existing) {
+            if( grep {$_->parent eq $point->id} @$existing) {
+                push(@$existing, $point);
+            } else {
+                $e->delete_vandelay_match_set_point($point) or return $e->die_event;
+            }
+        }
     }
 
     _walk_new_vmsp($e, $match_set_id, $tree);