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

(-)a/C4/Biblio.pm (-8 / +20 lines)
Lines 107-112 use Koha::Holds; Link Here
107
use Koha::ItemTypes;
107
use Koha::ItemTypes;
108
use Koha::SearchEngine;
108
use Koha::SearchEngine;
109
use Koha::Libraries;
109
use Koha::Libraries;
110
use Koha::Util::MARC;
110
111
111
use vars qw($debug $cgi_debug);
112
use vars qw($debug $cgi_debug);
112
113
Lines 3290-3304 sub ModBiblioMarc { Link Here
3290
    };
3291
    };
3291
    $record->as_usmarc; # Bug 20126/10455 This triggers field length calculation
3292
    $record->as_usmarc; # Bug 20126/10455 This triggers field length calculation
3292
3293
3293
    # FIXME To replace with ->find_or_create?
3294
    my $m_rs = Koha::Biblio::Metadatas->find($metadata);
3294
    if ( my $m_rs = Koha::Biblio::Metadatas->find($metadata) ) {
3295
    unless ($m_rs) {
3295
        $m_rs->metadata( $record->as_xml_record($encoding) );
3296
        $m_rs = Koha::Biblio::Metadata->new($metadata);
3296
        $m_rs->store;
3297
    }
3297
    } else {
3298
3298
        my $m_rs = Koha::Biblio::Metadata->new($metadata);
3299
    my $userenv = C4::Context->userenv;
3299
        $m_rs->metadata( $record->as_xml_record($encoding) );
3300
    if ($userenv) {
3300
        $m_rs->store;
3301
        my $borrowernumber = $userenv->{number};
3302
        my $borrowername = join ' ', @$userenv{qw(firstname surname)};
3303
        unless ($m_rs->in_storage) {
3304
            Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForCreatorId'), $borrowernumber);
3305
            Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForCreatorName'), $borrowername);
3306
        }
3307
        Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForModifierId'), $borrowernumber);
3308
        Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForModifierName'), $borrowername);
3301
    }
3309
    }
3310
3311
    $m_rs->metadata( $record->as_xml_record($encoding) );
3312
    $m_rs->store;
3313
3302
    ModZebra( $biblionumber, "specialUpdate", "biblioserver", $record );
3314
    ModZebra( $biblionumber, "specialUpdate", "biblioserver", $record );
3303
    return $biblionumber;
3315
    return $biblionumber;
3304
}
3316
}
(-)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 271-276 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
271
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
271
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
272
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
272
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
273
('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'),
273
('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'),
274
('MarcFieldForCreatorId','',NULL,'Where to store the borrowernumber of the record''s creator','Free'),
275
('MarcFieldForCreatorName','',NULL,'Where to store the name of the record''s creator','Free'),
276
('MarcFieldForModifierId','',NULL,'Where to store the borrowernumber of the record''s last modifier','Free'),
277
('MarcFieldForModifierName','',NULL,'Where to store the name of the record''s last modifier','Free'),
274
('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'),
278
('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'),
275
('MarcItemFieldsToOrder','',NULL,'Set the mapping values for new item records created from a MARC record in a staged file. In a YAML format.','textarea'),
279
('MarcItemFieldsToOrder','',NULL,'Set the mapping values for new item records created from a MARC record in a staged file. In a YAML format.','textarea'),
276
('MarkLostItemsAsReturned','batchmod|moredetail|cronjob|additem','batchmod|moredetail|cronjob|additem','Mark items as returned when flagged as lost','multiple'),
280
('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 => 10;
20
use Test::More tests => 11;
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 466-471 subtest 'DelBiblio' => sub { Link Here
466
    is( $deleted, undef, 'DelBiblo should return undef is the record did not exist');
466
    is( $deleted, undef, 'DelBiblo should return undef is the record did not exist');
467
};
467
};
468
468
469
subtest 'MarcFieldForCreatorAndModifier' => sub {
470
    plan tests => 8;
471
472
    t::lib::Mocks::mock_preference('MarcFieldForCreatorId', '998$a');
473
    t::lib::Mocks::mock_preference('MarcFieldForCreatorName', '998$b');
474
    t::lib::Mocks::mock_preference('MarcFieldForModifierId', '998$c');
475
    t::lib::Mocks::mock_preference('MarcFieldForModifierName', '998$d');
476
    my $c4_context = Test::MockModule->new('C4::Context');
477
    $c4_context->mock('userenv', sub { return { number => 123, firstname => 'John', surname => 'Doe'}; });
478
479
    my $record = MARC::Record->new();
480
    my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
481
482
    $record = GetMarcBiblio({biblionumber => $biblionumber});
483
    is($record->subfield('998', 'a'), 123, '998$a = 123');
484
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
485
    is($record->subfield('998', 'c'), 123, '998$c = 123');
486
    is($record->subfield('998', 'd'), 'John Doe', '998$d = John Doe');
487
488
    $c4_context->mock('userenv', sub { return { number => 321, firstname => 'Jane', surname => 'Doe'}; });
489
    C4::Biblio::ModBiblio($record, $biblionumber, '');
490
491
    $record = GetMarcBiblio({biblionumber => $biblionumber});
492
    is($record->subfield('998', 'a'), 123, '998$a = 123');
493
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
494
    is($record->subfield('998', 'c'), 321, '998$c = 321');
495
    is($record->subfield('998', 'd'), 'Jane Doe', '998$d = Jane Doe');
496
};
497
469
# Cleanup
498
# Cleanup
470
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
499
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
471
$schema->storage->txn_rollback;
500
$schema->storage->txn_rollback;
472
- 

Return to bug 19349