[open-ils-commits] [GIT] Evergreen ILS branch rel_2_0 updated. 41f00b25bb95ac45c826304fb8e17844ad0e6fa2

Evergreen Git git at git.evergreen-ils.org
Thu Aug 18 19:02:41 EDT 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, rel_2_0 has been updated
       via  41f00b25bb95ac45c826304fb8e17844ad0e6fa2 (commit)
       via  f087dc931de79d3d5bc86866c4de64d557a7db51 (commit)
      from  6aa534f6a8d2af765c50e711fdd9479fbbf2347c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 41f00b25bb95ac45c826304fb8e17844ad0e6fa2
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Tue Aug 16 17:22:47 2011 -0400

    Stricter order for actor.org_unit_parent_protect()
    
    actor.org_unit_parent_protect() may not work due to the fact
    that 'IF' conditions in PL/pgSQL are not necessarily processed
    in the order written. This line:
    
    "IF TG_OP = 'INSERT' OR NEW.parent_ou
    IS DISTINCT FROM OLD.parent_ou THEN"
    
    may fail because the 'IS DISTINCT FROM' happens before the
    'INSERT' check, and and that fails because there is no 'OLD'
    variable for INSERTs.
    
    This commit may not be the optimal style for this circumstance
    in this language, but it works.  It also appears to change more
    than it really does due to a loss of one level of indentation in
    the structure.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 9140414..2183f19 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -57,7 +57,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0602'); -- miker/gmc
+INSERT INTO config.upgrade_log (version) VALUES ('0605'); -- dbwells/dbs
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/005.schema.actors.sql b/Open-ILS/src/sql/Pg/005.schema.actors.sql
index b9389d9..0768673 100644
--- a/Open-ILS/src/sql/Pg/005.schema.actors.sql
+++ b/Open-ILS/src/sql/Pg/005.schema.actors.sql
@@ -253,23 +253,29 @@ CREATE OR REPLACE FUNCTION actor.org_unit_parent_protect () RETURNS TRIGGER AS $
 		current_aou := NEW;
 		depth_count := 0;
 		seen_ous := ARRAY[NEW.id];
-		IF TG_OP = 'INSERT' OR NEW.parent_ou IS DISTINCT FROM OLD.parent_ou THEN
-			LOOP
-				IF current_aou.parent_ou IS NULL THEN -- Top of the org tree?
-					RETURN NEW; -- No loop. Carry on.
-				END IF;
-				IF current_aou.parent_ou = ANY(seen_ous) THEN -- Parent is one we have seen?
-					RAISE 'OU LOOP: Saw % twice', current_aou.parent_ou; -- LOOP! ABORT!
-				END IF;
-				-- Get the next one!
-				SELECT INTO current_aou * FROM actor.org_unit WHERE id = current_aou.parent_ou;
-				seen_ous := seen_ous || current_aou.id;
-				depth_count := depth_count + 1;
-				IF depth_count = 100 THEN
-					RAISE 'OU CHECK TOO DEEP';
-				END IF;
-			END LOOP;
+
+		IF (TG_OP = 'UPDATE') THEN
+			IF (NEW.parent_ou IS NOT DISTINCT FROM OLD.parent_ou) THEN
+				RETURN NEW; -- Doing an UPDATE with no change, just return it
+			END IF;
 		END IF;
+
+		LOOP
+			IF current_aou.parent_ou IS NULL THEN -- Top of the org tree?
+				RETURN NEW; -- No loop. Carry on.
+			END IF;
+			IF current_aou.parent_ou = ANY(seen_ous) THEN -- Parent is one we have seen?
+				RAISE 'OU LOOP: Saw % twice', current_aou.parent_ou; -- LOOP! ABORT!
+			END IF;
+			-- Get the next one!
+			SELECT INTO current_aou * FROM actor.org_unit WHERE id = current_aou.parent_ou;
+			seen_ous := seen_ous || current_aou.id;
+			depth_count := depth_count + 1;
+			IF depth_count = 100 THEN
+				RAISE 'OU CHECK TOO DEEP';
+			END IF;
+		END LOOP;
+
 		RETURN NEW;
 	END;
 $$ LANGUAGE PLPGSQL;
