my $U = "OpenILS::Application::AppUtils";
my $conf;
my %marctemplates;
+my $assetcom = 'OpenILS::Application::Cat::AssetCommon';
__PACKAGE__->register_method(
method => "retrieve_marc_template",
if( $vol->isdeleted ) {
$logger->info("vol-update: deleting volume");
- return $editor->event unless
+ return $editor->die_event unless
$editor->allowed('UPDATE_VOLUME', $vol->owning_lib);
- my $cs = $editor->search_asset_copy(
- { call_number => $vol->id, deleted => 'f' } );
- return OpenILS::Event->new(
- 'VOLUME_NOT_EMPTY', payload => $vol->id ) if @$cs;
- $vol->deleted('t');
- return $editor->event unless
+ if(my $evt = $assetcom->delete_volume($editor, $vol, $override, $$options{force_delete_copies})) {
+ $editor->rollback;
+ return $evt;
+ }
+
+ return $editor->die_event unless
$editor->update_asset_call_number($vol);
-
} elsif( $vol->isnew ) {
$logger->info("vol-update: creating volume");
- $evt = OpenILS::Application::Cat::AssetCommon->create_volume( $override, $editor, $vol );
+ $evt = $assetcom->create_volume( $override, $editor, $vol );
return $evt if $evt;
} elsif( $vol->ischanged ) {
# now update any attached copies
if( $copies and @$copies and !$vol->isdeleted ) {
$_->call_number($vol->id) for @$copies;
- $evt = OpenILS::Application::Cat::AssetCommon->update_fleshed_copies(
+ $evt = $assetcom->update_fleshed_copies(
$editor, $override, $vol, $copies, $delete_stats, $retarget_holds, undef);
return $evt if $evt;
}
my $evt;
my $org = (ref $copy->circ_lib) ? $copy->circ_lib->id : $copy->circ_lib;
- return $evt if ($evt = OpenILS::Application::Cat::AssetCommon->org_cannot_have_vols($editor, $org));
+ return $evt if ($evt = $class->org_cannot_have_vols($editor, $org));
$copy->clear_id;
$copy->editor($editor->requestor->id);
my $evt;
my $org = (ref $copy->circ_lib) ? $copy->circ_lib->id : $copy->circ_lib;
- return $evt if ( $evt = OpenILS::Application::Cat::AssetCommon->org_cannot_have_vols($editor, $org) );
+ return $evt if ( $evt = $class->org_cannot_have_vols($editor, $org) );
$logger->info("vol-update: updating copy ".$copy->id);
my $orig_copy = $editor->retrieve_asset_copy($copy->id);
sub delete_copy {
- my($class, $editor, $override, $vol, $copy, $retarget_holds, $force_delete_empty_bib) = @_;
+ my($class, $editor, $override, $vol, $copy, $retarget_holds, $force_delete_empty_bib, $skip_empty_cleanup) = @_;
return $editor->event unless
$editor->allowed('DELETE_COPY', $class->copy_perm_org($vol, $copy));
$class->check_hold_retarget($editor, $copy, undef, $retarget_holds);
+ return undef if $skip_empty_cleanup;
+
return $class->remove_empty_objects($editor, $override, $vol, $force_delete_empty_bib);
}
$vol->suffix($suffix);
$vol->record($record_id);
- my $evt = OpenILS::Application::Cat::AssetCommon->create_volume(0, $e, $vol);
+ my $evt = $class->create_volume(0, $e, $vol);
return (undef, $evt) if $evt;
return ($vol);
# delete this volume if it's not already marked as deleted
unless( $U->is_true($vol->deleted) || $vol->isdeleted ) {
- $vol->deleted('t');
- $vol->editor($editor->requestor->id);
- $vol->edit_date('now');
- $editor->update_asset_call_number($vol) or return $editor->event;
+ my $evt = $class->delete_volume($editor, $vol, $override, 0, 1);
+ return $evt if $evt;
}
return OpenILS::Event->new('TITLE_LAST_COPY', payload => $vol->record )
return undef;
}
+# Deletes a volume. Returns undef on success, event on error
+# force : deletes all attached copies
+# skip_copy_check : assumes caller has verified no copies need deleting first
+sub delete_volume {
+ my($class, $editor, $vol, $override, $delete_copies, $skip_copy_checks) = @_;
+ my $evt;
+
+ unless($skip_copy_checks) {
+ my $cs = $editor->search_asset_copy(
+ [{call_number => $vol->id, deleted => 'f'}, {limit => 1}], {idlist => 1});
+
+ return OpenILS::Event->new('VOLUME_NOT_EMPTY', payload => $vol->id)
+ if @$cs and !$delete_copies;
+
+ my $copies = $editor->search_asset_copy({call_number => $vol->id, deleted => 'f'});
+
+ for my $copy (@$copies) {
+ $evt = $class->delete_copy($editor, $override, $vol, $copy, 0, 0, 1);
+ return $evt if $evt;
+ }
+ }
+
+ $vol->deleted('t');
+ $vol->edit_date('now');
+ $vol->editor($editor->requestor->id);
+ $editor->update_asset_call_number($vol) or return $editor->die_event;
+
+ # handle the case where this is the last volume on the record
+ return $class->remove_empty_objects($editor, $override, $vol);
+}
+
sub copy_perm_org {
my($class, $vol, $copy) = @_;