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

(-)a/C4/Biblio.pm (-8 / +20 lines)
Lines 48-53 use Koha::Holds; Link Here
48
use Koha::ItemTypes;
48
use Koha::ItemTypes;
49
use Koha::SearchEngine;
49
use Koha::SearchEngine;
50
use Koha::Libraries;
50
use Koha::Libraries;
51
use Koha::Util::MARC;
51
52
52
use vars qw(@ISA @EXPORT);
53
use vars qw(@ISA @EXPORT);
53
use vars qw($debug $cgi_debug);
54
use vars qw($debug $cgi_debug);
Lines 3306-3320 sub ModBiblioMarc { Link Here
3306
    };
3307
    };
3307
    $record->as_usmarc; # Bug 20126/10455 This triggers field length calculation
3308
    $record->as_usmarc; # Bug 20126/10455 This triggers field length calculation
3308
3309
3309
    # FIXME To replace with ->find_or_create?
3310
    my $m_rs = Koha::Biblio::Metadatas->find($metadata);
3310
    if ( my $m_rs = Koha::Biblio::Metadatas->find($metadata) ) {
3311
    unless ($m_rs) {
3311
        $m_rs->metadata( $record->as_xml_record($encoding) );
3312
        $m_rs = Koha::Biblio::Metadata->new($metadata);
3312
        $m_rs->store;
3313
    }
3313
    } else {
3314
3314
        my $m_rs = Koha::Biblio::Metadata->new($metadata);
3315
    my $userenv = C4::Context->userenv;
3315
        $m_rs->metadata( $record->as_xml_record($encoding) );
3316
    if ($userenv) {
3316
        $m_rs->store;
3317
        my $borrowernumber = $userenv->{number};
3318
        my $borrowername = join ' ', @$userenv{qw(firstname surname)};
3319
        unless ($m_rs->in_storage) {
3320
            Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForCreatorId'), $borrowernumber);
3321
            Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForCreatorName'), $borrowername);
3322
        }
3323
        Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForModifierId'), $borrowernumber);
3324
        Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForModifierName'), $borrowername);
3317
    }
3325
    }
3326
3327
    $m_rs->metadata( $record->as_xml_record($encoding) );
3328
    $m_rs->store;
3329
3318
    ModZebra( $biblionumber, "specialUpdate", "biblioserver", $record );
3330
    ModZebra( $biblionumber, "specialUpdate", "biblioserver", $record );
3319
    return $biblionumber;
3331
    return $biblionumber;
3320
}
3332
}
(-)a/Koha/Util/MARC.pm (+43 lines)
Lines 179-182 sub getAuthorityAuthorizedHeading { Link Here
179
    return;
179
    return;
180
}
180
}
181
181
182
=head2 set_marc_field
183
184
    set_marc_field($record, $marcField, $value);
