Purge Circulations: Skip partially complete chains
authorThomas Berezansky <tsbere@mvlc.org>
Mon, 18 Jun 2012 16:52:04 +0000 (12:52 -0400)
committerJason Stephenson <jason@sigio.com>
Wed, 30 Jan 2013 20:17:15 +0000 (15:17 -0500)
Billings in earlier portions of the chain may leave them open. Thus, look
for any circulations in the chain with a null xact_finish.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/src/sql/Pg/090.schema.action.sql

index c59f27e..31e4e1e 100644 (file)
@@ -779,6 +779,7 @@ DECLARE
 
     purge_position  INT;
     count_purged    INT;
+    num_incomplete  INT;
 BEGIN
 
     count_purged := 0;
@@ -814,7 +815,8 @@ BEGIN
             EXIT WHEN target_acp.total_real_circs - purge_position <= org_keep_count;
 
             SELECT * INTO circ_chain_tail FROM action.circ_chain(circ_chain_head.id) ORDER BY xact_start DESC LIMIT 1;
-            EXIT WHEN circ_chain_tail.xact_finish IS NULL;
+            SELECT COUNT(CASE WHEN xact_finish IS NULL THEN 1 ELSE NULL END) INTO num_incomplete FROM action.circ_chain(circ_chain_head.id);
+            EXIT WHEN circ_chain_tail.xact_finish IS NULL OR num_incomplete > 0;
 
             -- Now get the user settings, if any, to block purging if the user wants to keep more circs
             usr_keep_age.value := NULL;