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

(-)a/C4/Biblio.pm (-43 / +9 lines)
Lines 283-310 sub AddBiblio { Link Here
283
            # update MARC subfield that stores biblioitems.cn_sort
283
            # update MARC subfield that stores biblioitems.cn_sort
284
            _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
284
            _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
285
285
286
            # update the control number (001) in MARC
287
            if(C4::Context->preference('autoControlNumber') eq 'biblionumber'){
288
                unless($record->field('001')){
289
                    $record->insert_fields_ordered(MARC::Field->new('001', $biblionumber));
290
                }elsif($record->field('001')->data() eq 'biblionumber'){
291
                    $record->field('001')->update($biblionumber);
292
                }
293
            }elsif(C4::Context->preference('autoControlNumber') eq 'incremental'){
294
                if(!defined($record->field('001')) or (defined($record->field('001')) and $record->field('001')->data() eq 'incremental')){
295
                    my $sth = $dbh->prepare(q{UPDATE systempreferences SET value = value+1 WHERE variable = 'incrementalControlNumber'});
296
                    $sth->execute();
297
                    $sth->finish();
298
                    my $incrementalCN=C4::Context->preference('incrementalControlNumber')-1;
299
                    unless($record->field('001')){
300
                        $record->insert_fields_ordered(MARC::Field->new('001', $incrementalCN));
301
                    }else{
302
                        $record->field('001')->update($incrementalCN);
303
                    }
304
                }
305
            }
306
307
308
            # now add the record
286
            # now add the record
309
            ModBiblioMarc( $record, $biblionumber ) unless $defer_marc_save;
287
            ModBiblioMarc( $record, $biblionumber ) unless $defer_marc_save;
310
288
Lines 398-424 sub ModBiblio { Link Here
398
    # update MARC subfield that stores biblioitems.cn_sort
376
    # update MARC subfield that stores biblioitems.cn_sort
399
    _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode );
377
    _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode );
400
378
401
    # update the control number (001) in MARC
402
    if(C4::Context->preference('autoControlNumber') eq 'biblionumber'){
403
        unless($record->field('001')){
404
            $record->insert_fields_ordered(MARC::Field->new('001', $biblionumber));
405
        }elsif($record->field('001')->data() eq 'biblionumber'){
406
            $record->field('001')->update($biblionumber);
407
        }
408
    }elsif(C4::Context->preference('autoControlNumber') eq 'incremental'){
409
        if(!defined($record->field('001')) or (defined($record->field('001')) and $record->field('001')->data() eq 'incremental')){
410
            my $sth = $dbh->prepare(q{UPDATE systempreferences SET value = value+1 WHERE variable = 'incrementalControlNumber'});
411
            $sth->execute();
412
            $sth->finish();
413
            my $incrementalCN=C4::Context->preference('incrementalControlNumber')-1;
414
            unless($record->field('001')){
415
                $record->insert_fields_ordered(MARC::Field->new('001', $incrementalCN));
416
            }else{
417
                $record->field('001')->update($incrementalCN);
418
            }
419
        }
420
    }
421
422
    # update the MARC record (that now contains biblio and items) with the new record data
379
    # update the MARC record (that now contains biblio and items) with the new record data
423
    &ModBiblioMarc( $record, $biblionumber );
380
    &ModBiblioMarc( $record, $biblionumber );
424
381
Lines 2668-2673 sub _koha_marc_update_bib_ids { Link Here
2668
    } else {
2625
    } else {
2669
        C4::Biblio::UpsertMarcSubfield($record, $biblioitem_tag, $biblioitem_subfield, $biblioitemnumber);
2626
        C4::Biblio::UpsertMarcSubfield($record, $biblioitem_tag, $biblioitem_subfield, $biblioitemnumber);
2670
    }
2627
    }
2628
2629
    # update the control number (001) in MARC
2630
    if(C4::Context->preference('autoControlNumber') eq 'biblionumber'){
2631
        unless($record->field('001')){
2632
            $record->insert_fields_ordered(MARC::Field->new('001', $biblionumber));
2633
        }elsif($record->field('001')->data() eq 'biblionumber'){
2634
            $record->field('001')->update($biblionumber);
2635
        }
2636
    }
