From 047e3586f757038e8e0c29b9d78f8191ae9d1683 Mon Sep 17 00:00:00 2001 From: Dan Wells Date: Tue, 24 May 2011 10:53:09 -0400 Subject: [PATCH] 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 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/040.schema.asset.sql | 8 +++--- ...schema.call_number_honor_default_class.sql | 27 +++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0541.schema.call_number_honor_default_class.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 1b9890e922..ebb1cf1343 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -86,7 +86,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0540', :eg_version); -- dbwells +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0541', :eg_version); -- 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 3e46a19c76..f335713e1f 100644 --- a/Open-ILS/src/sql/Pg/040.schema.asset.sql +++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql @@ -200,14 +200,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; @@ -337,7 +339,7 @@ CREATE TABLE asset.call_number ( deleted BOOL NOT NULL DEFAULT FALSE, prefix INT NOT NULL DEFAULT -1 REFERENCES asset.call_number_prefix(id) DEFERRABLE INITIALLY DEFERRED, suffix INT NOT NULL DEFAULT -1 REFERENCES asset.call_number_suffix(id) DEFERRABLE INITIALLY DEFERRED, - 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; -- 2.43.2