From: miker Date: Mon, 8 Nov 2010 16:34:11 +0000 (+0000) Subject: keep trunk version of the 2.0 upgrade script in sync ... for now X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=bd50670648d5e3141094827181cd1ec2953bd2e8;p=evergreen%2Fbjwebb.git keep trunk version of the 2.0 upgrade script in sync ... for now git-svn-id: svn://svn.open-ils.org/ILS/trunk@18656 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql index 270fe407d..64c774a7d 100644 --- a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql +++ b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql @@ -23,7 +23,7 @@ BEGIN; -- Highest-numbered individual upgrade script incorporated herein: -INSERT INTO config.upgrade_log (version) VALUES ('0453'); +INSERT INTO config.upgrade_log (version) VALUES ('0461'); -- Remove some uses of the connectby() function from the tablefunc contrib module CREATE OR REPLACE FUNCTION actor.org_unit_descendants( INT, INT ) RETURNS SETOF actor.org_unit AS $$ @@ -3850,6 +3850,132 @@ $$ $$ ); +UPDATE action_trigger.event_definition SET template = $$[% FILTER collapse %] +[%- SET invoice = target -%] + +
+

Invoice

+
+ No. [% invoice.inv_ident %] + [% IF invoice.inv_type %] + / Type:[% invoice.inv_type %] + [% END %] +
+
+
+ [% BLOCK ent_with_address %] +
[% ent_label %]: [% ent.name %] ([% ent.code %])
+
+ [% IF ent.addresses.0 %] + [% SET addr = ent.addresses.0 %] + [% addr.street1 %]
+ [% IF addr.street2 %][% addr.street2 %]
[% END %] + [% addr.city %], + [% IF addr.county %] [% addr.county %], [% END %] + [% IF addr.state %] [% addr.state %] [% END %] + [% IF addr.post_code %][% addr.post_code %][% END %]
+ [% IF addr.country %] [% addr.country %] [% END %] + [% END %] +

+ [% IF ent.phone %] Phone: [% ent.phone %]
[% END %] + [% IF ent.fax_phone %] Fax: [% ent.fax_phone %]
[% END %] + [% IF ent.url %] URL: [% ent.url %]
[% END %] + [% IF ent.email %] E-mail: [% ent.email %] [% END %] +

