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

(-)a/C4/AuthoritiesMarc.pm (-1 / +20 lines)
Lines 1551-1557 sub merge { Link Here
1551
    my $auth_tag_to_report_to   = $authtypeto ? $authtypeto->auth_tag_to_report : '';
1551
    my $auth_tag_to_report_to   = $authtypeto ? $authtypeto->auth_tag_to_report : '';
1552
1552
1553
    my @record_to;
1553
    my @record_to;
1554
    @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $auth_tag_to_report_to && $MARCto && $MARCto->field($auth_tag_to_report_to);
1554
1555
    my $short_langcode = C4::Context->preference('LanguageToReportOnMerge');
1556
    if ( $auth_tag_to_report_to && $MARCto && $MARCto->field($auth_tag_to_report_to) ) {
1557
        my $chosen_field = $MARCto->field($auth_tag_to_report_to);
1558
        if ($short_langcode) {
1559
            foreach my $field ( $MARCto->field($auth_tag_to_report_to) ) {
1560
                my $subfield = $field->subfield('7');
1561
                if (
1562
                    defined $subfield
1563
                    && (   ( length($subfield) == 2 && $subfield eq $short_langcode )
1564
                        || ( length($subfield) == 8 && substr( $subfield, 4, 2 ) eq $short_langcode ) )
1565
                    )
1566
                {
1567
                    $chosen_field = $field;
1568
                }
1569
            }
1570
        }
1571
        @record_to = $chosen_field->subfields();
1572
    }
1573
1555
    # Exceptional: If MARCto and authtypeto exist but $auth_tag_to_report_to
1574
    # Exceptional: If MARCto and authtypeto exist but $auth_tag_to_report_to
1556
    # is empty, make sure that $9 and $a remain (instead of clearing the
1575
    # is empty, make sure that $9 and $a remain (instead of clearing the
1557
    # reference) in order to allow for data recovery.
1576
    # reference) in order to allow for data recovery.
(-)a/installer/data/mysql/atomicupdate/Bug38142.pl (+18 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "38142",
5
    description => "LanguageToReportOnMerge",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
        $dbh->do(
10
            q{
11
            INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES
12
           ('LanguageToReportOnMerge','','','If set, the authority field having the given language code in its $7 subfield will be reported to the bibliographic record if it exists, rather than the first field. The code can be in a short, 2 characters long form (example: ba for latin) or in a long, 8 characters long form, with the short form in position 5 and 6 starting from 1 (example: ba0yba0y for latin). A list of available codes can be found here: https://documentation.abes.fr/sudoc/formats/unmb/DonneesCodees/CodesZone104.htm#$d','Free');
13
        }
14
        );
15
16
        say $out "Added new syspref 'LanguageToReportOnMerge'";
17
    }
18
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 364-369 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
364
('KohaManualLanguage','en','en|ar|cs|de|es|fr|it|pt_BR|tr|zh_TW','What is the language of the online manual you want to use?','Choice'),
364
('KohaManualLanguage','en','en|ar|cs|de|es|fr|it|pt_BR|tr|zh_TW','What is the language of the online manual you want to use?','Choice'),
365
('LabelMARCView','standard','standard|economical','Define how a MARC record will display','Choice'),
365
('LabelMARCView','standard','standard|economical','Define how a MARC record will display','Choice'),
366
('StaffInterfaceLanguages','en',NULL,'Set the default language in the staff interface.','Languages'),
366
('StaffInterfaceLanguages','en',NULL,'Set the default language in the staff interface.','Languages'),
367
('LanguageToReportOnMerge','',NULL,'If set, the authority field having the given language code in its $7 subfield will be reported to the bibliographic record if it exists, rather than the first field. The code can be in a short, 2 characters long form (example: ba for latin) or in a long, 8 characters long form, with the short form in position 5 and 6 starting from 1 (example: ba0yba0y for latin). A list of available codes can be found here: https://documentation.abes.fr/sudoc/formats/unmb/DonneesCodees/CodesZone104.htm#$d','Free'),
367
('LibraryName','','','Define the library name as displayed on the OPAC',''),
368
('LibraryName','','','Define the library name as displayed on the OPAC',''),
368
('LibraryThingForLibrariesEnabled','0','','Enable or Disable Library Thing for Libraries Features','YesNo'),
369
('LibraryThingForLibrariesEnabled','0','','Enable or Disable Library Thing for Libraries Features','YesNo'),
369
('LibraryThingForLibrariesID','','','See:http://librarything.com/forlibraries/','free'),
370
('LibraryThingForLibrariesID','','','See:http://librarything.com/forlibraries/','free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref (+3 lines)
Lines 95-100 Authorities: Link Here
95
            - Display the MARC field/subfields
95
            - Display the MARC field/subfields
96
            - pref: AdditionalFieldsInZ3950ResultAuthSearch
96
            - pref: AdditionalFieldsInZ3950ResultAuthSearch
97
            - " in the 'Additional fields' column of Z39.50 search results (use comma as delimiter e.g.: \"<code>001, 035$a</code>\")"
97
            - " in the 'Additional fields' column of Z39.50 search results (use comma as delimiter e.g.: \"<code>001, 035$a</code>\")"
98
        -
99
            - "If set, the authority field having the given language code in its $7 subfield will be reported to the bibliographic record if it exists, rather than the first field. The code can be in a short, 2 characters long form (example: ba for latin) or in a long, 8 characters long form, with the short form in position 5 and 6 starting from 1 (example: ba0yba0y for latin). A list of available codes can be found here: https://documentation.abes.fr/sudoc/formats/unmb/DonneesCodees/CodesZone104.htm#$d"
100
            - pref: LanguageToReportOnMerge
98
101
99
    Linker:
102
    Linker:
100
        -
103
        -
(-)a/t/db_dependent/Authority/Merge.t (-2 / +73 lines)
Lines 4-10 Link Here
4
4
5
use Modern::Perl;
5
use Modern::Perl;
6
6
7
use Test::More tests => 12;
7
use Test::More tests => 13;
8
8
9
use Getopt::Long;
9
use Getopt::Long;
10
use MARC::Record;
10
use MARC::Record;
Lines 187-192 subtest 'Test merge A1 to modified A1, test strict mode' => sub { Link Here
187
        # Note: the +1 comes from the added subfield $9 in the biblio
187
        # Note: the +1 comes from the added subfield $9 in the biblio
188
};
188
};
189
189
190
subtest 'Test merge A1 to B1 (choosing language)' => sub {
191
    plan tests => 4;
192
193
    t::lib::Mocks::mock_preference( 'LanguageToReportOnMerge', '' );
194
195
    my $auth1 = MARC::Record->new;
196
    $auth1->append_fields(
197
        MARC::Field->new( '109', '0', '0', 'a' => 'language da', '7' => 'da' ),
198
        MARC::Field->new( '109', '0', '0', 'a' => 'language ba', '7' => 'ba' ),
199
    );
200
    my $authid1 = AddAuthority( $auth1, undef, $authtype1 );
201
202
    my $marc = MARC::Record->new;
203
    $marc->append_fields(
204
        MARC::Field->new( '003', 'some_003' ),
205
        MARC::Field->new( '245', '', '', a => 'My title' ),
206
        MARC::Field->new( '609', '', '', a => 'language ba', '7' => 'ba', 9 => $authid1 ),
207
    );
208
    my ($biblionumber) = C4::Biblio::AddBiblio( $marc, '' );
209
210
    @linkedrecords = ($biblionumber);
211
    C4::AuthoritiesMarc::merge( { mergefrom => $authid1, MARCfrom => $auth1, mergeto => $authid1, MARCto => $auth1 } );
212
    my $biblio = Koha::Biblios->find($biblionumber)->metadata->record;
213
214
    is(
215
        $biblio->subfield( '609', 'a' ), 'language da',
216
        'When LanguageToReportOnMerge is not set, the first authority field is used'
217
    );
218
219
    t::lib::Mocks::mock_preference( 'LanguageToReportOnMerge', 'ba' );
220
    C4::AuthoritiesMarc::merge( { mergefrom => $authid1, MARCfrom => $auth1, mergeto => $authid1, MARCto => $auth1 } );
221
    $biblio = Koha::Biblios->find($biblionumber)->metadata->record;
222
    is(
223
        $biblio->subfield( '609', 'a' ), 'language ba',
224
        'When LanguageToReportOnMerge is set, the field with the matching language is reported'
225
    );
226
227
    t::lib::Mocks::mock_preference( 'LanguageToReportOnMerge', 'xx' );
228
    C4::AuthoritiesMarc::merge( { mergefrom => $authid1, MARCfrom => $auth1, mergeto => $authid1, MARCto => $auth1 } );
229
    $biblio = Koha::Biblios->find($biblionumber)->metadata->record;
230
    is(
231
        $biblio->subfield( '609', 'a' ), 'language da',
232
        'When LanguageToReportOnMerge is set to a value that does not exist in the authority, the first authority field is used'
233
    );
234
235
    # Long form of lang code
236
    t::lib::Mocks::mock_preference( 'LanguageToReportOnMerge', 'ba' );
237
    my $auth2 = MARC::Record->new;
238
    $auth2->append_fields(
239
        MARC::Field->new( '109', '0', '0', 'a' => 'language da (long form)', '7' => 'ba0yda0y' ),
240
        MARC::Field->new( '109', '0', '0', 'a' => 'language ba (long form)', '7' => 'ba0yba0y' ),
241
    );
242
    my $authid2 = AddAuthority( $auth2, undef, $authtype1 );
243
244
    $marc = MARC::Record->new;
245
    $marc->append_fields(
246
        MARC::Field->new( '003', 'some_003' ),
247
        MARC::Field->new( '245', '', '', a => 'My title' ),
248
        MARC::Field->new( '609', '', '', a => 'language ba', '7' => 'ba', 9 => $authid2 ),
249
    );
250
    my ($biblionumber2) = C4::Biblio::AddBiblio( $marc, '' );
251
252
    @linkedrecords = ($biblionumber2);
253
    C4::AuthoritiesMarc::merge( { mergefrom => $authid2, MARCfrom => $auth2, mergeto => $authid2, MARCto => $auth2 } );
254
    my $biblio2 = Koha::Biblios->find($biblionumber2)->metadata->record;
255
    is(
256
        $biblio2->subfield( '609', 'a' ), 'language ba (long form)',
257
        'When LanguageToReportOnMerge is set, the field with the matching language in its long form is reported'
258
    );
259
260
};
261
190
subtest 'Test merge A1 to B1 (changing authtype)' => sub {
262
subtest 'Test merge A1 to B1 (changing authtype)' => sub {
191
# Tests were aimed for bug 9988, moved to 17909 in adjusted form
263
# Tests were aimed for bug 9988, moved to 17909 in adjusted form
192
# Would not encourage this type of merge, but we should test what we offer
264
# Would not encourage this type of merge, but we should test what we offer
193
- 

Return to bug 38142