<event code='12002' textcode='ITEM_TO_MARK_LAST_HOLD_COPY'>
<desc xml:lang="en-US">The item to be marked is the last possible target for a hold.</desc>
</event>
+
+ <!-- ================================================================ -->
+
+ <event code='12003' textcode='TITLE_HAS_HOLDS'>
+ <desc xml:lang="en-US">This title has hold requests on it that will be canceled if they are not transferred.</desc>
+ </event>
</ils_events>
# Now see if any empty records need to be deleted after all of this
my $keep_on_empty = $U->ou_ancestor_setting_value($e->requestor->ws_ou, 'cat.bib.keep_on_empty', $e);
unless ($U->is_true($keep_on_empty)) {
+
for (@rec_ids) {
$logger->debug("merge: seeing if we should delete record $_...");
- $evt = OpenILS::Application::Cat::BibCommon->delete_rec($e, $_)
- if OpenILS::Application::Cat::BibCommon->title_is_empty($e, $_);
- return $evt if $evt;
+ if (OpenILS::Application::Cat::BibCommon->title_is_empty($e, $_)) {
+ # check for any title holds on the bib, bail if so
+ my $has_holds = OpenILS::Application::Cat::BibCommon->title_has_holds($e, $_);
+ return OpenILS::Event->new('TITLE_HAS_HOLDS', payload => $_) if $has_holds;
+ # we're good, delete the record
+ $evt = OpenILS::Application::Cat::BibCommon->delete_rec($e, $_);
+ return $evt if $evt;
+ }
}
}
}
return OpenILS::Event->new('TITLE_LAST_COPY', payload => $vol->record )
if $aoe and not ($override->{all} || grep { $_ eq 'TITLE_LAST_COPY' } @{$override->{events}}) and not $force_delete_empty_bib;
+ # check for any holds on the title and alert the user before plowing ahead
+ if( OpenILS::Application::Cat::BibCommon->title_has_holds($editor, $vol->record) ) {
+ return OpenILS::Event->new('TITLE_HAS_HOLDS', payload => $vol->record )
+ if not ($override->{all} || grep { $_ eq 'TITLE_HAS_HOLDS' } @{$override->{events}}) and not $force_delete_empty_bib;
+ }
+
unless($koe and not $force_delete_empty_bib) {
# delete the bib record if the keep-on-empty setting is not set (and we're not otherwise forcing things, say through acq settings)
my $evt = OpenILS::Application::Cat::BibCommon->delete_rec($editor, $vol->record);
return 1;
}
+
+# --------------------------------------------------------------------------
+# returns true if the given title (id) has active hold requests on it
+# --------------------------------------------------------------------------
+sub title_has_holds {
+ my($class, $editor, $rid) = @_;
+
+ # check if $rid is an object, because may be passing the volume
+ # with a fleshed record in one of our callers.
+ $rid = $rid->id() if (ref($rid));
+
+ my $holds = $editor->search_action_hold_request(
+ [
+ { fulfillment_time => undef,
+ cancel_time => undef,
+ hold_type => 'T',
+ target => $rid },
+ { limit => 1 },
+ ], { idlist => 1 });
+ return 0 unless @$holds;
+
+ return 1; # we found a hold
+}
1;