yet untested method for calling the in-db merge stored proc to handle merging of...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 15 Apr 2009 01:47:25 +0000 (01:47 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 15 Apr 2009 01:47:25 +0000 (01:47 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@12872 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Cat.pm

index c492d44..dc89430 100644 (file)
@@ -476,6 +476,41 @@ __PACKAGE__->register_method(
        /
 );
 
+sub in_db_merge {
+       my( $self, $conn, $auth, $master, $records ) = @_;
+       my( $reqr, $evt ) = $U->checkses($auth);
+       return $evt if $evt;
+
+       my $editor = new_editor( requestor => $reqr, xact => 1 );
+
+    my $count = 0;
+    for my $source ( @$records ) {
+        #XXX we actually /will/ want to check perms for master and sources after record ownership exists
+
+        # This stored proc (asset.merge_record_assets(target,source)) has the side effects of
+        # moving call_number, title-type (and some volume-type) hold_request and uri-mapping
+        # objects from the source record to the target record, so must be called from within
+        # a transaction.
+
+        $count += $editor->json_query({
+            select => {
+                bre => [{
+                    alias => 'count',
+                    transform => 'asset.merge_record_assets',
+                    column => 'id',
+                    params => [$source]
+                }]
+            },
+            from   => 'bre',
+            where  => { id => $master }
+        })->[0]->{count}; # count of objects moved, of all types
+
+    }
+
+       $editor->commit;
+    return $count;
+}
+
 sub merge {
        my( $self, $conn, $auth, $master, $records ) = @_;
        my( $reqr, $evt ) = $U->checkses($auth);