Lp 1835035: Refactor auto_renewal back end code
authorJason Stephenson <jason@sigio.com>
Fri, 30 Aug 2019 15:37:24 +0000 (11:37 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 1 Oct 2019 21:23:02 +0000 (17:23 -0400)
Refactor the auto_renewal feature so that it works like other renewal
types: opac_renewal, sip_renewal, etc.  This refactor prevents
desk_renewal from being set when auto_renewal is set.

Deprecate the newly added open-ils.circ.renew.auto API and ensure that
it still works as intended.  Add release note indicating the
deprecation of this API and intent to remove it in Evergreen 3.5.

Modify the AutoRenew action trigger reactor to use the plain
open-ils.circ.renew API with the auto_renewal option set to 1.

Add database update script to cleanup (i.e. set to FALSE) the
desk_renewal field on action.circulation and action.aged_circulation
tables where auto_renewal is TRUE.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/Circ/AutoRenew.pm
Open-ILS/src/sql/Pg/upgrade/XXXX.data.auto_renewal-not-desk_renewal.sql [new file with mode: 0644]
docs/RELEASE_NOTES_NEXT/Circulation/auto-renew-api-deprecation.adoc [new file with mode: 0644]

index 5c810d6..d99d525 100644 (file)
@@ -128,6 +128,10 @@ __PACKAGE__->register_method(
     method    => "run_method",
     api_name  => "open-ils.circ.renew.auto",
     signature => q/@see open-ils.circ.renew/,
     method    => "run_method",
     api_name  => "open-ils.circ.renew.auto",
     signature => q/@see open-ils.circ.renew/,
+    notes     => q/
+    The open-ils.circ.renew.auto API is deprecated.  Please use the
+    auto_renew => 1 option to open-ils.circ.renew, instead.
+    /
 );
 
 __PACKAGE__->register_method(
 );
 
 __PACKAGE__->register_method(
@@ -244,7 +248,7 @@ sub run_method {
     }
 
     $circulator->is_renewal(1) if $api =~ /renew/;
     }
 
     $circulator->is_renewal(1) if $api =~ /renew/;
-    $circulator->is_autorenewal(1) if $api =~ /renew.auto/;
+    $circulator->auto_renewal(1) if $api =~ /renew.auto/;
     $circulator->is_checkin(1) if $api =~ /checkin/;
     $circulator->is_checkout(1) if $api =~ /checkout/;
     $circulator->override(1) if $api =~ /override/o;
     $circulator->is_checkin(1) if $api =~ /checkin/;
     $circulator->is_checkout(1) if $api =~ /checkout/;
     $circulator->override(1) if $api =~ /override/o;
@@ -435,7 +439,6 @@ my @AUTOLOAD_FIELDS = qw/
     volume
     title
     is_renewal
     volume
     title
     is_renewal
-    is_autorenewal
     is_checkout
     is_res_checkout
     is_precat
     is_checkout
     is_res_checkout
     is_precat
@@ -487,6 +490,7 @@ my @AUTOLOAD_FIELDS = qw/
     phone_renewal
     desk_renewal
     sip_renewal
     phone_renewal
     desk_renewal
     sip_renewal
+    auto_renewal
     retarget
     matrix_test_result
     circ_matrix_matchpoint
     retarget
     matrix_test_result
     circ_matrix_matchpoint
@@ -565,8 +569,9 @@ sub new {
         ($self->circ_lib) ? $self->circ_lib : $self->editor->requestor->ws_ou);
 
     # if this is a renewal, default to desk_renewal
         ($self->circ_lib) ? $self->circ_lib : $self->editor->requestor->ws_ou);
 
     # if this is a renewal, default to desk_renewal
-    $self->desk_renewal(1) unless 
-        $self->opac_renewal or $self->phone_renewal or $self->sip_renewal;
+    $self->desk_renewal(1) unless
+        $self->opac_renewal or $self->phone_renewal or $self->sip_renewal
+        or $self->auto_renewal;
 
     $self->capture('') unless $self->capture;
 
 
     $self->capture('') unless $self->capture;
 
