]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/version-upgrade/2.3.9-2.3.10-upgrade-db.sql
LP#1772028 Add some FK violation functions just in case they are missing
[Evergreen.git] / Open-ILS / src / sql / Pg / version-upgrade / 2.3.9-2.3.10-upgrade-db.sql
1 --Upgrade Script for 2.3.9 to 2.3.10
2 \set eg_version '''2.3.10'''
3 BEGIN;
4 INSERT INTO config.upgrade_log (version, applied_to) VALUES ('2.3.10', :eg_version);
5
6 SELECT evergreen.upgrade_deps_block_check('0818', :eg_version);
7
8 INSERT INTO config.org_unit_setting_type ( name, grp, label, description, datatype ) VALUES (
9     'circ.patron_edit.duplicate_patron_check_depth', 'circ',
10     oils_i18n_gettext(
11         'circ.patron_edit.duplicate_patron_check_depth',
12         'Specify search depth for the duplicate patron check in the patron editor',
13         'coust',
14         'label'),
15     oils_i18n_gettext(
16         'circ.patron_edit.duplicate_patron_check_depth',
17         'When using the patron registration page, the duplicate patron check will use the configured depth to scope the search for duplicate patrons.',
18         'coust',
19         'description'),
20     'integer')
21 ;
22
23
24
25 -- Evergreen DB patch 0819.schema.acn_dewey_normalizer.sql
26 --
27 -- Fixes Dewey call number sorting (per LP# 1150939)
28 --
29
30 -- check whether patch can be applied
31 SELECT evergreen.upgrade_deps_block_check('0819', :eg_version);
32
33 CREATE OR REPLACE FUNCTION asset.label_normalizer_dewey(TEXT) RETURNS TEXT AS $func$
34     # Derived from the Koha C4::ClassSortRoutine::Dewey module
35     # Copyright (C) 2007 LibLime
36     # Licensed under the GPL v2 or later
37
38     use strict;
39     use warnings;
40
41     my $init = uc(shift);
42     $init =~ s/^\s+//;
43     $init =~ s/\s+$//;
44     $init =~ s!/!!g;
45     $init =~ s/^([\p{IsAlpha}]+)/$1 /;
46     my @tokens = split /\.|\s+/, $init;
47     my $digit_group_count = 0;
48     my $first_digit_group_idx;
49     for (my $i = 0; $i <= $#tokens; $i++) {
50         if ($tokens[$i] =~ /^\d+$/) {
51             $digit_group_count++;
52             if ($digit_group_count == 1) {
53                 $first_digit_group_idx = $i;
54             }
55             if (2 == $digit_group_count) {
56                 $tokens[$i] = sprintf("%-15.15s", $tokens[$i]);
57                 $tokens[$i] =~ tr/ /0/;
58             }
59         }
60     }
61     # Pad the first digit_group if there was only one
62     if (1 == $digit_group_count) {
63         $tokens[$first_digit_group_idx] .= '_000000000000000'
64     }
65     my $key = join("_", @tokens);
66     $key =~ s/[^\p{IsAlnum}_]//g;
67
68     return $key;
69
70 $func$ LANGUAGE PLPERLU;
71
72 -- regenerate sort keys for any dewey call numbers
73 UPDATE asset.call_number SET id = id WHERE label_class = 2;
74
75 COMMIT;