Purge Circulations: Skip partially complete chains
authorThomas Berezansky <tsbere@mvlc.org>
Mon, 18 Jun 2012 16:52:04 +0000 (12:52 -0400)
committerDan Wells <dbw2@calvin.edu>
Fri, 7 Jun 2013 19:49:45 +0000 (15:49 -0400)
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>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/sql/Pg/090.schema.action.sql

index c3f2814..293aafb 100644 (file)
@@ -987,6 +987,7 @@ DECLARE
 
     purge_position  INT;
     count_purged    INT;
+    num_incomplete  INT;
 BEGIN
 
     count_purged := 0;
@@ -1022,7 +1023,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;