From: Dan Scott Date: Thu, 22 Mar 2012 16:53:13 +0000 (-0400) Subject: Wrap upgrade script for CSV circ history export X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=001ef6a6b0f4da8ea5a3606c415a9bbfe0a6a9d8;p=contrib%2FConifer.git Wrap upgrade script for CSV circ history export Thanks, Bill! Signed-off-by: Dan Scott --- diff --git a/Open-ILS/src/sql/Pg/upgrade/0688.data.circ_history_export_csv.sql b/Open-ILS/src/sql/Pg/upgrade/0688.data.circ_history_export_csv.sql new file mode 100644 index 0000000000..25e451bb8c --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0688.data.circ_history_export_csv.sql @@ -0,0 +1,54 @@ +-- Evergreen DB patch 0688.data.circ_history_export_csv.sql +-- +-- FIXME: insert description of change, if needed +-- +BEGIN; + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('0688', :eg_version); + +INSERT INTO action_trigger.hook (key, core_type, description, passive) +VALUES ( + 'circ.format.history.csv', + 'circ', + oils_i18n_gettext( + 'circ.format.history.csv', + 'Produce CSV of circulation history', + 'ath', + 'description' + ), + FALSE +); + +INSERT INTO action_trigger.event_definition ( + active, owner, name, hook, reactor, validator, group_field, template) +VALUES ( + TRUE, 1, 'Circ History CSV', 'circ.format.history.csv', 'ProcessTemplate', 'NOOP_True', 'usr', +$$ +Title,Author,Call Number,Barcode,Format +[%- +FOR circ IN target; + bibxml = helpers.unapi_bre(circ.target_copy.call_number.record, {flesh => '{mra}'}); + title = ""; + FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]'); + title = title _ part.textContent; + END; + author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent; + item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value') %] + + [%- helpers.csv_datum(title) -%], + [%- helpers.csv_datum(author) -%], + [%- helpers.csv_datum(circ.target_copy.call_number.label) -%], + [%- helpers.csv_datum(circ.target_copy.barcode) -%], + [%- helpers.csv_datum(item_type) %] +[%- END -%] +$$ +); + +INSERT INTO action_trigger.environment (event_def, path) + VALUES ( + currval('action_trigger.event_definition_id_seq'), + 'target_copy.call_number' + ); + +COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.circ_history_export_csv.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.circ_history_export_csv.sql deleted file mode 100644 index 47cad2cdb5..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.circ_history_export_csv.sql +++ /dev/null @@ -1,55 +0,0 @@ - -BEGIN; - -INSERT INTO action_trigger.hook (key, core_type, description, passive) -VALUES ( - 'circ.format.history.csv', - 'circ', - oils_i18n_gettext( - 'circ.format.history.csv', - 'Produce CSV of circulation history', - 'ath', - 'description' - ), - FALSE -); - -INSERT INTO action_trigger.event_definition ( - active, owner, name, hook, reactor, validator, group_field, template) -VALUES ( - TRUE, 1, 'Circ History CSV', 'circ.format.history.csv', 'ProcessTemplate', 'NOOP_True', 'usr', -$$ -Title,Author,Call Number,Barcode,Format -[%- -FOR circ IN target; - bibxml = helpers.unapi_bre(circ.target_copy.call_number.record, {flesh => '{mra}'}); - title = ""; - FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]'); - title = title _ part.textContent; - END; - author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent; - item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value') %] - - [%- helpers.csv_datum(title) -%], - [%- helpers.csv_datum(author) -%], - [%- helpers.csv_datum(circ.target_copy.call_number.label) -%], - [%- helpers.csv_datum(circ.target_copy.barcode) -%], - [%- helpers.csv_datum(item_type) %] -[%- END -%] -$$ -); - -INSERT INTO action_trigger.environment (event_def, path) - VALUES ( - currval('action_trigger.event_definition_id_seq'), - 'target_copy.call_number' - ); - -COMMIT; - -/* UNDO -DELETE FROM action_trigger.event WHERE event_def = ( - SELECT id FROM action_trigger.event_definition WHERE hook = 'circ.format.history.csv'); -DELETE FROM action_trigger.event_definition WHERE hook = 'circ.format.history.csv'); -DELETE FROM action_trigger.hook WHERE key = 'circ.format.history.csv'; -*/