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 |