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

(-)a/C4/Biblio.pm (-8 / +63 lines)
Lines 3420-3434 sub ModBiblioMarc { Link Here
3420
        format       => 'marcxml',
3420
        format       => 'marcxml',
3421
        marcflavour  => C4::Context->preference('marcflavour'),
3421
        marcflavour  => C4::Context->preference('marcflavour'),
3422
    };
3422
    };
3423
    # FIXME To replace with ->find_or_create?
3423
3424
    if ( my $m_rs = Koha::Biblio::Metadatas->find($metadata) ) {
3424
    my $m_rs = Koha::Biblio::Metadatas->find($metadata);
3425
        $m_rs->metadata( $record->as_xml_record($encoding) );
3425
    unless ($m_rs) {
3426
        $m_rs->store;
3426
        $m_rs = Koha::Biblio::Metadata->new($metadata);
3427
    } else {
3427
    }
3428
        my $m_rs = Koha::Biblio::Metadata->new($metadata);
3428
3429
        $m_rs->metadata( $record->as_xml_record($encoding) );
3429
    my $userenv = C4::Context->userenv;
3430
        $m_rs->store;
3430
    if ($userenv) {
3431
        my $borrowernumber = $userenv->{number};
3432
        my $borrowername = join ' ', @$userenv{qw(firstname surname)};
3433
        unless ($m_rs->in_storage) {
3434
            _set_marc_field($record, C4::Context->preference('MarcFieldForCreatorId'), $borrowernumber);
3435
            _set_marc_field($record, C4::Context->preference('MarcFieldForCreatorName'), $borrowername);
3436
        }
3437
        _set_marc_field($record, C4::Context->preference('MarcFieldForModifierId'), $borrowernumber);
3438
        _set_marc_field($record, C4::Context->preference('MarcFieldForModifierName'), $borrowername);
3431
    }
3439
    }
3440
3441
    $m_rs->metadata( $record->as_xml_record($encoding) );
3442
    $m_rs->store;
3443
3432
    ModZebra( $biblionumber, "specialUpdate", "biblioserver", $record );
3444
    ModZebra( $biblionumber, "specialUpdate", "biblioserver", $record );
3433
    return $biblionumber;
3445
    return $biblionumber;
3434
}
3446
}
Lines 3683-3688 sub RemoveAllNsb { Link Here
3683
    return $record;
3695
    return $record;
3684
}
3696
}
3685
3697
3698
=head2 _set_marc_field
3699
3700
    _set_marc_field($record, $marcField, $value);
3701
3702
Set the value of $marcField to $value in $record
3703
3704
=head3 Parameters
3705
3706
=over 4
3707
3708
=item C<$record>
3709
3710
MARC::Record object
3711
3712
=item C<$marcField>
3713
3714
the MARC field to modify, a string in the form of 'XXX$y'
3715
3716
=item C<$value>
3717
3718
the value
3719
3720
=back
3721
3722
=cut
3723
3724
sub _set_marc_field {
3725
    my ($record, $marcField, $value) = @_;
3726
3727
    if ($marcField) {
3728
        my ($fieldTag, $subfieldCode) = split /\$/, $marcField;
3729
        my $field = $record->field($fieldTag);
3730
        if ($field) {
3731
            $field->update($subfieldCode => $value);
3732
        } else {
3733
            $field = MARC::Field->new($fieldTag, ' ', ' ',
3734
                $subfieldCode => $value);
3735
            $record->append_fields($field);
3736
        }
3737
    }
3738
}
3739
3740
3686
1;
3741
1;
3687
3742
3688
3743
(-)a/installer/data/mysql/atomicupdate/bug_19349.perl (+13 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{
4
        INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES
5
        ('MarcFieldForCreatorId','',NULL,'Where to store the borrowernumber of the record''s creator','Free'),
6
        ('MarcFieldForCreatorName','',NULL,'Where to store the name of the record''s creator','Free'),
7
        ('MarcFieldForModifierId','',NULL,'Where to store the borrowernumber of the record''s last modifier','Free'),
8
        ('MarcFieldForModifierName','',NULL,'Where to store the name of the record''s last modifier','Free')
9
    });
10
11
    SetVersion( $DBversion );
12
    print "Upgrade to $DBversion done (Bug 19349 - Add system preferences MarcFieldForCreatorId, MarcFieldForCreatorName, MarcFieldForModifierId, MarcFieldForModifierName)\n";
