From: Dan Wells Date: Tue, 24 May 2011 14:53:09 +0000 (-0400) Subject: Make label_class on any new call numbers default to org_unit setting X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=baa93a8b3c0b3f6a9148ca0b2533d808667f57ae;p=contrib%2FConifer.git Make label_class on any new call numbers default to org_unit setting Evergreen 2.0 added a label_class column to the call number table with one major purpose being the generation of correct sort keys. You can also specify a default label class as an org unit setting. However: 1) There are no interface elements for setting the label class of an individual call number. 2) The default setting from the actor.org_unit_setting 'cat.default_classification_scheme' value, if set, is not consulted (that is, not set in the call number table) when new call numbers are created. These two facts together greatly reduce the utility of this very valuable feature, as all new call numbers end up in the 'Generic' class. While #1 has been addressed in 2.1+, there is still work to be done in setting this class on import. Also, which interface parts (if any) make it back to 2.0 is subject to debate. This commit addresses #2. See lp #787150. Signed-off-by: Dan Wells Signed-off-by: Dan Scott --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 316c23d2cb..a3e0738667 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 ('0540'); -- dbwells +INSERT INTO config.upgrade_log (version) VALUES ('0541'); -- dbwells CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/040.schema.asset.sql b/Open-ILS/src/sql/Pg/040.schema.asset.sql index 4d4f0d9295..6f76ee39d1 100644 --- a/Open-ILS/src/sql/Pg/040.schema.asset.sql +++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql @@ -190,14 +190,16 @@ DECLARE 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_setting WHERE name = 'cat.default_classification_scheme' AND org_unit = 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; @@ -289,7 +291,7 @@ CREATE TABLE asset.call_number ( owning_lib INT NOT NULL, label TEXT NOT NULL, deleted BOOL NOT NULL DEFAULT FALSE, - label_class BIGINT DEFAULT 1 NOT NULL + label_class BIGINT NOT NULL REFERENCES asset.call_number_class(id) DEFERRABLE INITIALLY DEFERRED, label_sortkey TEXT diff --git a/Open-ILS/src/sql/Pg/upgrade/0541.schema.call_number_honor_default_class.sql b/Open-ILS/src/sql/Pg/upgrade/0541.schema.call_number_honor_default_class.sql new file mode 100644 index 0000000000..32be6a3c1e --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0541.schema.call_number_honor_default_class.sql @@ -0,0 +1,27 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('0541', :eg_version); -- dbwells + +ALTER TABLE asset.call_number ALTER COLUMN label_class DROP DEFAULT; + +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_setting WHERE name = 'cat.default_classification_scheme' AND org_unit = 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;