@@ -2155,13 +2160,10 @@ sub build_checkout_circ_object {
       $circ->opac_renewal('t') if $self->opac_renewal;
       $circ->phone_renewal('t') if $self->phone_renewal;
       $circ->desk_renewal('t') if $self->desk_renewal;
       $circ->opac_renewal('t') if $self->opac_renewal;
       $circ->phone_renewal('t') if $self->phone_renewal;
       $circ->desk_renewal('t') if $self->desk_renewal;
+      $circ->auto_renewal('t') if $self->auto_renewal;
       $circ->renewal_remaining($self->renewal_remaining);
       $circ->renewal_remaining($self->renewal_remaining);
-      $circ->circ_staff($self->editor->requestor->id);
-   }
-
-   if ( $self->is_autorenewal ){
       $circ->auto_renewal_remaining($self->auto_renewal_remaining);
       $circ->auto_renewal_remaining($self->auto_renewal_remaining);
-      $circ->auto_renewal('t');
+      $circ->circ_staff($self->editor->requestor->id);
    }
 
     # if the user provided an overiding checkout time,
    }
 
     # if the user provided an overiding checkout time,
@@ -4057,7 +4059,7 @@ sub do_renew {
         if $circ->renewal_remaining < 1;
 
     $self->push_events(OpenILS::Event->new('MAX_AUTO_RENEWALS_REACHED'))
         if $circ->renewal_remaining < 1;
 
     $self->push_events(OpenILS::Event->new('MAX_AUTO_RENEWALS_REACHED'))
-        if $api =~ /renew.auto/ and $circ->auto_renewal_remaining < 1;
+        if $self->auto_renewal and $circ->auto_renewal_remaining < 1;
     # -----------------------------------------------------------------
 
     $self->parent_circ($circ->id);
     # -----------------------------------------------------------------
 
     $self->parent_circ($circ->id);
@@ -4066,7 +4068,7 @@ sub do_renew {
     $self->circ($circ);
 
     # Opac renewal - re-use circ library from original circ (unless told not to)
     $self->circ($circ);
 
     # Opac renewal - re-use circ library from original circ (unless told not to)
-    if($self->opac_renewal or $api =~ /renew.auto/) {
+    if($self->opac_renewal or $self->auto_renewal) {
         unless(defined($opac_renewal_use_circ_lib)) {
             my $use_circ_lib = $self->editor->retrieve_config_global_flag('circ.opac_renewal.use_original_circ_lib');
             if($use_circ_lib and $U->is_true($use_circ_lib->enabled)) {
         unless(defined($opac_renewal_use_circ_lib)) {
             my $use_circ_lib = $self->editor->retrieve_config_global_flag('circ.opac_renewal.use_original_circ_lib');
             if($use_circ_lib and $U->is_true($use_circ_lib->enabled)) {
index f06adc8..09dc0b1 100644 (file)
@@ -53,12 +53,12 @@ sub handler {
         $logger->info( "AUTORENEW: circ.target_copy: " . Dumper($_->target_copy()) );
         my $evt = $AppUtils->simplereq(
             'open-ils.circ',
         $logger->info( "AUTORENEW: circ.target_copy: " . Dumper($_->target_copy()) );
         my $evt = $AppUtils->simplereq(
             'open-ils.circ',
-            'open-ils.circ.renew.auto',
+            'open-ils.circ.renew',
             $token,
             {
                 patron_id => $_->usr(),
                 copy_id => $_->target_copy(),
             $token,
             {
                 patron_id => $_->usr(),
                 copy_id => $_->target_copy(),
-                opac_renewal => 0
+                auto_renewal => 1
             }
         );
 
             }
         );
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.auto_renewal-not-desk_renewal.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.auto_renewal-not-desk_renewal.sql
new file mode 100644 (file)
index 0000000..0afb614
--- /dev/null
@@ -0,0 +1,9 @@
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+UPDATE action.circulation SET desk_renewal = FALSE WHERE auto_renewal IS TRUE;
+
+UPDATE action.aged_circulation SET desk_renewal = FALSE WHERE auto_renewal IS TRUE;
+
+COMMIT;
diff --git a/docs/RELEASE_NOTES_NEXT/Circulation/auto-renew-api-deprecation.adoc b/docs/RELEASE_NOTES_NEXT/Circulation/auto-renew-api-deprecation.adoc
new file mode 100644 (file)
index 0000000..8f3ae66
--- /dev/null
@@ -0,0 +1,6 @@
+open-ils.circ.renew.auto API Deprecated
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+The open-ils.circ.renew.auto API added in release 3.2 is deprecated
+and will be removed in Evergreen release 3.5.  Please switch to using
+the open-ils.circ.renew API with the auto_renew option set to 1 in any
+custom code.