From: Bill Erickson Date: Tue, 6 Aug 2013 15:09:45 +0000 (-0400) Subject: LP1207396 purge old pending users X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=26b04ccb853a4edd71bd820231061d4eeec16f53;p=evergreen%2Fmasslnc.git LP1207396 purge old pending users 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 Signed-off-by: Dan Wells --- diff --git a/Open-ILS/examples/crontab.example b/Open-ILS/examples/crontab.example index 1cd1db3d7d..5838ff400c 100644 --- a/Open-ILS/examples/crontab.example +++ b/Open-ILS/examples/crontab.example @@ -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 diff --git a/Open-ILS/src/sql/Pg/015.schema.staging.sql b/Open-ILS/src/sql/Pg/015.schema.staging.sql index 83bc697255..3f558e1ae5 100644 --- a/Open-ILS/src/sql/Pg/015.schema.staging.sql +++ b/Open-ILS/src/sql/Pg/015.schema.staging.sql @@ -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; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.patron-self-reg.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.patron-self-reg.sql index 9f6a574991..a08d957443 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.patron-self-reg.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.patron-self-reg.sql @@ -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 index 0000000000..56d337aba4 --- /dev/null +++ b/Open-ILS/src/support-scripts/purge_pending_users.srfsh @@ -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 +