$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;
}
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);
$e->commit;
+ #my $ses = OpenSRF::AppSession->create('open-ils.ingest');
+ #$ses->request('open-ils.ingest.full.biblio.record', $record->id);
+
return $record;
}
}
+__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",
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;
--- /dev/null
+------------------------------------------------------------------------------------------
+-- 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;
+
+
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 );