Add pub date to CSV output.
authorJason Stephenson <jstephenson@mvlc.org>
Fri, 27 Jul 2012 13:25:05 +0000 (09:25 -0400)
committerDan Scott <dscott@laurentian.ca>
Sun, 2 Sep 2012 03:32:11 +0000 (23:32 -0400)
Change the template for the ContainerCSV reactor to add the publication
date (MARC 260$c) in the csv output in the same position that the previous
commit adds it to the html output.

Add an upgrade script to update the existing template for the ContainerCSV
reactor in action_trigger.event_definition.

Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Dan Scott <dscott@laurentian.ca>

Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.update_ContainerCSV_template.sql [new file with mode: 0644]

index 41eb5fe..e5daf85 100644 (file)
@@ -9989,8 +9989,15 @@ FOR item IN items;
     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(item_type) %],[% FOR note IN item.notes; helpers.csv_datum(note.note); ","; END; "\n";
+    pub_date = "";
+    FOR pdatum IN bibxml.findnodes('//*[@tag="260"]/*[@code="c"]');
+        IF pub_date ;
+            pub_date = pub_date _ ", " _ pdatum.textContent;
+        ELSE ;
+            pub_date = pdatum.textContent;
+        END;
+    END;
+    helpers.csv_datum(title) %],[% helpers.csv_datum(author) %],[% helpers.csv_datum(pub_date) %],[% helpers.csv_datum(item_type) %],[% FOR note IN item.notes; helpers.csv_datum(note.note); ","; END; "\n";
 END -%]
 $$
 );
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.update_ContainerCSV_template.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.update_ContainerCSV_template.sql
new file mode 100644 (file)
index 0000000..5af0feb
--- /dev/null
@@ -0,0 +1,33 @@
+BEGIN;
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+UPDATE action_trigger.event_definition
+SET template =
+$$
+[%-
+# target is the bookbag itself. The 'items' variable does not need to be in
+# the environment because a special reactor will take care of filling it in.
+
+FOR item IN items;
+    bibxml = helpers.unapi_bre(item.target_biblio_record_entry, {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');
+    pub_date = "";
+    FOR pdatum IN bibxml.findnodes('//*[@tag="260"]/*[@code="c"]');
+        IF pub_date ;
+            pub_date = pub_date _ ", " _ pdatum.textContent;
+        ELSE ;
+            pub_date = pdatum.textContent;
+        END;
+    END;
+    helpers.csv_datum(title) %],[% helpers.csv_datum(author) %],[% helpers.csv_datum(pub_date) %],[% helpers.csv_datum(item_type) %],[% FOR note IN item.notes; helpers.csv_datum(note.note); ","; END; "\n";
+END -%]
+$$
+WHERE id = 48;
+
+COMMIT;