185
186
Set the value of $marcField to $value in $record. If the field exists, it will
187
be updated. If not, it will be created.
188
189
=head3 Parameters
190
191
=over 4
192
193
=item C<$record>
194
195
MARC::Record object
196
197
=item C<$marcField>
198
199
the MARC field to modify, a string in the form of 'XXX$y'
200
201
=item C<$value>
202
203
the value
204
205
=back
206
207
=cut
208
209
sub set_marc_field {
210
    my ($record, $marcField, $value) = @_;
211
212
    if ($marcField) {
213
        my ($fieldTag, $subfieldCode) = split /\$/, $marcField;
214
        my $field = $record->field($fieldTag);
215
        if ($field) {
216
            $field->update($subfieldCode => $value);
217
        } else {
218
            $field = MARC::Field->new($fieldTag, ' ', ' ',
219
                $subfieldCode => $value);
220
            $record->append_fields($field);
221
        }
222
    }
223
}
224
182
1;
225
1;
(-)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 265-270 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
265
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
265
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
266
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
266
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
267
('MarcFieldDocURL', NULL, NULL, 'URL used for MARC field documentation. Following substitutions are available: {MARC} = marc flavour, eg. "MARC21" or "UNIMARC". {FIELD} = field number, eg. "000" or "048". {LANG} = user language, eg. "en" or "fi-FI"', 'free'),
267
('MarcFieldDocURL', NULL, NULL, 'URL used for MARC field documentation. Following substitutions are available: {MARC} = marc flavour, eg. "MARC21" or "UNIMARC". {FIELD} = field number, eg. "000" or "048". {LANG} = user language, eg. "en" or "fi-FI"', 'free'),
268
('MarcFieldForCreatorId','',NULL,'Where to store the borrowernumber of the record''s creator','Free'),
269
('MarcFieldForCreatorName','',NULL,'Where to store the name of the record''s creator','Free'),
270
('MarcFieldForModifierId','',NULL,'Where to store the borrowernumber of the record''s last modifier','Free'),
271
('MarcFieldForModifierName','',NULL,'Where to store the name of the record''s last modifier','Free'),
268
('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'),
272
('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'),
269
('MarcItemFieldsToOrder','',NULL,'Set the mapping values for new item records created from a MARC record in a staged file. In a YAML format.','textarea'),
273
('MarcItemFieldsToOrder','',NULL,'Set the mapping values for new item records created from a MARC record in a staged file. In a YAML format.','textarea'),
270
('MarkLostItemsAsReturned','batchmod|moredetail|cronjob|additem','batchmod|moredetail|cronjob|additem','Mark items as returned when flagged as lost','multiple'),
274
('MarkLostItemsAsReturned','batchmod|moredetail|cronjob|additem','batchmod|moredetail|cronjob|additem','Mark items as returned when flagged as lost','multiple'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (+10 lines)
Lines 138-143 Cataloging: Link Here
138
            - 'MARC21: "952$a 952$b 952$c"'
138
            - 'MARC21: "952$a 952$b 952$c"'
139
            - Note that the FA framework is excluded from the permission.
139
            - Note that the FA framework is excluded from the permission.
140
            - If the pref is empty, no fields are restricted.
140
            - If the pref is empty, no fields are restricted.
141
        -
142
            - Store record's creator borrowernumber in MARC subfield
143
            - pref: MarcFieldForCreatorId
144
            - and record's creator name in MARC subfield
145
            - pref: MarcFieldForCreatorName
146
        -
147
            - Store record's last modifier borrowernumber in MARC subfield
148
            - pref: MarcFieldForModifierId
149
            - and record's last modifier name in MARC subfield
150
            - pref: MarcFieldForModifierName
141
    Display:
151
    Display:
142
        -
152
        -
143
            - 'Separate multiple displayed authors, series or subjects with '
153
            - 'Separate multiple displayed authors, series or subjects with '
(-)a/t/Koha/Util/MARC.t (+42 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 2;
21
22
BEGIN { use_ok('Koha::Util::MARC'); }
23
24
subtest 'set_marc_field' => sub {
25
    plan tests => 6;
26
27
    my $record = MARC::Record->new();
28
29
    Koha::Util::MARC::set_marc_field($record, '999$9', 'foobar');
30
    my @fields = $record->field('999');
31
    is(scalar @fields, 1, 'Created one field');
32
    my @subfields = $fields[0]->subfield('9');
33
    is(scalar @subfields, 1, 'Created one subfield');
34
    is($subfields[0], 'foobar', 'Created subfield has correct value');
35
36
    Koha::Util::MARC::set_marc_field($record, '999$9', 'foobaz');
37
    @fields = $record->field('999');
38
    is(scalar @fields, 1, 'No additional field created');
39
    @subfields = $fields[0]->subfield('9');
40
    is(scalar @subfields, 1, 'No additional subfield created');
41
    is($subfields[0], 'foobaz', 'Subfield value has been changed');
42
};
(-)a/t/db_dependent/Biblio.t (-2 / +30 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 9;
20
use Test::More tests => 10;
21
use Test::MockModule;
21
use Test::MockModule;
22
use List::MoreUtils qw( uniq );
22
use List::MoreUtils qw( uniq );
23
use MARC::Record;
23
use MARC::Record;
Lines 455-460 subtest 'deletedbiblio_metadata' => sub { Link Here
455
    is( $moved, $biblionumber, 'Found in deletedbiblio_metadata' );
455
    is( $moved, $biblionumber, 'Found in deletedbiblio_metadata' );
456
};
456
};
457
457
458
subtest 'MarcFieldForCreatorAndModifier' => sub {
459
    plan tests => 8;
460
461
    t::lib::Mocks::mock_preference('MarcFieldForCreatorId', '998$a');
462
    t::lib::Mocks::mock_preference('MarcFieldForCreatorName', '998$b');
463
    t::lib::Mocks::mock_preference('MarcFieldForModifierId', '998$c');
464
    t::lib::Mocks::mock_preference('MarcFieldForModifierName', '998$d');
465
    my $c4_context = Test::MockModule->new('C4::Context');
466
    $c4_context->mock('userenv', sub { return { number => 123, firstname => 'John', surname => 'Doe'}; });
467
468
    my $record = MARC::Record->new();
469
    my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
470
471
    $record = GetMarcBiblio({biblionumber => $biblionumber});
472
    is($record->subfield('998', 'a'), 123, '998$a = 123');
473
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
474
    is($record->subfield('998', 'c'), 123, '998$c = 123');
475
    is($record->subfield('998', 'd'), 'John Doe', '998$d = John Doe');
476
477
    $c4_context->mock('userenv', sub { return { number => 321, firstname => 'Jane', surname => 'Doe'}; });
478
    C4::Biblio::ModBiblio($record, $biblionumber, '');
479
480
    $record = GetMarcBiblio({biblionumber => $biblionumber});
481
    is($record->subfield('998', 'a'), 123, '998$a = 123');
482
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
483
    is($record->subfield('998', 'c'), 321, '998$c = 321');
484
    is($record->subfield('998', 'd'), 'Jane Doe', '998$d = Jane Doe');
485
};
486
458
# Cleanup
487
# Cleanup
459
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
488
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
460
$schema->storage->txn_rollback;
489
$schema->storage->txn_rollback;
461
- 

Return to bug 19349