From 7866f271c03ab39eac493bb336101c0d183d115d Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 15 Apr 2009 01:47:25 +0000 Subject: [PATCH] yet untested method for calling the in-db merge stored proc to handle merging of master/sub bib records git-svn-id: svn://svn.open-ils.org/ILS/trunk@12872 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Cat.pm | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm index c492d445ed..dc8943055a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm @@ -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); -- 2.11.0