LP#1251415: Skip deleted users in juvenile update
authorBill Erickson <berickxx@gmail.com>
Mon, 10 Aug 2015 20:05:45 +0000 (16:05 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 4 Nov 2015 21:56:37 +0000 (21:56 +0000)
Avoid setting juvenile = false on deleted users during the batch
juvenile update routine, even if they are a million years old.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/actor.pm

index ff9327f..e2a4edc 100644 (file)
@@ -30,13 +30,13 @@ sub juv_to_adult {
     my $adult_age = shift;
 
     my $sql = <<"    SQL";
-            UPDATE  actor.usr
-              SET   juvenile = FALSE
-              WHERE id IN (
-              SELECT au.id
-              FROM actor.usr au
-              WHERE AGE(au.dob) > COALESCE( BTRIM( (SELECT value FROM actor.org_unit_ancestor_setting('global.juvenile_age_threshold', au.home_ou)),'"' ), ? )::INTERVAL
-              AND au.juvenile IS TRUE)
+        UPDATE actor.usr
+            SET juvenile = FALSE
+            WHERE juvenile IS TRUE
+            AND deleted IS FALSE
+            AND AGE(dob) > COALESCE( BTRIM( (
+                    SELECT value FROM actor.org_unit_ancestor_setting(
+                    'global.juvenile_age_threshold', home_ou)),'"' ), ?)::INTERVAL
     SQL
 
     my $sth = actor::user->db_Main->prepare_cached($sql);