13
}
(-)a/installer/data/mysql/sysprefs.sql (+4 lines)
Lines 253-258 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
253
('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'),
253
('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'),
254
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
254
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
255
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
255
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
256
('MarcFieldForCreatorId','',NULL,'Where to store the borrowernumber of the record''s creator','Free'),
257
('MarcFieldForCreatorName','',NULL,'Where to store the name of the record''s creator','Free'),
258
('MarcFieldForModifierId','',NULL,'Where to store the borrowernumber of the record''s last modifier','Free'),
259
('MarcFieldForModifierName','',NULL,'Where to store the name of the record''s last modifier','Free'),
256
('MarcFieldsToOrder','',NULL,'Set the mapping values for a new order line created from a MARC record in a staged file. In a YAML format.','textarea'),
260
('MarcFieldsToOrder','',NULL,'Set the mapping values for a new order line created from a MARC record in a staged file. In a YAML format.','textarea'),
257
('MarcItemFieldsToOrder','',NULL,'Set the mapping values for new item records created from a MARC record in a staged file. In a YAML format.','textarea'),
261
('MarcItemFieldsToOrder','',NULL,'Set the mapping values for new item records created from a MARC record in a staged file. In a YAML format.','textarea'),
258
('MARCOrgCode','OSt','','Define MARC Organization Code for MARC21 records - http://www.loc.gov/marc/organizations/orgshome.html','free'),
262
('MARCOrgCode','OSt','','Define MARC Organization Code for MARC21 records - http://www.loc.gov/marc/organizations/orgshome.html','free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (+10 lines)
Lines 129-134 Cataloging: Link Here
129
            - 'MARC21: "952$a 952$b 952$c"'
129
            - 'MARC21: "952$a 952$b 952$c"'
130
            - Note that the FA framework is excluded from the permission.
130
            - Note that the FA framework is excluded from the permission.
131
            - If the pref is empty, no fields are restricted.
131
            - If the pref is empty, no fields are restricted.
132
        -
133
            - Store record's creator borrowernumber in MARC subfield
134
            - pref: MarcFieldForCreatorId
135
            - and record's creator name in MARC subfield
136
            - pref: MarcFieldForCreatorName
137
        -
138
            - Store record's last modifier borrowernumber in MARC subfield
139
            - pref: MarcFieldForModifierId
140
            - and record's last modifier name in MARC subfield
141
            - pref: MarcFieldForModifierName
132
    Display:
142
    Display:
133
        -
143
        -
134
            - 'Separate multiple displayed authors, series or subjects with '
144
            - 'Separate multiple displayed authors, series or subjects with '
(-)a/t/db_dependent/Biblio.t (-2 / +49 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 7;
20
use Test::More tests => 9;
21
use Test::MockModule;
21
use Test::MockModule;
22
22
23
use List::MoreUtils qw( uniq );
23
use List::MoreUtils qw( uniq );
Lines 391-393 subtest 'deletedbiblio_metadata' => sub { Link Here
391
    is( $moved, $biblionumber, 'Found in deletedbiblio_metadata' );
391
    is( $moved, $biblionumber, 'Found in deletedbiblio_metadata' );
392
};
392
};
393
393
394
- 
394
subtest '_set_marc_field' => sub {
395
    plan tests => 6;
396
397
    my $record = MARC::Record->new();
398
399
    C4::Biblio::_set_marc_field($record, '999$9', 'foobar');
400
    my @fields = $record->field('999');
401
    is(scalar @fields, 1, 'Created one field');
402
    my @subfields = $fields[0]->subfield('9');
403
    is(scalar @subfields, 1, 'Created one subfield');
404
    is($subfields[0], 'foobar', 'Created subfield has correct value');
405
406
    C4::Biblio::_set_marc_field($record, '999$9', 'foobaz');
407
    @fields = $record->field('999');
408
    is(scalar @fields, 1, 'No additional field created');
409
    @subfields = $fields[0]->subfield('9');
410
    is(scalar @subfields, 1, 'No additional subfield created');
411
    is($subfields[0], 'foobaz', 'Subfield value has been changed');
412
};
413
414
subtest 'MarcFieldForCreatorAndModifier' => sub {
415
    plan tests => 8;
416
417
    t::lib::Mocks::mock_preference('MarcFieldForCreatorId', '998$a');
418
    t::lib::Mocks::mock_preference('MarcFieldForCreatorName', '998$b');
419
    t::lib::Mocks::mock_preference('MarcFieldForModifierId', '998$c');
420
    t::lib::Mocks::mock_preference('MarcFieldForModifierName', '998$d');
421
    my $c4_context = Test::MockModule->new('C4::Context');
422
    $c4_context->mock('userenv', sub { return { number => 123, firstname => 'John', surname => 'Doe'}; });
423
424
    my $record = MARC::Record->new();
425
    my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
426
427
    $record = GetMarcBiblio({biblionumber => $biblionumber});
428
    is($record->subfield('998', 'a'), 123, '998$a = 123');
429
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
430
    is($record->subfield('998', 'c'), 123, '998$c = 123');
431
    is($record->subfield('998', 'd'), 'John Doe', '998$d = John Doe');
432
433
    $c4_context->mock('userenv', sub { return { number => 321, firstname => 'Jane', surname => 'Doe'}; });
434
    C4::Biblio::ModBiblio($record, $biblionumber, '');
435
436
    $record = GetMarcBiblio({biblionumber => $biblionumber});
437
    is($record->subfield('998', 'a'), 123, '998$a = 123');
438
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
439
    is($record->subfield('998', 'c'), 321, '998$c = 321');
440
    is($record->subfield('998', 'd'), 'Jane Doe', '998$d = Jane Doe');
441
};

Return to bug 19349