+
+ [% END %] + [% INCLUDE ent_with_address + ent = invoice.provider + ent_label = "Provider" %] + [% INCLUDE ent_with_address + ent = invoice.shipper + ent_label = "Shipper" %] +
Receiver
+
+ [% invoice.receiver.name %] ([% invoice.receiver.shortname %]) +
+
Received
+
+ [% helpers.format_date(invoice.recv_date) %] by + [% invoice.recv_method %] +
+ [% IF invoice.note %] +
Note
+
+ [% invoice.note %] +
+ [% END %] +
+
+ +
+ Amounts spent per fund: + + [% FOR blob IN user_data %] + + + + + [% END %] +
[% blob.fund.code %] ([% blob.fund.year %]):$[% blob.total %]
+
+
+[% END %]$$ WHERE id = 22; INSERT INTO action_trigger.environment (event_def, path) VALUES (22, 'provider'), (22, 'provider.addresses'), @@ -13939,7 +14065,7 @@ INSERT INTO acq.cancel_reason ( id, org_unit, label, description ) VALUES ( INSERT INTO acq.cancel_reason ( id, org_unit, label, description ) VALUES ( 2, 1, 'postpone', oils_i18n_gettext( 2, 'Title has been postponed', 'acqcr', 'label' )); -CREATE OR REPLACE FUNCTION vandelay.add_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$ +CREATE OR REPLACE FUNCTION vandelay.add_field ( target_xml TEXT, source_xml TEXT, field TEXT, force_add INT ) RETURNS TEXT AS $_$ use MARC::Record; use MARC::File::XML (BinaryEncoding => 'UTF-8'); @@ -13948,6 +14074,7 @@ CREATE OR REPLACE FUNCTION vandelay.add_field ( target_xml TEXT, source_xml TEXT my $target_xml = shift; my $source_xml = shift; my $field_spec = shift; + my $force_add = shift || 0; my $target_r = MARC::Record->new_from_xml( $target_xml ); my $source_r = MARC::Record->new_from_xml( $source_xml ); @@ -13983,7 +14110,7 @@ CREATE OR REPLACE FUNCTION vandelay.add_field ( target_xml TEXT, source_xml TEXT for my $from_field ($source_r->field( $f )) { my @tos = $target_r->field( $f ); if (!@tos) { - next if (exists($fields{$f}{match})); + next if (exists($fields{$f}{match}) and !$force_add); my @new_fields = map { $_->clone } $source_r->field( $f ); $target_r->insert_fields_ordered( @new_fields ); } else { @@ -14011,6 +14138,10 @@ CREATE OR REPLACE FUNCTION vandelay.add_field ( target_xml TEXT, source_xml TEXT $_$ LANGUAGE PLPERLU; +CREATE OR REPLACE FUNCTION vandelay.add_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$ + SELECT vandelay.add_field( $1, $2 $3, 0 ); +$_$ LANGUAGE SQL; + CREATE OR REPLACE FUNCTION vandelay.strip_field ( xml TEXT, field TEXT ) RETURNS TEXT AS $_$ use MARC::Record; @@ -14071,8 +14202,22 @@ CREATE OR REPLACE FUNCTION vandelay.strip_field ( xml TEXT, field TEXT ) RETURNS $_$ LANGUAGE PLPERLU; CREATE OR REPLACE FUNCTION vandelay.replace_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$ - SELECT vandelay.add_field( vandelay.strip_field( $1, $3), $2, $3 ); -$_$ LANGUAGE SQL; +DECLARE + xml_output TEXT; +BEGIN + xml_output := vandelay.strip_field( target_xml, field); + + IF xml_output <> target_xml AND field ~ E'~' THEN + -- we removed something, and there was a regexp restriction in the field definition, so proceed + xml_output := vandelay.add_field( xml_output, source_xml, field, 1 ); + ELSIF field !~ E'~' THEN + -- No regexp restriction, add the field + xml_output := vandelay.add_field( xml_output, source_xml, field, 0 ); + END IF; + + RETURN xml_output; +END; +$_$ LANGUAGE PLPGSQL; CREATE OR REPLACE FUNCTION vandelay.preserve_field ( incumbent_xml TEXT, incoming_xml TEXT, field TEXT ) RETURNS TEXT AS $_$ SELECT vandelay.add_field( vandelay.strip_field( $2, $3), $1, $3 ); @@ -14750,64 +14895,64 @@ CREATE TABLE acq.claim_policy_action ( CREATE OR REPLACE FUNCTION public.ingest_acq_marc ( ) RETURNS TRIGGER AS $function$ DECLARE - value TEXT; - atype TEXT; - prov INT; - pos INT; - adef RECORD; - xpath_string TEXT; + value TEXT; + atype TEXT; + prov INT; + pos INT; + adef RECORD; + xpath_string TEXT; BEGIN - FOR adef IN SELECT *,tableoid FROM acq.lineitem_attr_definition LOOP - - SELECT relname::TEXT INTO atype FROM pg_class WHERE oid = adef.tableoid; - - IF (atype NOT IN ('lineitem_usr_attr_definition','lineitem_local_attr_definition')) THEN - IF (atype = 'lineitem_provider_attr_definition') THEN - SELECT provider INTO prov FROM acq.lineitem_provider_attr_definition WHERE id = adef.id; - CONTINUE WHEN NEW.provider IS NULL OR prov <> NEW.provider; - END IF; - - IF (atype = 'lineitem_provider_attr_definition') THEN - SELECT xpath INTO xpath_string FROM acq.lineitem_provider_attr_definition WHERE id = adef.id; - ELSIF (atype = 'lineitem_marc_attr_definition') THEN - SELECT xpath INTO xpath_string FROM acq.lineitem_marc_attr_definition WHERE id = adef.id; - ELSIF (atype = 'lineitem_generated_attr_definition') THEN - SELECT xpath INTO xpath_string FROM acq.lineitem_generated_attr_definition WHERE id = adef.id; - END IF; - + FOR adef IN SELECT *,tableoid FROM acq.lineitem_attr_definition LOOP + + SELECT relname::TEXT INTO atype FROM pg_class WHERE oid = adef.tableoid; + + IF (atype NOT IN ('lineitem_usr_attr_definition','lineitem_local_attr_definition')) THEN + IF (atype = 'lineitem_provider_attr_definition') THEN + SELECT provider INTO prov FROM acq.lineitem_provider_attr_definition WHERE id = adef.id; + CONTINUE WHEN NEW.provider IS NULL OR prov <> NEW.provider; + END IF; + + IF (atype = 'lineitem_provider_attr_definition') THEN + SELECT xpath INTO xpath_string FROM acq.lineitem_provider_attr_definition WHERE id = adef.id; + ELSIF (atype = 'lineitem_marc_attr_definition') THEN + SELECT xpath INTO xpath_string FROM acq.lineitem_marc_attr_definition WHERE id = adef.id; + ELSIF (atype = 'lineitem_generated_attr_definition') THEN + SELECT xpath INTO xpath_string FROM acq.lineitem_generated_attr_definition WHERE id = adef.id; + END IF; + xpath_string := REGEXP_REPLACE(xpath_string,$re$//?text\(\)$$re$,''); IF (adef.code = 'title' OR adef.code = 'author') THEN -- title and author should not be split -- FIXME: once oils_xpath can grok XPATH 2.0 functions, we can use -- string-join in the xpath and remove this special case - SELECT extract_acq_marc_field(id, xpath_string, adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id; - IF (value IS NOT NULL AND value <> '') THEN - INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value) - VALUES (NEW.id, adef.id, atype, adef.code, value); + SELECT extract_acq_marc_field(id, xpath_string, adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id; + IF (value IS NOT NULL AND value <> '') THEN + INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value) + VALUES (NEW.id, adef.id, atype, adef.code, value); END IF; ELSE pos := 1; LOOP - SELECT extract_acq_marc_field(id, xpath_string || '[' || pos || ']', adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id; - - IF (value IS NOT NULL AND value <> '') THEN - INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value) - VALUES (NEW.id, adef.id, atype, adef.code, value); + SELECT extract_acq_marc_field(id, xpath_string || '[' || pos || ']', adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id; + + IF (value IS NOT NULL AND value <> '') THEN + INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value) + VALUES (NEW.id, adef.id, atype, adef.code, value); ELSE EXIT; - END IF; + END IF; pos := pos + 1; END LOOP; END IF; - END IF; + END IF; - END LOOP; + END LOOP; - RETURN NULL; + RETURN NULL; END; $function$ LANGUAGE PLPGSQL; @@ -17149,24 +17294,16 @@ DECLARE bib_id INT := 0; bib_rec biblio.record_entry%ROWTYPE; auth_link authority.bib_linking%ROWTYPE; + ingest_same boolean; BEGIN - -- 1. Make source_record MARC a copy of the target_record to get auto-sync in linked bib records - UPDATE authority.record_entry - SET marc = ( - SELECT marc - FROM authority.record_entry - WHERE id = target_record - ) - WHERE id = source_record; - - -- 2. Update all bib records with the ID from target_record in their $0 - FOR bib_rec IN SELECT bre.* FROM biblio.record_entry bre + -- 1. Update all bib records with the ID from target_record in their $0 + FOR bib_rec IN SELECT bre.* FROM biblio.record_entry bre INNER JOIN authority.bib_linking abl ON abl.bib = bre.id - WHERE abl.authority = target_record LOOP + WHERE abl.authority = source_record LOOP UPDATE biblio.record_entry - SET marc = REGEXP_REPLACE(marc, + SET marc = REGEXP_REPLACE(marc, E'([^<]*?\\))' || source_record || '<', E'\\1' || target_record || '<', 'g') WHERE id = bib_rec.id; @@ -17174,10 +17311,34 @@ BEGIN moved_objects := moved_objects + 1; END LOOP; - -- 3. "Delete" source_record + -- 2. Grab the current value of reingest on same MARC flag + SELECT enabled INTO ingest_same + FROM config.internal_flag + WHERE name = 'ingest.reingest.force_on_same_marc' + ; + + -- 3. Temporarily set reingest on same to TRUE + UPDATE config.internal_flag + SET enabled = TRUE + WHERE name = 'ingest.reingest.force_on_same_marc' + ; + + -- 4. Make a harmless update to target_record to trigger auto-update + -- in linked bibliographic records + UPDATE authority.record_entry + SET DELETED = FALSE + WHERE id = source_record; + + -- 5. "Delete" source_record DELETE FROM authority.record_entry WHERE id = source_record; + -- 6. Set "reingest on same MARC" flag back to initial value + UPDATE config.internal_flag + SET enabled = ingest_same + WHERE name = 'ingest.reingest.force_on_same_marc' + ; + RETURN moved_objects; END; $func$ LANGUAGE plpgsql; @@ -18733,7 +18894,7 @@ INSERT INTO acq.lineitem_marc_attr_definition ( code, description, xpath, remove SELECT 'upc', 'UPC', '//*[@tag="024" and @ind1="1"]/*[@code="a"]', $r$(?:-|\s.+$)$r$ WHERE NOT EXISTS ( SELECT 1 FROM acq.lineitem_marc_attr_definition WHERE code = 'upc' -); +); COMMIT; @@ -18863,4 +19024,3 @@ INSERT INTO action_trigger.event_definition ( \qecho Upgrade script completed. -