1 -- Evergreen DB patch 0658.schema.acn_dewey_sort_fix.sql
3 -- Fixes Dewey call number sorting (per LP# 902667)
7 -- check whether patch can be applied
8 SELECT evergreen.upgrade_deps_block_check('0658', :eg_version);
10 CREATE OR REPLACE FUNCTION asset.label_normalizer_dewey(TEXT) RETURNS TEXT AS $func$
11 # Derived from the Koha C4::ClassSortRoutine::Dewey module
12 # Copyright (C) 2007 LibLime
13 # Licensed under the GPL v2 or later
22 $init =~ s/^([\p{IsAlpha}]+)/$1 /;
23 my @tokens = split /\.|\s+/, $init;
24 my $digit_group_count = 0;
25 for (my $i = 0; $i <= $#tokens; $i++) {
26 if ($tokens[$i] =~ /^\d+$/) {
28 if (2 == $digit_group_count) {
29 $tokens[$i] = sprintf("%-15.15s", $tokens[$i]);
30 $tokens[$i] =~ tr/ /0/;
34 # Pad the first digit_group if there was only one
35 if (1 == $digit_group_count) {
36 $tokens[0] .= '_000000000000000'
38 my $key = join("_", @tokens);
39 $key =~ s/[^\p{IsAlnum}_]//g;
43 $func$ LANGUAGE PLPERLU;
45 -- regenerate sort keys for any dewey call numbers
46 UPDATE asset.call_number SET id = id WHERE label_class = 2;