added API call for create hold reset note, it is used within the hold targeter when...
authorLlewellyn Marshall <llewellyn.marshall@ncdcr.gov>
Wed, 15 Dec 2021 15:55:44 +0000 (10:55 -0500)
committerLlewellyn Marshall <llewellyn.marshall@ncdcr.gov>
Fri, 17 Dec 2021 17:43:04 +0000 (12:43 -0500)
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/HoldTargeter.pm

index a37cca3..b9f3705 100644 (file)
@@ -1024,7 +1024,7 @@ sub uncancel_hold {
     $hold->clear_prev_check_time;
     $hold->clear_shelf_expire_time;
     $hold->clear_current_shelf_lib;
-    create_reset_hold_note($e,$hold,"Hold Reset due to Uncancelation","Hold was reset due to Uncancelation.");
+    _create_reset_hold_note($e,$hold,"Hold Reset due to Uncancelation","Hold was reset due to Uncancelation.");
     $e->update_action_hold_request($hold) or return $e->die_event;
     $e->commit;
         
@@ -1110,7 +1110,7 @@ sub cancel_hold {
     my $note_body = "Hold Cancelation.";
     $note_body .= " Cancel Cause ID - $cause;";
     $note_body .= " Cancel Note - $note" unless $note eq "";
-    create_reset_hold_note($e,$hold,"Hold Reset due to Cancelation",$note_body);
+    _create_reset_hold_note($e,$hold,"Hold Reset due to Cancelation",$note_body);
     $e->update_action_hold_request($hold)
         or return $e->die_event;
 
@@ -1360,7 +1360,7 @@ sub update_hold_impl {
     }
 
     $e->update_action_hold_request($hold) or return $e->die_event;
-    create_reset_hold_note($e,$hold,"Hold Reset due to Update",$note_body) unless $note_body eq "";
+    _create_reset_hold_note($e,$hold,"Hold Reset due to Update",$note_body) unless $note_body eq "";
     $e->commit;
 
     if(!$U->is_true($hold->frozen) && $U->is_true($orig_hold->frozen)) {
@@ -1462,7 +1462,7 @@ sub update_hold_if_frozen {
     } else {
         if($U->is_true($orig_hold->frozen)) {
             $logger->info("Running targeter on activated hold ".$hold->id);
-            create_reset_hold_note($e,$hold,"Hold Reset by Unfreezing","Running targeter on activated hold");
+            _create_reset_hold_note($e,$hold,"Hold Reset by Unfreezing","Running targeter on activated hold");
             $U->simplereq('open-ils.hold-targeter', 
                 'open-ils.hold-targeter.target', {hold => $hold->id});
         }
@@ -2222,20 +2222,42 @@ sub reset_hold {
     return 1;
 }
 
+__PACKAGE__->register_method(
+    method   => 'create_reset_hold_note',
+    api_name => 'open-ils.circ.hold_reset_note.create'
+);
+
 sub create_reset_hold_note
 {
+    my($self, $conn, $holdid, $title, $note_body) = @_;
+    my $e = new_editor(xact => 1);
+    $logger->info("got editor");
+    #return $e->die_event unless $e->checkauth;
+    my ($hold, $evt) = $U->fetch_hold($holdid);
+    $logger->info("fetched hold");
+    return $evt if $evt;   
+    _create_reset_hold_note($e, $hold, $title, $note_body);
+    $e->commit;
+    return 1;
+}
+
+sub _create_reset_hold_note
+{
     my($e, $hold, $title, $note_body) = @_;
     my $ts = DateTime->now;
-    my $note = Fieldmapper::action::hold_request_note->new;  
+    my $note = Fieldmapper::action::hold_request_note->new; 
+    $logger->info("Creating hold note with title: " . $title . " and body: " . $note_body . " hold id: " . $hold->id);    
     my $last_copy = $hold->current_copy || 0;
     my $reqr = $e->requestor;
+    my $reqr_id = defined $reqr ? $reqr->id : 0;
+    my $reqr_usrname = $reqr_id ? $reqr->usrname : "";
     $title.=" ".$ts->mdy." ".$ts->hms;
     my $json = "{";
     $json .= "\"Reset Reason\" : \"$note_body\",";
     $json .= "\"Timestamp\" : \"".$ts->mdy." ".$ts->hms."\",";
     $json .= "\"Previous Copy ID\" : \"$last_copy\"," unless $last_copy == 0;
-    $json .= "\"Requestor ID\" : \"".$reqr->id."\",";
-    $json .= "\"Requestor Usrname\" : \"".$reqr->usrname."\"";
+    $json .= "\"Requestor ID\" : \"".$reqr_id."\",";
+    $json .= "\"Requestor Usrname\" : \"".$reqr_usrname."\"";
     $json .= "}";
     $note->hold($hold);
     $note->staff(1);
@@ -2315,7 +2337,7 @@ sub _reset_hold {
         }
     }
 
-    create_reset_hold_note($e,$hold,"Hold Reset by Staff",$note_body);
+    _create_reset_hold_note($e,$hold,"Hold Reset by Staff",$note_body);
     $hold->clear_capture_time;
     $hold->clear_current_copy;
     $hold->clear_shelf_time;
@@ -3536,6 +3558,7 @@ sub find_nearest_permitted_hold {
         next if $old_hold->id eq $best_hold->id; # don't re-target the hold we want
         $logger->info("circulator: clearing current_copy and prev_check_time on hold ".
             $old_hold->id." after a better hold [".$best_hold->id."] was found");
+        _create_reset_hold_note($editor,$old_hold,"Hold Reset due to Age","Old hold was reset. Last check time was ".$old_hold->prev_check_time.". a better hold [".$best_hold->id."] was found");
         $old_hold->clear_current_copy;
         $old_hold->clear_prev_check_time;
         $editor->update_action_hold_request($old_hold)
index afca2fc..de1553d 100644 (file)
@@ -80,13 +80,20 @@ sub hold_targeter {
     my $total = scalar(@hold_ids);
 
     $logger->info("targeter processing $total holds");
-
+    my $hold_ses = create OpenSRF::AppSession("open-ils.circ");
+    
     for my $hold_id (@hold_ids) {
         $count++;
 
         my $single = 
             OpenILS::Utils::HoldTargeter::Single->new(parent => $targeter);
 
+        $hold_ses->request(
+        "open-ils.circ.hold_reset_note.create",
+        $hold_id,
+        "Hold Automatically Retargeted",
+        "Automatic Reset.") unless defined $args->{hold};
+
         # Don't let an explosion on a single hold stop processing
         eval { $single->target($hold_id) };
 
@@ -105,9 +112,10 @@ sub hold_targeter {
             $client->respond($res);
 
             $logger->info("targeted $count of $total holds");
-        }
+        }        
     }
-
+    $hold_ses->disconnect;
+    
     return undef;
 }