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

(-)a/C4/Biblio.pm (-17 / +101 lines)
Lines 3035-3042 sub _koha_add_biblio { Link Here
3035
    	if ( $biblio->{'seriestitle'} ) { $biblio->{'serial'} = 1 }
3035
    	if ( $biblio->{'seriestitle'} ) { $biblio->{'serial'} = 1 }
3036
    }
3036
    }
3037
3037
3038
    ### Validating biblionumber.
3039
    my $biblionumber;
3040
    my $isBiblioNumberOk = ''; #placeholder for the sql-clause which inserts biblionumber
3041
    if (exists $biblio->{'biblionumber'}) {
3042
        $biblionumber = $biblio->{'biblionumber'};
3043
        if (! ($biblionumber =~ /^\d+$/) ) {
3044
            $error .= "C4::Biblio::_koha_add_biblio():> Biblionumber $biblionumber is not a number! Using a new biblionumber\n";
3045
        }
3046
        elsif (! ($biblionumber > 0)) {
3047
            $error .= "C4::Biblio::_koha_add_biblio():> Biblionumber $biblionumber is not greater than 0! Using a new biblionumber\n";
3048
        }
3049
        #The real Perl LONG_MAX is 2147483646, but using 2147483640
3050
        #  so we can detect the imminent primary key exhaustion before it actually is exhausted.
3051
        elsif (! ($biblionumber < 2147483640)) {
3052
            $error .= "C4::Biblio::_koha_add_biblio():> Biblionumber $biblionumber is too large for Perl! Using a new biblionumber\n";
3053
        }
3054
        else {
3055
            #We have validated the biblionumber and can prepare to insert it.
3056
            $isBiblioNumberOk = 'biblionumber = ?,';
3057
        }
3058
3059
    }
3060
3038
    my $query = "INSERT INTO biblio
3061
    my $query = "INSERT INTO biblio
3039
        SET frameworkcode = ?,
3062
        SET frameworkcode = ?,
3063
            $isBiblioNumberOk
3040
            author = ?,
3064
            author = ?,
3041
            title = ?,
3065
            title = ?,
3042
            unititle =?,
3066
            unititle =?,
Lines 3048-3064 sub _koha_add_biblio { Link Here
3048
            abstract = ?
3072
            abstract = ?
3049
        ";
3073
        ";
3050
    my $sth = $dbh->prepare($query);
3074
    my $sth = $dbh->prepare($query);
3051
    $sth->execute(
3052
        $frameworkcode, $biblio->{'author'},      $biblio->{'title'},         $biblio->{'unititle'}, $biblio->{'notes'},
3053
        $biblio->{'serial'},        $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'}
3054
    );
3055
3075
3056
    my $biblionumber = $dbh->{'mysql_insertid'};
3076
    if ($isBiblioNumberOk) {
3077
        $sth->execute(
3078
            $frameworkcode, $biblionumber, $biblio->{'author'},      $biblio->{'title'},         $biblio->{'unititle'}, $biblio->{'notes'},
3079
            $biblio->{'serial'},        $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'}
3080
        );
3081
    }
3082
    else {
3083
        $sth->execute(
3084
            $frameworkcode, $biblio->{'author'},      $biblio->{'title'},         $biblio->{'unititle'}, $biblio->{'notes'},
3085
            $biblio->{'serial'},        $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'}
3086
        );
3087
    }
3088
3089
3090
    $biblionumber = $isBiblioNumberOk ? $biblionumber : $dbh->{'mysql_insertid'};
3057
    if ( $dbh->errstr ) {
3091
    if ( $dbh->errstr ) {
3058
        $error .= "ERROR in _koha_add_biblio $query" . $dbh->errstr;
3092
        $error .= "ERROR in _koha_add_biblio $query" . $dbh->errstr;
3093
    }
3094
3095
3096
    if (defined $error) {
3059
        warn $error;
3097
        warn $error;
3060
    }
3098
    }
3061
3099
3100
3062
    $sth->finish();
3101
    $sth->finish();
3063
3102
3064
    #warn "LEAVING _koha_add_biblio: ".$biblionumber."\n";
3103
    #warn "LEAVING _koha_add_biblio: ".$biblionumber."\n";
Lines 3184-3191 sub _koha_add_biblioitem { Link Here
3184
    my ( $dbh, $biblioitem ) = @_;
3223
    my ( $dbh, $biblioitem ) = @_;
3185
    my $error;
3224
    my $error;
3186
3225
3226
    ### Validating biblionumber.
3227
    my $biblioitemnumber;
3228
    my $isBiblioitemNumberOk = ''; #placeholder for the sql-clause which inserts biblionumber
3229
    if (exists $biblioitem->{'biblioitemnumber'}) {
3230
        $biblioitemnumber = $biblioitem->{'biblioitemnumber'};
3231
        if (! ($biblioitemnumber =~ /^\d+$/) ) {
3232
            $error .= "C4::Biblio::_koha_add_biblioitem():> biblioitemnumber $biblioitemnumber is not a number! Using a new biblioitemnumber\n";
3233
        }
3234
        elsif (! ($biblioitemnumber > 0)) {
3235
            $error .= "C4::Biblio::_koha_add_biblioitem():> biblioitemnumber $biblioitemnumber is not greater than 0! Using a new biblioitemnumber\n";
3236
        }
3237
        #The real Perl LONG_MAX is 2147483646, but using 2147483640
3238
        #  so we can detect the imminent primary key exhaustion before it actually is exhausted.
3239
        elsif (! ($biblioitemnumber < 2147483640)) {
3240
            $error .= "C4::Biblio::_koha_add_biblioitem():> biblioitemnumber $biblioitemnumber is too large for Perl! Using a new biblioitemnumber\n";
3241
        }
3242
        else {
3243
            #We have validated the biblionumber and can prepare to insert it.
3244
            $isBiblioitemNumberOk = 'biblioitemnumber = ?,';
3245
        }
3246
3247
    }
3248
3187
    my ($cn_sort) = GetClassSort( $biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} );
3249
    my ($cn_sort) = GetClassSort( $biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} );
