JBAS-827 Move juv/adult and envisionware updates to utility
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Jul 2015 21:51:58 +0000 (17:51 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Make utility-server friendly versions of the juv_to_adult and
envisionware access batch SQL scripts.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/utility-scripts/CRONTAB
KCLS/utility-scripts/envware_access/envware_access.sh [new file with mode: 0755]
KCLS/utility-scripts/envware_access/envware_access.sql [new file with mode: 0644]
KCLS/utility-scripts/juv_to_adult/juv_to_adult.sh [new file with mode: 0755]
KCLS/utility-scripts/juv_to_adult/juv_to_adult.sql [new file with mode: 0644]

index b4626ca..4f4abef 100644 (file)
@@ -95,6 +95,12 @@ PGHOST     = localhost # change for cluster install
 # Update copy status for BC
 #0 22 * * * cd $SCRIPT_DIR/bc_missing/ && ./bc_missing.sh
 
+# Update Envisionware patron access
+#30 0 * * * cd $SCRIPT_DIR/envware_access/ && ./envware_access.sh
+
+# Update Envisionware patron access
+#0 1 * * * cd $SCRIPT_DIR/juv_to_adult/ && ./juv_to_adult.sh
+
 # Anonymize a range of historical circs each night, with a maximum run
 # time of 120 minutes.  We split them up, because each range takes time
 # to run (~45 minutes). The first range starts at 2004-08-12, which is the
diff --git a/KCLS/utility-scripts/envware_access/envware_access.sh b/KCLS/utility-scripts/envware_access/envware_access.sh
new file mode 100755 (executable)
index 0000000..405ea3f
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -eu
+
+echo -n "Updating Envisionware access at ";
+date +"%F %T"
+
+psql -U evergreen -f envware_access.sql
+
+echo -n "Completed updating Envisionware access at "
+date +"%F %T"
diff --git a/KCLS/utility-scripts/envware_access/envware_access.sql b/KCLS/utility-scripts/envware_access/envware_access.sql
new file mode 100644 (file)
index 0000000..1f93387
--- /dev/null
@@ -0,0 +1,38 @@
+-- Run these two commands prior to invoking this script:
+-- CREATE SCHEMA envisionware;
+--
+-- CREATE TABLE envisionware.users_made_no_access (
+--      id INTEGER,
+--      original_net_access_level INTEGER,
+--      date_changed TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
+-- );
+
+BEGIN;
+
+SET statement_timeout = 0;
+
+CREATE TEMP TABLE temp_users (
+    id INTEGER PRIMARY KEY,
+    original_net_access_level INTEGER
+);
+
+INSERT INTO temp_users (id,original_net_access_level)
+    SELECT id, net_access_level FROM actor.usr WHERE
+        (active = false OR expire_date < NOW())
+        AND net_access_level <> 101; -- 4 in test, 101 in prod
+
+INSERT INTO envisionware.users_made_no_access(id,original_net_access_level)
+    SELECT * FROM temp_users;
+
+INSERT INTO actor.usr_standing_penalty (usr,standing_penalty,org_unit,note)
+    SELECT
+        u.id,
+        21, -- SILENT_NOTE
+        1, -- or u.home_ou
+        'Original filter prior to Envisionware rollover: ' || name
+    FROM temp_users u, config.net_access_level c
+    WHERE original_net_access_level = c.id;
+
+UPDATE actor.usr u SET net_access_level = 101 FROM temp_users t WHERE u.id = t.id; -- 4 in test, 101 in prod
+UPDATE actor.usr u SET profile = 16 FROM temp_users t WHERE u.id = t.id; 
+COMMIT;
diff --git a/KCLS/utility-scripts/juv_to_adult/juv_to_adult.sh b/KCLS/utility-scripts/juv_to_adult/juv_to_adult.sh
new file mode 100755 (executable)
index 0000000..56964e5
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/bash
+set -eu
+
+echo -n "Updating patron juvenile flag at ";
+date +"%F %T" 
+
+psql -U evergreen -f juv_to_adult.sql
+
+echo -n "Completed updating patron juvenile flag at "
+date +"%F %T" 
+
+
diff --git a/KCLS/utility-scripts/juv_to_adult/juv_to_adult.sql b/KCLS/utility-scripts/juv_to_adult/juv_to_adult.sql
new file mode 100644 (file)
index 0000000..7a4f8fc
--- /dev/null
@@ -0,0 +1,10 @@
+-- query is more selective than that currently used by
+-- the  open-ils.storage.actor.user.juvenile_to_adult method
+-- ESI/Galen Charlton 2012-07-13
+-- TODO: add 'NOT deleted' to open-ils.storage method.
+-- so we won't need this custom script.
+SET statement_timeout = 0;
+
+UPDATE actor.usr SET juvenile = FALSE 
+    WHERE AGE(dob) > '18 years' AND juvenile AND NOT deleted;
+