2671
}
2637
}
2672
2638
2673
=head2 _koha_marc_update_biblioitem_cn_sort
2639
=head2 _koha_marc_update_biblioitem_cn_sort
(-)a/cataloguing/value_builder/marc21_field_001.pl (-76 lines)
Lines 1-76 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2013 Spanish Ministry of Education, Culture and Sport
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use C4::Context;
23
24
# This is a new style cataloging plugin, using $building_plugin
25
26
our $building_plugin;
27
if(defined $building_plugin) {
28
    marc21_field001_plugin_javascript();
29
}
30
else { #nothing to do (no popup)
31
}
32
33
#-------------------------------------------------------------------------------
34
35
sub marc21_field001_plugin_javascript {
36
    my $field_number= $building_plugin->{subfieldid};
37
    my $function_name= $field_number;
38
39
    #depending on preference, adjust Focus function
40
    my $autoControlNumber = C4::Context->preference('autoControlNumber');
41
    my $focusline='';
42
    if( $autoControlNumber ne 'OFF' ) {
43
        $focusline= "document.getElementById(\"$field_number\").value='$autoControlNumber';\n";
44
    }
45
    $focusline.='return 1;';
46
47
    #build the actual javascript
48
    my $res = "
49
<script type=\"text/javascript\">
50
//<![CDATA[
51
oldValue = document.getElementById(\"$field_number\").value;
52
function Blur$function_name(subfield_managed) {
53
    if(oldValue != document.getElementById(\"$field_number\").value){
54
        $focusline
55
    }
56
    return 1;
57
}
58
function Focus$function_name(subfield_managed) {
59
    if(!document.getElementById(\"$field_number\").value){
60
        $focusline
61
    }
62
    return 1;
63
}
64
function Clic$function_name(index) {
65
    $focusline
66
}
67
//]]>
68
</script>
69
";
70
71
    #return to caller via global hash
72
    $building_plugin->{function}= $function_name;
73
    $building_plugin->{javascript}= $res;
74
}
75
76
1;
(-)a/installer/data/mysql/atomicupdate/bug_9921.perl (-20 / +3 lines)
Lines 2-28 $DBversion = 'XXX'; # will be replaced by the RM Link Here
2
if( CheckVersion( $DBversion ) ) {
2
if( CheckVersion( $DBversion ) ) {
3
    # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" );
3
    # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" );
4
    $dbh->do(
4
    $dbh->do(
5
        q{INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('autoControlNumber','OFF','incremental|biblionumber|OFF',
5
        q{INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('autoControlNumber','OFF','biblionumber|OFF',
6
        'Used to autogenerate a Control Number: incremental will be of the form 1, 2, 3; biblionumber will be as biblionumber;','Choice');}
6
        'Used to autogenerate a Control Number: biblionumber will be as biblionumber; OFF will leave it as is','Choice');}
7
    );
7
    );
8
    $dbh->do(
9
        q{INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('incrementalControlNumber', '1', 'Set the number
10
        (controlnumber) of the next bibliographic record.',NULL,'');}
11
    );
12
    if (C4::Context->preference("marcflavour") eq 'MARC21') {
13
        my $sth = $dbh->prepare(
14
            q{SELECT * FROM marc_subfield_structure WHERE tagfield = '001' AND tagsubfield = '@'
15
            AND (value_builder IS NOT NULL AND value_builder != '') LIMIT 1;}
16
        );
17
        $sth->execute;
18
        unless($sth->fetchrow){
19
            $dbh->do(
20
                q{UPDATE marc_subfield_structure SET value_builder = 'marc21_field_001.pl' WHERE tagfield = '001' AND tagsubfield = '@';}
21
            );
22
            print "WARNING: Your frameworks have been updated, field 001 will filled in through marc21_field_001.pl plugin.\n";
23
        }
24
    }
25
8
26
    # Always end with this (adjust the bug info)
9
    # Always end with this (adjust the bug info)
27
    NewVersion( $DBversion, 9921, "Make it possible to force 001 = biblionumbe");
10
    NewVersion( $DBversion, 9921, "Make it possible to force 001 = biblionumber");
28
}
11
}
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-2 / +1 lines)
Lines 69-75 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
69
('AuthoritySeparator','--','10','Used to separate a list of authorities in a display. Usually --','free'),
69
('AuthoritySeparator','--','10','Used to separate a list of authorities in a display. Usually --','free'),
70
('AuthSuccessLog','0',NULL,'If enabled, log successful authentications','YesNo'),
70
('AuthSuccessLog','0',NULL,'If enabled, log successful authentications','YesNo'),
71
('autoBarcode','OFF','incremental|annual|hbyymmincr|EAN13|OFF','Used to autogenerate a barcode: incremental will be of the form 1, 2, 3; annual of the form 2007-0001, 2007-0002; hbyymmincr of the form HB08010001 where HB=Home Branch','Choice'),
71
('autoBarcode','OFF','incremental|annual|hbyymmincr|EAN13|OFF','Used to autogenerate a barcode: incremental will be of the form 1, 2, 3; annual of the form 2007-0001, 2007-0002; hbyymmincr of the form HB08010001 where HB=Home Branch','Choice'),
72
('autoControlNumber','OFF','incremental|biblionumber|OFF','Used to autogenerate a Control Number: incremental will be of the form 1, 2, 3; biblionumber will be as biblionumber;','Choice'),
72
('autoControlNumber','OFF','biblionumber|OFF','Used to autogenerate a Control Number: biblionumber will be as biblionumber, OFF will leave the field as it is;','Choice'),
73
('AutoCreateAuthorities','0',NULL,'Automatically create authorities that do not exist when cataloging records.','YesNo'),
73
('AutoCreateAuthorities','0',NULL,'Automatically create authorities that do not exist when cataloging records.','YesNo'),
74
('AutoCreditNumber', '', '', 'Automatically generate a number for account credits', 'Choice'),
74
('AutoCreditNumber', '', '', 'Automatically generate a number for account credits', 'Choice'),
75
('AutoEmailOpacUser','0',NULL,'Sends notification emails containing new account details to patrons - when account is created.','YesNo'),
75
('AutoEmailOpacUser','0',NULL,'Sends notification emails containing new account details to patrons - when account is created.','YesNo'),
Lines 256-262 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
256
('ILS-DI:AuthorizedIPs','','Restricts usage of ILS-DI to some IPs','.','Free'),
256
('ILS-DI:AuthorizedIPs','','Restricts usage of ILS-DI to some IPs','.','Free'),
257
('ImageLimit','5','','Limit images stored in the database by the Patron Card image manager to this number.','Integer'),
257
('ImageLimit','5','','Limit images stored in the database by the Patron Card image manager to this number.','Integer'),
258
('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'),
258
('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'),
259
('incrementalControlNumber', '1', 'Set the number (controlnumber) of the next bibliographic record.',NULL,''),
260
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
259
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
261
('IndependentBranchesPatronModifications','0', NULL, 'Show only modification request for the logged in branch','YesNo'),
260
('IndependentBranchesPatronModifications','0', NULL, 'Show only modification request for the logged in branch','YesNo'),
262
('IndependentBranchesTransfers','0', NULL, 'Allow non-superlibrarians to transfer items between libraries','YesNo'),
261
('IndependentBranchesTransfers','0', NULL, 'Allow non-superlibrarians to transfer items between libraries','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (-8 lines)
Lines 163-177 Cataloging: Link Here
163
            - pref: autoControlNumber
163
            - pref: autoControlNumber
164
              choices:
164
              choices:
165
                  biblionumber: generated as biblionumber.
165
                  biblionumber: generated as biblionumber.
166
                  incremental: generated in the form 1, 2, 3.
167
                  "OFF": not generated automatically.
166
                  "OFF": not generated automatically.
168
            - (You should fill in a value in incrementalControlNumber preference.)
169
        -
170
            - Use Control Number (001)
171
            - pref: incrementalControlNumber
172
              class: integer
173
            - as incremental number. (This requires generated in the form 1, 2, 3 in autoControlNumber preference.)
174
    Display:
175
        -
167
        -
176
            - 'Separate main entry and subdivisions with '
168
            - 'Separate main entry and subdivisions with '
177
            - pref: AuthoritySeparator
169
            - pref: AuthoritySeparator
(-)a/t/db_dependent/Biblio.t (-2 / +24 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 15;
20
use Test::More tests => 16;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
use List::MoreUtils qw( uniq );
23
use List::MoreUtils qw( uniq );
Lines 805-810 subtest "LinkBibHeadingsToAuthorities record generation tests" => sub { Link Here
805
    );
805
    );
806
};
806
};
807
807
808
subtest 'autoControlNumber tests' => sub {
809
    plan tests => 3;
810
811
    t::lib::Mocks::mock_preference('autoControlNumber', 'OFF');
812
813
    my $record = MARC::Record->new();
814
    my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
815
    $record = GetMarcBiblio({biblionumber => $biblionumber});
816
    is($record->field('001'), undef, '001 not set when pref is off');
817
818
    t::lib::Mocks::mock_preference('autoControlNumber', 'biblionumber');
819
    C4::Biblio::ModBiblio($record, $biblionumber, "", 1);
820
    $record = GetMarcBiblio({biblionumber => $biblionumber});
821
    is($record->field('001')->as_string(), $biblionumber, '001 set to biblionumber when pref set and field is blank');
822
823
    $record->field('001')->update('Not biblionumber');
824
    C4::Biblio::ModBiblio($record, $biblionumber, "", 1);
825
    $record = GetMarcBiblio({biblionumber => $biblionumber});
826
    is($record->field('001')->as_string(), 'Not biblionumber', '001 not set to biblionumber when pref set and field exists');
827
828
};
829
830
808
# Cleanup
831
# Cleanup
809
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
832
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
810
$schema->storage->txn_rollback;
833
$schema->storage->txn_rollback;
811
- 

Return to bug 9921