3188
    my $query = "INSERT INTO biblioitems SET
3250
    my $query = "INSERT INTO biblioitems SET
3251
        $isBiblioitemNumberOk
3189
        biblionumber    = ?,
3252
        biblionumber    = ?,
3190
        volume          = ?,
3253
        volume          = ?,
3191
        number          = ?,
3254
        number          = ?,
Lines 3219-3242 sub _koha_add_biblioitem { Link Here
3219
        agerestriction  = ?
3282
        agerestriction  = ?
3220
        ";
3283
        ";
3221
    my $sth = $dbh->prepare($query);
3284
    my $sth = $dbh->prepare($query);
3222
    $sth->execute(
3285
3223
        $biblioitem->{'biblionumber'},     $biblioitem->{'volume'},           $biblioitem->{'number'},                $biblioitem->{'itemtype'},
3286
    if ($isBiblioitemNumberOk) {
3224
        $biblioitem->{'isbn'},             $biblioitem->{'issn'},             $biblioitem->{'publicationyear'},       $biblioitem->{'publishercode'},
3287
        $sth->execute(
3225
        $biblioitem->{'volumedate'},       $biblioitem->{'volumedesc'},       $biblioitem->{'collectiontitle'},       $biblioitem->{'collectionissn'},
3288
            $biblioitem->{'biblioitemnumber'},
3226
        $biblioitem->{'collectionvolume'}, $biblioitem->{'editionstatement'}, $biblioitem->{'editionresponsibility'}, $biblioitem->{'illus'},
3289
            $biblioitem->{'biblionumber'},     $biblioitem->{'volume'},           $biblioitem->{'number'},                $biblioitem->{'itemtype'},
3227
        $biblioitem->{'pages'},            $biblioitem->{'bnotes'},           $biblioitem->{'size'},                  $biblioitem->{'place'},
3290
            $biblioitem->{'isbn'},             $biblioitem->{'issn'},             $biblioitem->{'publicationyear'},       $biblioitem->{'publishercode'},
3228
        $biblioitem->{'lccn'},             $biblioitem->{'marc'},             $biblioitem->{'url'},                   $biblioitem->{'biblioitems.cn_source'},
3291
            $biblioitem->{'volumedate'},       $biblioitem->{'volumedesc'},       $biblioitem->{'collectiontitle'},       $biblioitem->{'collectionissn'},
3229
        $biblioitem->{'cn_class'},         $biblioitem->{'cn_item'},          $biblioitem->{'cn_suffix'},             $cn_sort,
3292
            $biblioitem->{'collectionvolume'}, $biblioitem->{'editionstatement'}, $biblioitem->{'editionresponsibility'}, $biblioitem->{'illus'},
3230
        $biblioitem->{'totalissues'},      $biblioitem->{'ean'},              $biblioitem->{'agerestriction'}
3293
            $biblioitem->{'pages'},            $biblioitem->{'bnotes'},           $biblioitem->{'size'},                  $biblioitem->{'place'},
3231
    );
3294
            $biblioitem->{'lccn'},             $biblioitem->{'marc'},             $biblioitem->{'url'},                   $biblioitem->{'biblioitems.cn_source'},
3232
    my $bibitemnum = $dbh->{'mysql_insertid'};
3295
            $biblioitem->{'cn_class'},         $biblioitem->{'cn_item'},          $biblioitem->{'cn_suffix'},             $cn_sort,
3296
            $biblioitem->{'totalissues'},      $biblioitem->{'ean'},              $biblioitem->{'agerestriction'}
3297
        );
3298
    }
3299
    else {
3300
        $sth->execute(
3301
            $biblioitem->{'biblionumber'},     $biblioitem->{'volume'},           $biblioitem->{'number'},                $biblioitem->{'itemtype'},
3302
            $biblioitem->{'isbn'},             $biblioitem->{'issn'},             $biblioitem->{'publicationyear'},       $biblioitem->{'publishercode'},
3303
            $biblioitem->{'volumedate'},       $biblioitem->{'volumedesc'},       $biblioitem->{'collectiontitle'},       $biblioitem->{'collectionissn'},
3304
            $biblioitem->{'collectionvolume'}, $biblioitem->{'editionstatement'}, $biblioitem->{'editionresponsibility'}, $biblioitem->{'illus'},
3305
            $biblioitem->{'pages'},            $biblioitem->{'bnotes'},           $biblioitem->{'size'},                  $biblioitem->{'place'},
3306
            $biblioitem->{'lccn'},             $biblioitem->{'marc'},             $biblioitem->{'url'},                   $biblioitem->{'biblioitems.cn_source'},
3307
            $biblioitem->{'cn_class'},         $biblioitem->{'cn_item'},          $biblioitem->{'cn_suffix'},             $cn_sort,
3308
            $biblioitem->{'totalissues'},      $biblioitem->{'ean'},              $biblioitem->{'agerestriction'}
3309
        );
3310
    }
3311
3312
    $biblioitemnumber = $isBiblioitemNumberOk ? $biblioitemnumber : $dbh->{'mysql_insertid'};
3233
3313
3234
    if ( $dbh->errstr ) {
3314
    if ( $dbh->errstr ) {
3235
        $error .= "ERROR in _koha_add_biblioitem $query" . $dbh->errstr;
3315
        $error .= "ERROR in _koha_add_biblioitem $query" . $dbh->errstr;
3316
    }
3317
3318
    if (defined $error) {
3236
        warn $error;
3319
        warn $error;
3237
    }
3320
    }
3321
3238
    $sth->finish();
3322
    $sth->finish();
3239
    return ( $bibitemnum, $error );
3323
    return ( $biblioitemnumber, $error );
3240
}
3324
}
3241
3325
3242
=head2 _koha_delete_biblio
3326
=head2 _koha_delete_biblio
(-)a/misc/migration_tools/bulkmarcimport.pl (-2 / +68 lines)
Lines 34-40 use Pod::Usage; Link Here
34
use open qw( :std :encoding(UTF-8) );
34
use open qw( :std :encoding(UTF-8) );
35
binmode( STDOUT, ":encoding(UTF-8)" );
35
binmode( STDOUT, ":encoding(UTF-8)" );
36
my ( $input_marc_file, $number, $offset) = ('',0,0);
36
my ( $input_marc_file, $number, $offset) = ('',0,0);
37
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile);
37
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile, $legacyIdAsBiblionumberFromHere);
38
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes );
38
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes );
39
my $cleanisbn = 1;
39
my $cleanisbn = 1;
40
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
40
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
Lines 73-78 GetOptions( Link Here
73
    'yaml:s'        => \$yamlfile,
73
    'yaml:s'        => \$yamlfile,
74
    'dedupbarcode' => \$dedup_barcode,
74
    'dedupbarcode' => \$dedup_barcode,
75
    'framework=s' => \$framework,
75
    'framework=s' => \$framework,
76
	'g|legacyIdAsBiblionumberFromHere:s' => \$legacyIdAsBiblionumberFromHere,
76
);
77
);
77
$biblios ||= !$authorities;
78
$biblios ||= !$authorities;
78
$insert  ||= !$update;
79
$insert  ||= !$update;
Lines 166-179 if ( $offset ) { Link Here
166
    $batch->next() while ($offset--);
167
    $batch->next() while ($offset--);
167
}
168
}
168
169
169
my ($tagid,$subfieldid);
170
my ($tagid, $subfieldid, $binum_tagid, $binum_subfieldid);
170
if ($authorities){
171
if ($authorities){
171
	  $tagid='001';
172
	  $tagid='001';
172
}
173
}
173
else {
174
else {
174
   ( $tagid, $subfieldid ) =
175
   ( $tagid, $subfieldid ) =
175
            GetMarcFromKohaField( "biblio.biblionumber", $framework );
176
            GetMarcFromKohaField( "biblio.biblionumber", $framework );
177
   ( $binum_tagid, $binum_subfieldid ) =
178
            GetMarcFromKohaField( "biblioitems.biblioitemnumber", $framework );
176
	$tagid||="001";
179
	$tagid||="001";
180
181
	#This is important for the functionality $legacyIdAsBiblionumberFromHere
182
	if ($tagid ne $binum_tagid) {
183
		warn "Koha to MARC mapping values biblio.biblionumber and biblioitems.biblioitemnumber must share the same MARC field!";
184
		exit(1);
185
	}
186
177
}
187
}
178
188
179
# the SQL query to search on isbn
189
# the SQL query to search on isbn
Lines 204-209 RECORD: while ( ) { Link Here
204
    $i++;
214
    $i++;
205
    print ".";
215
    print ".";
206
    print "\n$i" unless $i % 100;
216
    print "\n$i" unless $i % 100;
217
218
219
220
	### If you are like me and don't have the legacy id in $999c and $999d, you
221
	###   can use this functionality to copy the id on the fly.
222
	### By default, copy legacy id field 001 to 999c and 999d ###
223
	if ($legacyIdAsBiblionumberFromHere) {
224
		my $legacyIdField = $record->field( $legacyIdAsBiblionumberFromHere );
225
		if ($legacyIdField) {
226
			my $legacyId = $legacyIdField->data();
227
			my $biblionumberField = MARC::Field->new( $tagid, '', '',
228
			   $subfieldid => $legacyId,
229
			   $binum_subfieldid => $legacyId,
230
			);
231
			$record->append_fields($biblionumberField);
232
		}
233
		else {
234
			warn "No $legacyIdAsBiblionumberFromHere found!";
235
		}
236
	}
207
    
237
    
208
    # transcode the record to UTF8 if needed & applicable.
238
    # transcode the record to UTF8 if needed & applicable.
209
    if ($record->encoding() eq 'MARC-8' and not $skip_marc8_conversion) {
239
    if ($record->encoding() eq 'MARC-8' and not $skip_marc8_conversion) {
Lines 582-593 bulkmarcimport.pl - Import bibliographic/authority records into Koha Link Here
582
 $ perl misc/migration_tools/bulkmarcimport.pl -d -commit 1000 \\
612
 $ perl misc/migration_tools/bulkmarcimport.pl -d -commit 1000 \\
583
    -file /home/jmf/koha.mrc -n 3000
613
    -file /home/jmf/koha.mrc -n 3000
584
614
615
 Migrate your legacy bibliographic records to Koha, while having the legacy id
616
 in a field $999 according to your directives here
617
 "Administration" > "Koha to Marc mapping".
618
 You also have the legacy id in field $001 so your analytic and component
619
 records links wont be broken.
620
 $ perl misc/migration_tools/bulkmarcimport.pl -d -commit 1000 \\
621
    -file /home/jmf/koha.marcxml -m MARCXML -b
622
585
=head1 WARNING
623
=head1 WARNING
586
624
587
Don't use this script before you've entered and checked your MARC parameters
625
Don't use this script before you've entered and checked your MARC parameters
588
tables twice (or more!). Otherwise, the import won't work correctly and you
626
tables twice (or more!). Otherwise, the import won't work correctly and you
589
will get invalid data.
627
will get invalid data.
590
628
629
If you want to assign your legacy bibliographic id as the biblionumber and
630
biblioitemnumber in Koha biblio- and bibliotiems -tables, you must first
631
specify the mappings in "Administration" > "Koha to MARC mapping".
632
633
It is extremely recommended to use field $999 to migrate your legacy id's.
634
If you set it to for ex. 001, librarians might manually reuse an existing id.
635
Also make sure that the legacy id is a strict positive integer and less than
636
perl -MPOSIX -le 'print LONG_MAX'.
637
591
=head1 DESCRIPTION
638
=head1 DESCRIPTION
592
639
593
=over
640
=over
Lines 687-692 Field store ids in I<FIELD> (usefull for authorities, where 001 contains the Link Here
687
authid for Koha, that can contain a very valuable info for authorities coming
734
authid for Koha, that can contain a very valuable info for authorities coming
688
from LOC or BNF. useless for biblios probably)
735
from LOC or BNF. useless for biblios probably)
689
736
737
If your legacy id is already in 001, or the field you want it in. Dont use this
738
parameter as it will move the biblionumber from your definition at
739
"Administration" > "Koha to Marc mapping" as a duplicate of your original id.
740
Thus you lose your MARC-field mapped to biblionumber before the record is
741
processed.
742
690
=item B<-match>=<FIELD>
743
=item B<-match>=<FIELD>
691
744
692
I<FIELD> matchindex,fieldtomatch matchpoint to use to deduplicate fieldtomatch
745
I<FIELD> matchindex,fieldtomatch matchpoint to use to deduplicate fieldtomatch
Lines 734-739 This is the code for the framework that the requested records will have attached Link Here
734
to them when they are created. If not specified, then the default framework
787
to them when they are created. If not specified, then the default framework
735
will be used.
788
will be used.
736
789
790
=item B<-g, -legacyIdAsBiblionumberFromHere>=<FIELD>
791
792
If you already have your legacy database id in your marc record and want to
793
preserve it, but still want to get it set as the biblionumber and biblioitemnumber
794
in Kohas database, use this.
795
796
Example:
797
Field 001 has your legacy id.
798
Koha to MARC mapping needs legacy id in 999c and 999d as well for biblionumber
799
and biblioitemnumber, use
800
 -g 001
801
to copy the legacy id to field 999cd and thus get the id preserved in DB.
802
737
=back
803
=back
738
804
739
=cut
805
=cut
(-)a/t/db_dependent/PreserveLegacyId.t (-1 / +150 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!
4
# Add more tests here!!!
5
6
use Modern::Perl;
7
use utf8;
8
9
use Test::More tests => 3;
10
use MARC::Record;
11
12
BEGIN {
13
        use_ok('C4::Record');
14
        use_ok('C4::Biblio');
15
}
16
17
### Preparing our testing data ###
18
my $bibFramework = ''; #Using the default bibliographic framework.
19
my $marcxml=qq(<?xml version="1.0" encoding="UTF-8"?>
20
<record format="MARC21" type="Bibliographic">
21
  <leader>00000cim a22000004a 4500</leader>
22
  <controlfield tag="001">1001</controlfield>
23
  <controlfield tag="005">2013-06-03 07:04:07+02</controlfield>
24
  <controlfield tag="007">ss||||j|||||||</controlfield>
25
  <controlfield tag="008">       uuuu    xxk|||||||||||||||||eng|c</controlfield>
26
  <datafield tag="020" ind1=" " ind2=" ">
27
    <subfield code="a">0-00-103147-3</subfield>
28
    <subfield code="c">14.46 EUR</subfield>
29
  </datafield>
30
  <datafield tag="041" ind1="0" ind2=" ">
31
    <subfield code="d">eng</subfield>
32
  </datafield>
33
  <datafield tag="084" ind1=" " ind2=" ">
34
    <subfield code="a">83.5</subfield>
35
    <subfield code="2">ykl</subfield>
36
  </datafield>
37
  <datafield tag="100" ind1="1" ind2=" ">
38
    <subfield code="a">SHAKESPEARE, WILLIAM.</subfield>
39
  </datafield>
40
  <datafield tag="245" ind1="1" ind2="4">
41
    <subfield code="a">THE TAMING OF THE SHREW /</subfield>
42
    <subfield code="c">WILLIAM SHAKESPEARE</subfield>
43
    <subfield code="h">[ÄÄNITE].</subfield>
44
  </datafield>
45
  <datafield tag="260" ind1=" " ind2=" ">
46
    <subfield code="a">LONDON :</subfield>
47
    <subfield code="b">COLLINS.</subfield>
48
  </datafield>
49
  <datafield tag="300" ind1=" " ind2=" ">
50
    <subfield code="a">2 ÄÄNIKASETTIA.</subfield>
51
  </datafield>
52
  <datafield tag="852" ind1=" " ind2=" ">
53
    <subfield code="a">FI-Jm</subfield>
54
    <subfield code="h">83.5</subfield>
55
  </datafield>
56
  <datafield tag="852" ind1=" " ind2=" ">
57
    <subfield code="a">FI-Konti</subfield>
58
    <subfield code="h">83.5</subfield>
59
  </datafield>
60
</record>
61
);
62
63
my $record=marcxml2marc($marcxml);
64
65
my ( $biblionumberTagid, $biblionumberSubfieldid ) =
66
            GetMarcFromKohaField( "biblio.biblionumber", $bibFramework );
67
my ( $biblioitemnumberTagid, $biblioitemnumberSubfieldid ) =
68
            GetMarcFromKohaField( "biblioitems.biblioitemnumber", $bibFramework );
69
70
# Making sure the Koha to MARC mappings stand correct
71
is ($biblionumberTagid, $biblioitemnumberTagid, 'Testing "Koha to MARC mapping" biblionumber and biblioitemnumber source MARC field sameness');
72
if ($biblionumberTagid ne $biblioitemnumberTagid) {
73
	warn "Koha to MARC mapping values biblio.biblionumber and biblioitems.biblioitemnumber must share the same MARC field!";
74
}
75
76
#Moving the 001 to the field configured for legacy id
77
my $legacyIdField = $record->field( '001' );
78
my $legacyId = $legacyIdField->data();
79
my $biblionumberField = MARC::Field->new( $biblionumberTagid, '', '',
80
   $biblionumberSubfieldid => $legacyId,
81
   $biblioitemnumberSubfieldid => $legacyId,
82
);
83
$record->append_fields($biblionumberField);
84
85
#Convenience method to easily change the legacy id.
86
# Is used to test out database id boundary values.
87
sub changeLegacyId {
88
    my ($record, $newId) = @_;
89
90
    # Because the author of Marc::Record decided it would be nice to replace all subfields with new ones whenever they are updated,
91
    #  old references are lost and need to be found again.
92
    my $legacyIdField = $record->field( '001' );
93
    my $biblionumberField = $record->field( $biblionumberTagid );
94
95
    $legacyIdField->update( $newId );
96
    $biblionumberField->update( $biblionumberSubfieldid => $newId,
97
                                $biblioitemnumberSubfieldid => $newId);
98
    $legacyId = $newId;
99
100
101
}
102
103
##############################
104
### Running the main test! ###
105
##############################
106
107
## INSERT the record to the DB, SELECT the one we got,
108
## then find out if the biblionumber and biblioitemnumbers are the original ones.
109
110
my $dbh = C4::Context->dbh;
111
112
$dbh->{AutoCommit} = 0; #We don't want to save anything in DB as this is just a test run!
113
$dbh->{RaiseError} = 1;
114
115
##Testing just below the critical threshold in _koha_add_item() primary key validators.
116
##  Test should run OK. Also this biblionumber hardly is reserved :)
117
changeLegacyId($record, 2147483639);
118
119
my ( $newBiblionumber, $newBiblioitemnumber ) = AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } );
120
my $selectedBiblio = GetBiblio($legacyId);
121
122
is ($legacyId, $newBiblionumber, 'Biblionumber returned by AddBiblio matches');
123
is ($legacyId, $selectedBiblio->{biblionumber}, 'Biblionumber returned by GetBiblio matches the legacy biblionumber');
124
125
126
##Testing primary key exhaustion situation. Validator should prevent biblionumber or biblioitemnumber INSERTion
127
##  if the value is over the safety threshold 2147483639 == LONG_MAX
128
##  So both tests should fail.
129
changeLegacyId($record, 2147483645);
130
131
( $newBiblionumber, $newBiblioitemnumber ) = AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } );
132
$selectedBiblio = GetBiblio($legacyId);
133
134
isnt ($legacyId, $newBiblionumber, 'Testing primary key exhaustion prevention.');
135
isnt ($legacyId, $selectedBiblio->{biblionumber}, 'Primary key exhausted biblio matching');
136
137
##Testing bad primary key situation. Validator should prevent biblionumber or biblioitemnumber INSERTion
138
##  if the value is not a pure integer/long.
139
##  So both tests should fail.
140
changeLegacyId($record, '12134FAN');
141
142
( $newBiblionumber, $newBiblioitemnumber ) = AddBiblio( $record, $bibFramework, { defer_marc_save => 1 } );
143
$selectedBiblio = GetBiblio($legacyId);
144
145
isnt ($legacyId, $newBiblionumber, 'Testing primary key not-an-integer prevention.');
146
isnt ($legacyId, $selectedBiblio->{biblionumber}, 'Primary key not-an-integer biblio matching');
147
148
149
$dbh->rollback();
150
$dbh->disconnect();

Return to bug 6113