KMIG-52-KCLSUPGRAD-98-user_activity_tracking_feature
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Oct 2014 21:05:54 +0000 (17:05 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
    Cross-port: e774e36

Conflicts:
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm

KCLS/sql/kmain-81-upgrad-98_usr_activity_types.sql [new file with mode: 0644]
KCLS/sql/kmain-81-upgrad-98_usr_activity_types_rollback.sql [new file with mode: 0644]
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm

diff --git a/KCLS/sql/kmain-81-upgrad-98_usr_activity_types.sql b/KCLS/sql/kmain-81-upgrad-98_usr_activity_types.sql
new file mode 100644 (file)
index 0000000..73e2f94
--- /dev/null
@@ -0,0 +1,22 @@
+--Insert in four more activity types (Payment, Checkin, Checkout, Hold Request).
+--Default Activity Types use up the first 24 of the 1000 reserved IDs.
+INSERT INTO config.usr_activity_type (ewhat, egroup, label)
+VALUES
+('payment' ,'circ', 'Payment'),
+('checkin' ,'circ', 'Check in'),
+('checkout' ,'circ', 'Check out'),
+('hold' ,'hold' , 'Hold Request')
+;
+
+
+-- Change constraint to 'cascade' on delete, rather than 'no action'
+-- For easier rollback of activities
+
+ALTER TABLE actor.usr_activity
+    DROP CONSTRAINT usr_activity_etype_fkey;
+
+ALTER TABLE actor.usr_activity
+    ADD CONSTRAINT usr_activity_etype_fkey FOREIGN KEY (etype)
+    REFERENCES config.usr_activity_type (id) MATCH SIMPLE
+    ON UPDATE NO ACTION ON DELETE CASCADE;
+
diff --git a/KCLS/sql/kmain-81-upgrad-98_usr_activity_types_rollback.sql b/KCLS/sql/kmain-81-upgrad-98_usr_activity_types_rollback.sql
new file mode 100644 (file)
index 0000000..3b92d41
--- /dev/null
@@ -0,0 +1,20 @@
+
+------- Delete added user activities -------------------------
+DELETE FROM  config.usr_activity_type
+WHERE ewho IS NULL AND ehow IS NULL AND ewhat = 'payment';
+DELETE FROM  config.usr_activity_type
+WHERE ewho IS NULL AND ehow IS NULL AND ewhat = 'checkin';
+DELETE FROM  config.usr_activity_type
+WHERE ewho IS NULL AND ehow IS NULL AND ewhat = 'checkout';
+DELETE FROM  config.usr_activity_type
+WHERE ewho IS NULL AND ehow IS NULL AND ewhat = 'hold';
+
+-------Revert constraint change------
+ALTER TABLE actor.usr_activity
+    DROP CONSTRAINT usr_activity_etype_fkey;
+
+ALTER TABLE actor.usr_activity
+    ADD CONSTRAINT usr_activity_etype_fkey FOREIGN KEY (etype)
+    REFERENCES config.usr_activity_type (id) MATCH SIMPLE
+    ON UPDATE NO ACTION ON DELETE NO ACTION;
+
index 6b7ab50..eb5e9b6 100644 (file)
@@ -254,6 +254,7 @@ sub run_method {
 
     return circ_events($circulator) if $circulator->bail_out;
 
+    my $ops = 0;
     if( $api =~ /checkout\.permit/ ) {
         $circulator->do_permit();
 
@@ -268,6 +269,7 @@ sub run_method {
         unless( $circulator->bail_out ) {
             $circulator->events([]);
             $circulator->do_checkout();
+           $ops = 1;
         }
 
     } elsif( $circulator->is_res_checkout ) {
@@ -280,12 +282,14 @@ sub run_method {
 
     } elsif( $api =~ /checkout/ ) {
         $circulator->do_checkout();
+       $ops = 1;
 
     } elsif( $circulator->is_res_checkin ) {
         $circulator->do_reservation_return();
         $circulator->do_checkin() if ($circulator->copy());
     } elsif( $api =~ /checkin/ ) {
         $circulator->do_checkin();
+       $ops = 2;
 
     } elsif( $api =~ /renew/ ) {
         $circulator->do_renew($api);
@@ -318,6 +322,14 @@ sub run_method {
         }
 
         $circulator->editor->commit;
+
+        if($ops == 1) {
+            $U->log_user_activity($$args{patron_id}, '', 'checkout');
+        } elsif ($ops == 2) {
+            if ($circulator->circ) {
+                $U->log_user_activity($circulator->circ->usr, '', 'checkin');
+            }
+        }
     }
     
     $conn->respond_complete(circ_events($circulator));
@@ -4292,80 +4304,4 @@ sub checkin_handle_lost_or_lo_now_found_restore_od {
     }
 }
 
-# ------------------------------------------------------------------
-# Lost-then-found item checked in.  This sub generates new overdue
-# fines, beyond the point of any existing and possibly voided 
-# overdue fines, up to the point of final checkin time (or max fine
-# amount).  
-# ------------------------------------------------------------------
-sub generate_lost_overdue_fines {
-    my $self = shift;
-    my $circ = $self->circ;
-    my $e = $self->editor;
-    my $isBackDated = 0;
-
-    # Re-open the transaction so the fine generator can see it
-    if ($circ->checkin_time == $circ->checkin_scan_time) {
-        #Check in is not backdated
-        if($circ->xact_finish or $circ->stop_fines) {
-            $e->xact_begin;
-            $circ->clear_xact_finish;
-            $circ->clear_stop_fines;
-            $circ->clear_stop_fines_time;
-            $e->update_action_circulation($circ) or return $e->die_event;
-            $e->xact_commit;
-        }
-    }
-    else {
-        #Check in is backdated
-        $isBackDated = 1;
-        if($circ->xact_finish or $circ->stop_fines) {
-            $e->xact_begin;
-            $circ->clear_xact_finish;
-            $e->update_action_circulation($circ) or return $e->die_event;
-            $e->xact_commit;
-        }
-    }
-
-    $e->xact_begin; # generate_fines expects an in-xact editor
-    $self->generate_fines;
-    $circ = $self->circ; # generate fines re-fetches the circ
-    
-    my $update = 0;
-
-    # Re-close the transaction if no money is owed
-    my ($obt) = $U->fetch_mbts($circ->id, $e);
-    if ($obt and $obt->balance_owed == 0) {
-        $circ->xact_finish('now');
-        $update = 1;
-    }
-
-    if ($isBackDated == 1) {
-        #Check in is backdated
-        if($circ->xact_finish or $circ->stop_fines) {
-            $circ->clear_stop_fines;
-            $circ->clear_stop_fines_time;
-        }
-    }
-
-    # Set stop fines if the fine generator didn't have to
-    unless($circ->stop_fines) {
-        $circ->stop_fines(OILS_STOP_FINES_CHECKIN);
-        $circ->stop_fines_time('now');
-        $update = 1;
-    }
-
-    # update the event data sent to the caller within the transaction
-    $self->checkin_flesh_events;
-
-    if ($update) {
-        $e->update_action_circulation($circ) or return $e->die_event;
-        $e->commit;
-    } else {
-        $e->rollback;
-    }
-
-    return undef;
-}
-
 1;
index e9ac64e..ff0815b 100644 (file)
@@ -395,6 +395,7 @@ sub create_hold {
         'open-ils.hold-targeter.target', {hold => $hold->id}
     ) unless $U->is_true($hold->frozen);
 
+    $U->log_user_activity($recipient->id, $self->get_act_who, 'hold');
     return undef;
 }
 
index 6b84a78..b00ad01 100644 (file)
@@ -570,6 +570,7 @@ sub make_payments {
     $U->simplereq('open-ils.auth', 'open-ils.auth.session.reset_timeout', $auth, 1)
         if $user_id == $e->requestor->id;
 
+    $U->log_user_activity($user_id, '', 'payment');
     return {last_xact_id => $patron->last_xact_id, payments => \@payment_ids};
 }