View | Details | Raw Unified | Return to bug 19096
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/bug19096.perl (+94 lines)
Line 0 Link Here
1
$DBversion = 'XXX';  # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
4
    my $dbh = C4::Context->dbh;
5
6
    my $msss = $dbh->selectall_arrayref(q|
7
        SELECT kohafield, tagfield, tagsubfield, frameworkcode
8
        FROM marc_subfield_structure
9
        WHERE   frameworkcode != ''
10
    |, { Slice => {} });
11
12
13
    my $sth = $dbh->prepare(q|
14
        SELECT kohafield
15
        FROM marc_subfield_structure
16
        WHERE frameworkcode = ''
17
        AND tagfield = ?
18
        AND tagsubfield = ?
19
    |);
20
21
    my @exceptions;
22
    for my $mss ( @$msss ) {
23
        $sth->execute($mss->{tagfield}, $mss->{tagsubfield} );
24
        my ( $default_kohafield ) = $sth->fetchrow_array();
25
        if( $mss->{kohafield} ) {
26
            push @exceptions, { frameworkcode => $mss->{frameworkcode}, tagfield => $mss->{tagfield}, tagsubfield => $mss->{tagsubfield}, kohafield => $mss->{kohafield} } if not $default_kohafield or $default_kohafield ne $mss->{kohafield};
27
        } else {
28
            push @exceptions, { frameworkcode => $mss->{frameworkcode}, tagfield => $mss->{tagfield}, tagsubfield => $mss->{tagsubfield}, kohafield => q{} } if $default_kohafield;
29
        }
30
    }
31
32
    if (@exceptions) {
33
        print
34
"WARNING: The Default framework is now considered as authoritative for Koha to MARC mappings. We have found that your additional frameworks contained "
35
          . scalar(@exceptions)
36
          . " mapping(s) that deviate from the standard mappings. Please look at the following list and consider if you need to add them again in Default (possibly as a second mapping).\n";
37
        for my $exception (@exceptions) {
38
            print "Field "
39
              . $exception->{tagfield} . '$'
40
              . $exception->{tagsubfield}
41
              . " in framework "
42
              . $exception->{frameworkcode} . ': ';
43
            if ( $exception->{kohafield} ) {
44
                print "Mapping to "
45
                  . $exception->{kohafield}
46
                  . " has been adjusted.\n";
47
            }
48
            else {
49
                print "Mapping has been reset.\n";
50
            }
51
        }
52
53
        # Sync kohafield
54
55
        # Clear the destination frameworks first
56
        $dbh->do(q|
57
            UPDATE marc_subfield_structure
58
            SET kohafield = NULL
59
            WHERE   frameworkcode > ''
60
                AND     Kohafield > ''
61
        |);
62
63
        # Now copy from Default
64
        my $msss = $dbh->selectall_arrayref(q|
65
            SELECT kohafield, tagfield, tagsubfield
66
            FROM marc_subfield_structure
67
            WHERE   frameworkcode = ''
68
                AND     kohafield > ''
69
        |, { Slice => {} });
70
        my $sth = $dbh->prepare(q|
71
            UPDATE marc_subfield_structure
72
            SET kohafield = ?
73
            WHERE frameworkcode > ''
74
            AND tagfield = ?
75
            AND tagsubfield = ?
76
        |);
77
        for my $mss (@$msss) {
78
            $sth->execute( $mss->{kohafield}, $mss->{tagfield},
79
                $mss->{tagsubfield} );
80
        }
81
82
        # Clear the cache
83
        my @frameworkcodes = $dbh->selectall_arrayref(q|
84
            SELECT frameworkcode FROM biblio_framework WHERE frameworkcode > ''
85
        |);
86
        for my $frameworkcode (@frameworkcodes) {
87
            Koha::Caches->get_instance->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
88
        }
89
        Koha::Caches->get_instance->clear_from_cache("default_value_for_mod_marc-");
90
    }
91
92
    SetVersion( $DBversion );
93
    print "Upgrade to $DBversion done (Bug 19096 - Make Default authoritative for Koha to MARC mappings)\n";
94
}
(-)a/t/db_dependent/Koha/MarcSubfieldStructures.t (-2 lines)
Lines 21-27 use Modern::Perl; Link Here
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 1;
23
23
24
use Koha::MarcSubfieldStructure;
25
use Koha::MarcSubfieldStructures;
24
use Koha::MarcSubfieldStructures;
26
use Koha::Database;
25
use Koha::Database;
27
26
28
- 

Return to bug 19096