From: dbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4> Date: Sun, 28 Nov 2010 15:11:55 +0000 (+0000) Subject: Address 1.6.1-2.0 upgrade problems reported by Ben Shum X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=275e69c67d1ba9b3f539a4eca0ad65b702ca693f;p=evergreen%2Fmasslnc.git Address 1.6.1-2.0 upgrade problems reported by Ben Shum 1. We were attempting to update the asset.uri ID sequence value with the wrong syntax; also, adding just 1 would return an error in the event that only the seed value for asset.uri had been inserted. 2. Somehow the body of the maintain_control_numbers() function was pasted twice, resulting in a syntax error. git-svn-id: svn://svn.open-ils.org/ILS/trunk@18850 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 5dae9d7ef1..16139edbda 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 @@ -19,6 +19,10 @@ ALTER TABLE permission.usr_object_perm_map DROP CONSTRAINT usr_object_perm_map_p ALTER TABLE booking.resource_type DROP CONSTRAINT brt_name_or_record_once_per_owner; ALTER TABLE booking.resource_type DROP CONSTRAINT brt_name_once_per_owner; +\qecho Before starting the transaction: create seed data for the asset.uri table +\qecho If the INSERT fails because the -1 value already exists, ignore the failure. +INSERT INTO asset.uri (id, href, active) VALUES (-1, 'http://example.com/fake', FALSE); + \qecho Beginning the transaction now BEGIN; @@ -29,8 +33,9 @@ UPDATE biblio.record_entry SET marc = '<record xmlns="http://www.loc.gov/MARC21/ INSERT INTO config.upgrade_log (version) VALUES ('0461'); --- Push the auri serial in case it's out of date -SELECT SETVAL('asset.uri'::TEXT, (SELECT MAX(id) + 1 FROM asset.uri)); +-- Push the auri sequence in case it's out of date +-- Add 2 as the sequence value must be 1 or higher, and seed is -1 +SELECT SETVAL('asset.uri_id_seq'::TEXT, (SELECT MAX(id) + 2 FROM asset.uri)); -- 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 $$ @@ -17055,122 +17060,6 @@ if ($create or $munge) { return "MODIFY"; } -CREATE OR REPLACE FUNCTION maintain_control_numbers() RETURNS TRIGGER AS $func$ -use strict; -use MARC::Record; -use MARC::File::XML (BinaryEncoding => 'UTF-8'); -use Encode; -use Unicode::Normalize; - -my $record = MARC::Record->new_from_xml($_TD->{new}{marc}); -my $schema = $_TD->{table_schema}; -my $rec_id = $_TD->{new}{id}; - -# Short-circuit if maintaining control numbers per MARC21 spec is not enabled -my $enable = spi_exec_query("SELECT enabled FROM config.global_flag WHERE name = 'cat.maintain_control_numbers'"); -if (!($enable->{processed}) or $enable->{rows}[0]->{enabled} eq 'f') { - return; -} - -# Get the control number identifier from an OU setting based on $_TD->{new}{owner} -my $ou_cni = 'EVRGRN'; - -my $owner; -if ($schema eq 'serial') { - $owner = $_TD->{new}{owning_lib}; -} else { - # are.owner and bre.owner can be null, so fall back to the consortial setting - $owner = $_TD->{new}{owner} || 1; -} - -my $ous_rv = spi_exec_query("SELECT value FROM actor.org_unit_ancestor_setting('cat.marc_control_number_identifier', $owner)"); -if ($ous_rv->{processed}) { - $ou_cni = $ous_rv->{rows}[0]->{value}; - $ou_cni =~ s/"//g; # Stupid VIM syntax highlighting" -} else { - # Fall back to the shortname of the OU if there was no OU setting - $ous_rv = spi_exec_query("SELECT shortname FROM actor.org_unit WHERE id = $owner"); - if ($ous_rv->{processed}) { - $ou_cni = $ous_rv->{rows}[0]->{shortname}; - } -} - -my ($create, $munge) = (0, 0); - -my @scns = $record->field('035'); - -foreach my $id_field ('001', '003') { - my $spec_value; - my @controls = $record->field($id_field); - - if ($id_field eq '001') { - $spec_value = $rec_id; - } else { - $spec_value = $ou_cni; - } - - # Create the 001/003 if none exist - if (scalar(@controls) == 1) { - # Only one field; check to see if we need to munge it - unless (grep $_->data() eq $spec_value, @controls) { - $munge = 1; - } - } else { - # Delete the other fields, as with more than 1 001/003 we do not know which 003/001 to match - foreach my $control (@controls) { - unless ($control->data() eq $spec_value) { - $record->delete_field($control); - } - } - $record->insert_fields_ordered(MARC::Field->new($id_field, $spec_value)); - $create = 1; - } -} - -# Now, if we need to munge the 001, we will first push the existing 001/003 -# into the 035; but if the record did not have one (and one only) 001 and 003 -# to begin with, skip this process -if ($munge and not $create) { - my $scn = "(" . $record->field('003')->data() . ")" . $record->field('001')->data(); - - # Do not create duplicate 035 fields - unless (grep $_->subfield('a') eq $scn, @scns) { - $record->insert_fields_ordered(MARC::Field->new('035', '', '', 'a' => $scn)); - } -} - -# Set the 001/003 and update the MARC -if ($create or $munge) { - $record->field('001')->data($rec_id); - $record->field('003')->data($ou_cni); - - my $xml = $record->as_xml_record(); - $xml =~ s/\n//sgo; - $xml =~ s/^<\?xml.+\?\s*>//go; - $xml =~ s/>\s+</></go; - $xml =~ s/\p{Cc}//go; - - # Embed a version of OpenILS::Application::AppUtils->entityize() - # to avoid having to set PERL5LIB for PostgreSQL as well - - # If we are going to convert non-ASCII characters to XML entities, - # we had better be dealing with a UTF8 string to begin with - $xml = decode_utf8($xml); - - $xml = NFC($xml); - - # Convert raw ampersands to entities - $xml =~ s/&(?!\S+;)/&/gso; - - # Convert Unicode characters to entities - $xml =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe; - - $xml =~ s/[\x00-\x1f]//go; - $_TD->{new}{marc} = $xml; - - return "MODIFY"; -} - return; $func$ LANGUAGE PLPERLU;