In actor.usr_merge(): when transferring rows from vandelay.queue,
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 30 Jun 2009 13:06:20 +0000 (13:06 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 30 Jun 2009 13:06:20 +0000 (13:06 +0000)
change the name in order to avoid collisions with existing rows
belonging to the destination user.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@13489 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/sql/Pg/999.functions.global.sql

index f0b8a59..e0a238d 100644 (file)
@@ -49,6 +49,7 @@ DECLARE
        suffix TEXT;
        bucket_row RECORD;
        picklist_row RECORD;
+       queue_row RECORD;
 BEGIN
 
     -- do some initial cleanup 
@@ -175,7 +176,25 @@ BEGIN
        UPDATE container.user_bucket_item SET target_user = dest_usr WHERE target_user = src_usr;
 
     -- vandelay.*
-    PERFORM actor.usr_merge_rows('vandelay.queue', 'owner', src_usr, dest_usr);
+       -- transfer queues the same way we transfer buckets (see above)
+       FOR queue_row in
+               SELECT id, name
+               FROM   vandelay.queue
+               WHERE  owner = src_usr
+       LOOP
+               suffix := ' (' || src_usr || ')';
+               LOOP
+                       BEGIN
+                               UPDATE  vandelay.queue
+                               SET     owner = dest_usr, name = name || suffix
+                               WHERE   id = queue_row.id;
+                       EXCEPTION WHEN unique_violation THEN
+                               suffix := suffix || ' ';
+                               CONTINUE;
+                       END;
+                       EXIT;
+               END LOOP;
+       END LOOP;
 
     -- money.*
     PERFORM actor.usr_merge_rows('money.collections_tracker', 'usr', src_usr, dest_usr);