diff --git a/Open-ILS/src/sql/Pg/upgrade/0605.schema.lp826844_org_unit_parent_protect_fix.sql b/Open-ILS/src/sql/Pg/upgrade/0605.schema.lp826844_org_unit_parent_protect_fix.sql
new file mode 100644
index 0000000..12cf25c
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/0605.schema.lp826844_org_unit_parent_protect_fix.sql
@@ -0,0 +1,48 @@
+-- Evergreen DB patch XXXX.schema.lp826844_org_unit_parent_protect_fix.sql
+--
+-- Correct the fact that actor.org_unit_parent_protect() may not work
+-- due to 'IF' conditions in PL/pgSQL not necessarily processing in the
+-- order written
+--
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0605'); --dbwells via dbs
+
+CREATE OR REPLACE FUNCTION actor.org_unit_parent_protect () RETURNS TRIGGER AS $$
+	DECLARE
+		current_aou actor.org_unit%ROWTYPE;
+		seen_ous    INT[];
+		depth_count INT;
+	BEGIN
+		current_aou := NEW;
+		depth_count := 0;
+		seen_ous := ARRAY[NEW.id];
+
+		IF (TG_OP = 'UPDATE') THEN
+			IF (NEW.parent_ou IS NOT DISTINCT FROM OLD.parent_ou) THEN
+				RETURN NEW; -- Doing an UPDATE with no change, just return it
+			END IF;
+		END IF;
+
+		LOOP
+			IF current_aou.parent_ou IS NULL THEN -- Top of the org tree?
+				RETURN NEW; -- No loop. Carry on.
+			END IF;
+			IF current_aou.parent_ou = ANY(seen_ous) THEN -- Parent is one we have seen?
+				RAISE 'OU LOOP: Saw % twice', current_aou.parent_ou; -- LOOP! ABORT!
+			END IF;
+			-- Get the next one!
+			SELECT INTO current_aou * FROM actor.org_unit WHERE id = current_aou.parent_ou;
+			seen_ous := seen_ous || current_aou.id;
+			depth_count := depth_count + 1;
+			IF depth_count = 100 THEN
+				RAISE 'OU CHECK TOO DEEP';
+			END IF;
+		END LOOP;
+
+		RETURN NEW;
+	END;
+$$ LANGUAGE PLPGSQL;
+
+
+COMMIT;

commit f087dc931de79d3d5bc86866c4de64d557a7db51
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Tue Aug 16 17:16:35 2011 -0400

    Whitespace Only Changes
    
    Files uses primarily tabs, function used both spaces and tabs.
    It now uses all tabs.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/Open-ILS/src/sql/Pg/005.schema.actors.sql b/Open-ILS/src/sql/Pg/005.schema.actors.sql
index 72b7f5b..b9389d9 100644
--- a/Open-ILS/src/sql/Pg/005.schema.actors.sql
+++ b/Open-ILS/src/sql/Pg/005.schema.actors.sql
@@ -245,31 +245,31 @@ CREATE INDEX actor_org_unit_mailing_address_idx ON actor.org_unit (mailing_addre
 CREATE INDEX actor_org_unit_holds_address_idx ON actor.org_unit (holds_address);
 
 CREATE OR REPLACE FUNCTION actor.org_unit_parent_protect () RETURNS TRIGGER AS $$
-    DECLARE
-        current_aou actor.org_unit%ROWTYPE;
-        seen_ous    INT[];
-        depth_count INT;
+	DECLARE
+		current_aou actor.org_unit%ROWTYPE;
+		seen_ous    INT[];
+		depth_count INT;
 	BEGIN
-        current_aou := NEW;
-        depth_count := 0;
-        seen_ous := ARRAY[NEW.id];
-        IF TG_OP = 'INSERT' OR NEW.parent_ou IS DISTINCT FROM OLD.parent_ou THEN
-            LOOP
-                IF current_aou.parent_ou IS NULL THEN -- Top of the org tree?
-                    RETURN NEW; -- No loop. Carry on.
-                END IF;
-                IF current_aou.parent_ou = ANY(seen_ous) THEN -- Parent is one we have seen?
-                    RAISE 'OU LOOP: Saw % twice', current_aou.parent_ou; -- LOOP! ABORT!
-                END IF;
-                -- Get the next one!
-                SELECT INTO current_aou * FROM actor.org_unit WHERE id = current_aou.parent_ou;
-                seen_ous := seen_ous || current_aou.id;
-                depth_count := depth_count + 1;
-                IF depth_count = 100 THEN
-                    RAISE 'OU CHECK TOO DEEP';
-                END IF;
-            END LOOP;
-        END IF;
+		current_aou := NEW;
+		depth_count := 0;
+		seen_ous := ARRAY[NEW.id];
+		IF TG_OP = 'INSERT' OR NEW.parent_ou IS DISTINCT FROM OLD.parent_ou THEN
+			LOOP
+				IF current_aou.parent_ou IS NULL THEN -- Top of the org tree?
+					RETURN NEW; -- No loop. Carry on.
+				END IF;
+				IF current_aou.parent_ou = ANY(seen_ous) THEN -- Parent is one we have seen?
+					RAISE 'OU LOOP: Saw % twice', current_aou.parent_ou; -- LOOP! ABORT!
+				END IF;
+				-- Get the next one!
+				SELECT INTO current_aou * FROM actor.org_unit WHERE id = current_aou.parent_ou;
+				seen_ous := seen_ous || current_aou.id;
+				depth_count := depth_count + 1;
+				IF depth_count = 100 THEN
+					RAISE 'OU CHECK TOO DEEP';
+				END IF;
+			END LOOP;
+		END IF;
 		RETURN NEW;
 	END;
 $$ LANGUAGE PLPGSQL;

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/src/sql/Pg/002.schema.config.sql          |    2 +-
 Open-ILS/src/sql/Pg/005.schema.actors.sql          |   54 +++++++++++---------
 ...schema.lp826844_org_unit_parent_protect_fix.sql |   48 +++++++++++++++++
 3 files changed, 79 insertions(+), 25 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/0605.schema.lp826844_org_unit_parent_protect_fix.sql


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list