LP#1398107: Alert when autodeleting a title with holds on it.
authorChris Sharp <csharp@georgialibraries.org>
Wed, 11 Mar 2020 23:33:15 +0000 (19:33 -0400)
committerJason Stephenson <jason@sigio.com>
Mon, 30 Nov 2020 18:18:36 +0000 (13:18 -0500)
Add a new "TITLE_HAS_HOLDS" event that we pass up to the user
if any non-canceled, unfulfilled title hold targets a bib that
would otherwise be silently deleted with holds canceled.

Also, retarget any holds pointing to a bib that is automatically
deleted after removing its volumes/copies to the destination bib
if this is the last copy.

Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Signed-off-by: Rogan Hamby <rogan.hamby@gmail.com>
Signed-off-by: Jason Stephenson <jason@sigio.com>

Open-ILS/src/extras/ils_events.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/BibCommon.pm

index ce36cc6..527c612 100644 (file)
     <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>
 
 
index 36376a0..d072dd1 100644 (file)
@@ -1532,11 +1532,17 @@ sub batch_volume_transfer {
         # 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;
+                }
             }
         }
     }
index f9f60dc..db35407 100644 (file)
@@ -724,6 +724,12 @@ sub remove_empty_objects {
         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);
index 3f2cfbc..ebbaed0 100644 (file)
@@ -410,4 +410,27 @@ sub title_is_empty {
 
     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;