In usr_merge(): when merging rows from reporter.*_folder,
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 30 Jun 2009 14:25:00 +0000 (14:25 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 30 Jun 2009 14:25:00 +0000 (14:25 +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@13490 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index e0a238d..86abc32 100644 (file)
@@ -50,6 +50,7 @@ DECLARE
        bucket_row RECORD;
        picklist_row RECORD;
        queue_row RECORD;
+       folder_row RECORD;
 BEGIN
 
     -- do some initial cleanup 
@@ -280,17 +281,71 @@ BEGIN
         -- do nothing
     END;
     BEGIN
-        PERFORM actor.usr_merge_rows('reporter.template_folder', 'owner', src_usr, dest_usr);
+               -- transfer folders the same way we transfer buckets (see above)
+               FOR folder_row in
+                       SELECT id, name
+                       FROM   reporter.template_folder
+                       WHERE  owner = src_usr
+               LOOP
+                       suffix := ' (' || src_usr || ')';
+                       LOOP
+                               BEGIN
+                                       UPDATE  reporter.template_folder
+                                       SET     owner = dest_usr, name = name || suffix
+                                       WHERE   id = folder_row.id;
+                               EXCEPTION WHEN unique_violation THEN
+                                       suffix := suffix || ' ';
+                                       CONTINUE;
+                               END;
+                               EXIT;
+                       END LOOP;
+               END LOOP;
     EXCEPTION WHEN undefined_table THEN
         -- do nothing
     END;
     BEGIN
-        PERFORM actor.usr_merge_rows('reporter.report_folder', 'owner', src_usr, dest_usr);
+               -- transfer folders the same way we transfer buckets (see above)
+               FOR folder_row in
+                       SELECT id, name
+                       FROM   reporter.report_folder
+                       WHERE  owner = src_usr
+               LOOP
+                       suffix := ' (' || src_usr || ')';
+                       LOOP
+                               BEGIN
+                                       UPDATE  reporter.report_folder
+                                       SET     owner = dest_usr, name = name || suffix
+                                       WHERE   id = folder_row.id;
+                               EXCEPTION WHEN unique_violation THEN
+                                       suffix := suffix || ' ';
+                                       CONTINUE;
+                               END;
+                               EXIT;
+                       END LOOP;
+               END LOOP;
     EXCEPTION WHEN undefined_table THEN
         -- do nothing
     END;
     BEGIN
-        PERFORM actor.usr_merge_rows('reporter.output_folder', 'owner', src_usr, dest_usr);
+               -- transfer folders the same way we transfer buckets (see above)
+               FOR folder_row in
+                       SELECT id, name
+                       FROM   reporter.output_folder
+                       WHERE  owner = src_usr
+               LOOP
+                       suffix := ' (' || src_usr || ')';
+                       LOOP
+                               BEGIN
+                                       UPDATE  reporter.output_folder
+                                       SET     owner = dest_usr, name = name || suffix
+                                       WHERE   id = folder_row.id;
+                               EXCEPTION WHEN unique_violation THEN
+                                       suffix := suffix || ' ';
+                                       CONTINUE;
+                               END;
+                               EXIT;
+                       END LOOP;
+               END LOOP;
     EXCEPTION WHEN undefined_table THEN
         -- do nothing
     END;