From cd85d310bfb0c9f8b248dd7f837d4771c1928d27 Mon Sep 17 00:00:00 2001 From: Chris Sharp Date: Thu, 25 Jun 2015 15:46:43 -0400 Subject: [PATCH] adding script to set patrons inactive --- sql/set_patrons_inactive.sql | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 sql/set_patrons_inactive.sql diff --git a/sql/set_patrons_inactive.sql b/sql/set_patrons_inactive.sql new file mode 100644 index 0000000..7c87653 --- /dev/null +++ b/sql/set_patrons_inactive.sql @@ -0,0 +1,55 @@ +-- a script to set users to inactive per PINES policy +-- designed to run nightly via cron + +begin; +update actor.usr au +set + active = false, + alert_message = 'automatically set to inactive status via PINES policy ' || alert_message, + last_update_time = now() +-- no unfinished circulations and no circulations within the last 3 years +where not exists ( + select 1 + from action.circulation ac + where ac.usr = au.id + and ( + xact_finish is null or ( + now() - ac.xact_start < '3 years'::interval + ) + ) + ) +-- no hold requests placed in the last 3 years +and not exists ( + select 1 + from action.hold_request ahr + where ahr.usr = au.id + and (now() - request_time) < '3 years'::interval + ) +-- no owed money in either direction and no payment within the last 3 years +and not exists ( + select 1 + from money.materialized_billable_xact_summary mmbxs + where mmbxs.usr = au.id + and ( + balance_owed <> '0.00' or (now() - last_payment_ts) < '3 years'::interval) + ) +-- no activity entries within the last 3 years +and not exists ( + select 1 + from actor.usr_activity aua + where aua.usr = au.id + and (now() - event_time) < '3 years'::interval + ) +-- we only care about active users +and au.active +-- we don't care about deleted users +and not au.deleted +-- we don't want users that have been created within the last 3 years +and (now() - au.create_date) > '3 years' +-- restrict to patron profiles ('Patrons' = 45) +and profile in ( + select id + from permission.grp_descendants(45) + ) +; +commit; -- 2.11.0