LP1207396 purge old pending users
authorBill Erickson <berick@esilibrary.com>
Tue, 6 Aug 2013 15:09:45 +0000 (11:09 -0400)
committerDan Wells <dbw2@calvin.edu>
Fri, 23 Aug 2013 23:14:19 +0000 (19:14 -0400)
Script to delete pending user accounts based on the interval defined in
the opac.pending_user_expire_interval org unit setting.

Add /openils/bin/purge_pending_users.srfsh to opensrf's CRON.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/examples/crontab.example
Open-ILS/src/sql/Pg/015.schema.staging.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.patron-self-reg.sql
Open-ILS/src/support-scripts/purge_pending_users.srfsh [new file with mode: 0755]

index 1cd1db3..5838ff4 100644 (file)
@@ -42,6 +42,9 @@ EG_BIN_DIR = /openils/bin
 # Run the reshelving completer
 2  0  * * *   . ~/.bashrc && $EG_BIN_DIR/reshelving_complete.srfsh
 
+# Run the pending user purger
+2  30  * * *   . ~/.bashrc && $EG_BIN_DIR/purge_pending_users.srfsh
+
 # create the list of blocked patrons for offline use
 # Note: The resulting list.txt file needs to be copied to all Apache servers
 30 6  * * *   . ~/.bashrc && $EG_BIN_DIR/offline-blocked-list.pl $SRF_CORE > $OPENILS/var/web/standalone/list.txt
index 83bc697..3f558e1 100644 (file)
@@ -60,5 +60,29 @@ CREATE TABLE staging.statcat_stage (
         complete        BOOL DEFAULT FALSE
 );
 
+-- stored procedure for deleting expired pending patrons
+CREATE OR REPLACE FUNCTION staging.purge_pending_users() RETURNS VOID AS $$
+DECLARE
+    org_id INT;
+    intvl TEXT;
+BEGIN
+    FOR org_id IN SELECT DISTINCT(home_ou) FROM staging.user_stage LOOP
+
+        SELECT INTO intvl value FROM 
+            actor.org_unit_ancestor_setting(
+                'opac.pending_user_expire_interval', org_id);
+
+        CONTINUE WHEN intvl IS NULL OR intvl ILIKE 'null';
+
+        -- de-JSON-ify the string
+        SELECT INTO intvl TRIM(BOTH '"' FROM intvl);
+
+        DELETE FROM staging.user_stage 
+            WHERE home_ou = org_id AND row_date + intvl::INTERVAL < NOW();
+
+    END LOOP;
+END;
+$$ LANGUAGE PLPGSQL;
+
 COMMIT;
 
index 9f6a574..a08d957 100644 (file)
@@ -18,6 +18,31 @@ ALTER TABLE staging.billing_address_stage
     ALTER COLUMN state DROP DEFAULT,
     ALTER COLUMN state DROP NOT NULL;
 
+-- stored procedure for deleting expired pending patrons
+CREATE OR REPLACE FUNCTION staging.purge_pending_users() RETURNS VOID AS $$
+DECLARE
+    org_id INT;
+    intvl TEXT;
+BEGIN
+    FOR org_id IN SELECT DISTINCT(home_ou) FROM staging.user_stage LOOP
+
+        SELECT INTO intvl value FROM 
+            actor.org_unit_ancestor_setting(
+                'opac.pending_user_expire_interval', org_id);
+
+        CONTINUE WHEN intvl IS NULL OR intvl ILIKE 'null';
+
+        -- de-JSON-ify the string
+        SELECT INTO intvl TRIM(BOTH '"' FROM intvl);
+
+        DELETE FROM staging.user_stage 
+            WHERE home_ou = org_id AND row_date + intvl::INTERVAL < NOW();
+
+    END LOOP;
+END;
+$$ LANGUAGE PLPGSQL;
+
+
 INSERT INTO config.org_unit_setting_type
     (name, grp, datatype, label, description)
 VALUES (
diff --git a/Open-ILS/src/support-scripts/purge_pending_users.srfsh b/Open-ILS/src/support-scripts/purge_pending_users.srfsh
new file mode 100755 (executable)
index 0000000..56d337a
--- /dev/null
@@ -0,0 +1,7 @@
+#!/openils/bin/srfsh
+open open-ils.cstore
+request open-ils.cstore open-ils.cstore.transaction.begin
+request open-ils.cstore open-ils.cstore.json_query {"from":["staging.purge_pending_users"]}
+request open-ils.cstore open-ils.cstore.transaction.commit
+close open-ils.cstore
+