From: Dan Pearl Date: Tue, 5 May 2015 14:35:45 +0000 (-0400) Subject: LP#904472: X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9018e2b7d8dfa0cc5e4458d3c94a93691ed170b3;p=working%2FEvergreen.git LP#904472: --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index 91566c2aed..b7227a41c3 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -173,6 +173,9 @@ sub biblio_record_replace_marc { $e->commit unless $U->event_code($res); + #my $ses = OpenSRF::AppSession->create('open-ils.ingest'); + #$ses->request('open-ils.ingest.full.biblio.record', $recid); + return $res; } @@ -266,7 +269,7 @@ sub template_overlay_container { my $responses = []; my $some_failed = 0; - $conn->respond_complete( + $self->respond_complete( $actor->request('open-ils.actor.anon_cache.set_value', $auth, res_list => $responses)->gather(1) ) if ($actor); @@ -423,6 +426,9 @@ sub biblio_record_xml_import { $e->commit; + #my $ses = OpenSRF::AppSession->create('open-ils.ingest'); + #$ses->request('open-ils.ingest.full.biblio.record', $record->id); + return $record; } @@ -710,6 +716,42 @@ sub _build_volume_list { } +__PACKAGE__->register_method( + method => "move_attached_parts", + api_name => "open-ils.cat.asset.move_attached_parts", + argc => 3, + signature => q/ + Moves monograph part attached to a copy to another record + @param auth The login session key + @param dest_call_number_id The id of the call_number of the destination record + @param source_copy_id The copy to which the moving monograph part is attached + @return 1 on success, 0 on no action + / + ); + +sub move_attached_parts { + my( $self, $conn, $auth, $dest_call_number_id, $source_copy_id ) = @_; + + my $editor = new_editor( authtoken => $auth, xact => 1 ); + return $editor->die_event unless $editor->checkauth; + + my $query = { + select => { + acn => [{ + alias => 'count', + transform => 'asset.move_attached_parts', + column => 'id', + params => [$source_copy_id] + }] + }, + from => 'acn', + where => { id => $dest_call_number_id } + }; + + my $result = $editor->json_query($query)->[0]; + + return $result; +} __PACKAGE__->register_method( method => "fleshed_copy_update", diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index d98edc052a..adae67021d 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -2387,4 +2387,58 @@ BEGIN END; $$ LANGUAGE PLPGSQL; +------------------------------------------------------------------------------------------ +-- When moving an item from one bib record or another (to correct errors, most likely), this +-- function also ensures that the monograph part associated with the item is moved as well. +-- Note that the exisiting monograph part is left behind. This could be improved in the future, but +-- there are business decisions to be made that affect this. Specifically, how does EG handle holds (or even +-- checked out items) that are moved. + +CREATE OR REPLACE FUNCTION biblio.move_attached_parts( target_call_number_id BIGINT, source_copy_id BIGINT ) RETURNS INT AS $func$ +DECLARE + copy_part_map_entry asset.copy_part_map%ROWTYPE; + current_part biblio.monograph_part%ROWTYPE; + destination_mp_id BIGINT; + dest_rec_id BIGINT; + +BEGIN + + -- Find affected copy_part_map item. An existing bug allows more than one part for a copy, + -- hence the LIMIT 1; + SELECT * INTO copy_part_map_entry + FROM asset.copy_part_map + WHERE target_copy = source_copy_id + LIMIT 1; + + IF NOT FOUND THEN + RETURN 0; + END IF; + + SELECT * INTO current_part + FROM biblio.monograph_part + WHERE id = copy_part_map_entry.part; + + SELECT record INTO dest_rec_id + FROM asset.call_number + WHERE id = target_call_number_id; + -- Find monograph_part of destination record, if any + SELECT id INTO destination_mp_id + FROM biblio.monograph_part + WHERE record = dest_rec_id + AND label = current_part.label; + + IF NOT FOUND THEN + -- We need to create a new monograph_part entry + INSERT INTO biblio.monograph_part (record, label) + VALUES (dest_rec_id, current_part.label) RETURNING id INTO destination_mp_id; + + END IF; + + UPDATE asset.copy_part_map + SET part = destination_mp_id + WHERE id = copy_part_map_entry.id; + + RETURN 1; +END; +$func$ LANGUAGE plpgsql; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.move_attached_parts.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.move_attached_parts.sql new file mode 100644 index 0000000000..ae1a77b7d3 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.move_attached_parts.sql @@ -0,0 +1,57 @@ +------------------------------------------------------------------------------------------ +-- When moving an item from one bib record or another (to correct errors, most likely), this +-- function also ensures that the monograph part associated with the item is moved as well. +-- Note that the exisiting monograph part is left behind. This could be improved in the future, but +-- there are business decisions to be made that affect this. Specifically, how does EG handle holds (or even +-- checked out items) that are moved. + +CREATE OR REPLACE FUNCTION biblio.move_attached_parts( target_call_number_id BIGINT, source_copy_id BIGINT ) RETURNS INT AS $func$ +DECLARE + copy_part_map_entry asset.copy_part_map%ROWTYPE; + current_part biblio.monograph_part%ROWTYPE; + destination_mp_id BIGINT; + dest_rec_id BIGINT; + +BEGIN + + -- Find affected copy_part_map item. An existing bug allows more than one part for a copy, + -- hence the LIMIT 1; + SELECT * INTO copy_part_map_entry + FROM asset.copy_part_map + WHERE target_copy = source_copy_id + LIMIT 1; + + IF NOT FOUND THEN + RETURN 0; + END IF; + + SELECT * INTO current_part + FROM biblio.monograph_part + WHERE id = copy_part_map_entry.part; + + SELECT record INTO dest_rec_id + FROM asset.call_number + WHERE id = target_call_number_id; + + -- Find monograph_part of destination record, if any + SELECT id INTO destination_mp_id + FROM biblio.monograph_part + WHERE record = dest_rec_id + AND label = current_part.label; + + IF NOT FOUND THEN + -- We need to create a new monograph_part entry + INSERT INTO biblio.monograph_part (record, label) + VALUES (dest_rec_id, current_part.label) RETURNING id INTO destination_mp_id; + + END IF; + + UPDATE asset.copy_part_map + SET part = destination_mp_id + WHERE id = copy_part_map_entry.id; + + RETURN 1; +END; +$func$ LANGUAGE plpgsql; + + diff --git a/Open-ILS/xul/staff_client/server/cat/util.js b/Open-ILS/xul/staff_client/server/cat/util.js index 2a7578e7dd..446cf44ea9 100644 --- a/Open-ILS/xul/staff_client/server/cat/util.js +++ b/Open-ILS/xul/staff_client/server/cat/util.js @@ -187,6 +187,9 @@ cat.util.transfer_copies = function(params) { var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE.authoritative', [ params.copy_ids ]); for (var i = 0; i < copies.length; i++) { + var results = fieldmapper.standardRequest( + ["open-ils.cat", "open-ils.cat.asset.move_attached_parts"], + [ses(), data.marked_volume, copies[i].id ]); copies[i].call_number( data.marked_volume ); copies[i].circ_lib( params.owning_lib ); copies[i].ischanged( 1 );