lp#825303: fix cat.default_classification_scheme lookup
authorGalen Charlton <gmc@esilibrary.com>
Fri, 12 Aug 2011 16:18:54 +0000 (12:18 -0400)
committerMike Rylander <mrylander@gmail.com>
Tue, 16 Aug 2011 12:57:13 +0000 (08:57 -0400)
Fixes a bug where the wrong default classification scheme
could be chosen when adding a new volume whose classification
scheme was not explicitly set.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/sql/Pg/040.schema.asset.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.fix_cat_default_class_lookup.sql [new file with mode: 0644]

index 4698e3f..ca584a1 100644 (file)
@@ -262,9 +262,7 @@ BEGIN
             NEW.label_class := COALESCE(
             (
                 SELECT substring(value from E'\\d+')::integer
             NEW.label_class := COALESCE(
             (
                 SELECT substring(value from E'\\d+')::integer
-                FROM actor.org_unit_setting
-                WHERE name = 'cat.default_classification_scheme'
-                AND org_unit = NEW.owning_lib
+                FROM actor.org_unit_ancestor_setting('cat.default_classification_scheme', NEW.owning_lib)
             ), 1
         );
     END IF;
             ), 1
         );
     END IF;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.fix_cat_default_class_lookup.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.fix_cat_default_class_lookup.sql
new file mode 100644 (file)
index 0000000..5f52d89
--- /dev/null
@@ -0,0 +1,38 @@
+-- Evergreen DB patch XXXX.fix_cat_default_class_lookup.sql
+--
+-- Fix LP#825303 by allowing for ancestor OUs to be checked
+-- when retrieving the default classification scheme.
+--
+BEGIN;
+
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION asset.label_normalizer() RETURNS TRIGGER AS $func$
+DECLARE
+    sortkey        TEXT := '';
+BEGIN
+    sortkey := NEW.label_sortkey;
+
+    IF NEW.label_class IS NULL THEN
+            NEW.label_class := COALESCE(
+            (
+                SELECT substring(value from E'\\d+')::integer
+                FROM actor.org_unit_ancestor_setting('cat.default_classification_scheme', NEW.owning_lib)
+            ), 1
+        );
+    END IF;
+
+    EXECUTE 'SELECT ' || acnc.normalizer || '(' || 
+       quote_literal( NEW.label ) || ')'
+       FROM asset.call_number_class acnc
+       WHERE acnc.id = NEW.label_class
+       INTO sortkey;
+    NEW.label_sortkey = sortkey;
+    RETURN NEW;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+
+COMMIT;