]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0499.schema.generic_CN_normalizer.sql
LP#1426133: Set merge_profile_id_seq explicitly
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0499.schema.generic_CN_normalizer.sql
1 BEGIN;
2
3 INSERT INTO config.upgrade_log (version) VALUES ('0499'); -- miker for Steve Callendar
4
5 CREATE OR REPLACE FUNCTION asset.label_normalizer_generic(TEXT) RETURNS TEXT AS $func$
6     # Created after looking at the Koha C4::ClassSortRoutine::Generic module,
7     # thus could probably be considered a derived work, although nothing was
8     # directly copied - but to err on the safe side of providing attribution:
9     # Copyright (C) 2007 LibLime
10     # Copyright (C) 2011 Equinox Software, Inc (Steve Callendar)
11     # Licensed under the GPL v2 or later
12
13     use strict;
14     use warnings;
15
16     # Converts the callnumber to uppercase
17     # Strips spaces from start and end of the call number
18     # Converts anything other than letters, digits, and periods into spaces
19     # Collapses multiple spaces into a single underscore
20     my $callnum = uc(shift);
21     $callnum =~ s/^\s//g;
22     $callnum =~ s/\s$//g;
23     # NOTE: this previously used underscores, but this caused sorting issues
24     # for the "before" half of page 0 on CN browse, sorting CNs containing a
25     # decimal before "whole number" CNs
26     $callnum =~ s/[^A-Z0-9_.]/ /g;
27     $callnum =~ s/ {2,}/ /g;
28
29     return $callnum;
30 $func$ LANGUAGE PLPERLU;
31
32 UPDATE asset.call_number SET id = id;
33
34 COMMIT;
35