Lines 2944-2952
sub _koha_add_biblio {
Link Here
|
2944 |
$biblio->{'serial'} = 0; |
2944 |
$biblio->{'serial'} = 0; |
2945 |
if ( $biblio->{'seriestitle'} ) { $biblio->{'serial'} = 1 } |
2945 |
if ( $biblio->{'seriestitle'} ) { $biblio->{'serial'} = 1 } |
2946 |
} |
2946 |
} |
|
|
2947 |
|
2948 |
### Validating biblionumber. |
2949 |
my $biblionumber; |
2950 |
my $isBiblioNumberOk = ''; #placeholder for the sql-clause which inserts biblionumber |
2951 |
if (exists $biblio->{'biblionumber'}) { |
2952 |
$biblionumber = $biblio->{'biblionumber'}; |
2953 |
if (! ($biblionumber =~ /^\d+$/) ) { |
2954 |
$error .= "C4::Biblio::_koha_add_biblio():> Biblionumber $biblionumber is not a number! Using a new biblionumber\n"; |
2955 |
} |
2956 |
elsif (! ($biblionumber > 0)) { |
2957 |
$error .= "C4::Biblio::_koha_add_biblio():> Biblionumber $biblionumber is not greater than 0! Using a new biblionumber\n"; |
2958 |
} |
2959 |
#The real Perl LONG_MAX is 2147483646, but using 2147483640 |
2960 |
# so we can detect the imminent primary key exhaustion before it actually is exhausted. |
2961 |
elsif (! ($biblionumber < 2147483640)) { |
2962 |
$error .= "C4::Biblio::_koha_add_biblio():> Biblionumber $biblionumber is too large for Perl! Using a new biblionumber\n"; |
2963 |
} |
2964 |
else { |
2965 |
#We have validated the biblionumber and can prepare to insert it. |
2966 |
$isBiblioNumberOk = 'biblionumber = ?,'; |
2967 |
} |
2968 |
|
2969 |
} |
2947 |
|
2970 |
|
2948 |
my $query = "INSERT INTO biblio |
2971 |
my $query = "INSERT INTO biblio |
2949 |
SET frameworkcode = ?, |
2972 |
SET frameworkcode = ?, |
|
|
2973 |
$isBiblioNumberOk |
2950 |
author = ?, |
2974 |
author = ?, |
2951 |
title = ?, |
2975 |
title = ?, |
2952 |
unititle =?, |
2976 |
unititle =?, |
Lines 2958-2973
sub _koha_add_biblio {
Link Here
|
2958 |
abstract = ? |
2982 |
abstract = ? |
2959 |
"; |
2983 |
"; |
2960 |
my $sth = $dbh->prepare($query); |
2984 |
my $sth = $dbh->prepare($query); |
2961 |
$sth->execute( |
2985 |
|
2962 |
$frameworkcode, $biblio->{'author'}, $biblio->{'title'}, $biblio->{'unititle'}, $biblio->{'notes'}, |
2986 |
if ($isBiblioNumberOk) { |
2963 |
$biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'} |
2987 |
$sth->execute( |
2964 |
); |
2988 |
$frameworkcode, $biblionumber, $biblio->{'author'}, $biblio->{'title'}, $biblio->{'unititle'}, $biblio->{'notes'}, |
|
|
2989 |
$biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'} |
2990 |
); |
2991 |
} |
2992 |
else { |
2993 |
$sth->execute( |
2994 |
$frameworkcode, $biblio->{'author'}, $biblio->{'title'}, $biblio->{'unititle'}, $biblio->{'notes'}, |
2995 |
$biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'} |
2996 |
); |
2997 |
} |
2998 |
|
2965 |
|
2999 |
|
2966 |
my $biblionumber = $dbh->{'mysql_insertid'}; |
3000 |
$biblionumber = $isBiblioNumberOk ? $biblionumber : $dbh->{'mysql_insertid'}; |
2967 |
if ( $dbh->errstr ) { |
3001 |
if ( $dbh->errstr ) { |
2968 |
$error .= "ERROR in _koha_add_biblio $query" . $dbh->errstr; |
3002 |
$error .= "ERROR in _koha_add_biblio $query" . $dbh->errstr; |
|
|
3003 |
} |
3004 |
|
3005 |
|
3006 |
if (defined $error) { |
2969 |
warn $error; |
3007 |
warn $error; |
2970 |
} |
3008 |
} |
|
|
3009 |
|
2971 |
|
3010 |
|
2972 |
$sth->finish(); |
3011 |
$sth->finish(); |
2973 |
|
3012 |
|
Lines 3093-3101
Internal function to add a biblioitem
Link Here
|
3093 |
sub _koha_add_biblioitem { |
3132 |
sub _koha_add_biblioitem { |
3094 |
my ( $dbh, $biblioitem ) = @_; |
3133 |
my ( $dbh, $biblioitem ) = @_; |
3095 |
my $error; |
3134 |
my $error; |
|
|
3135 |
|
3136 |
### Validating biblionumber. |
3137 |
my $biblioitemnumber; |
3138 |
my $isBiblioitemNumberOk = ''; #placeholder for the sql-clause which inserts biblionumber |
3139 |
if (exists $biblioitem->{'biblioitemnumber'}) { |
3140 |
$biblioitemnumber = $biblioitem->{'biblioitemnumber'}; |
3141 |
if (! ($biblioitemnumber =~ /^\d+$/) ) { |
3142 |
$error .= "C4::Biblio::_koha_add_biblioitem():> biblioitemnumber $biblioitemnumber is not a number! Using a new biblioitemnumber\n"; |
3143 |
} |
3144 |
elsif (! ($biblioitemnumber > 0)) { |
3145 |
$error .= "C4::Biblio::_koha_add_biblioitem():> biblioitemnumber $biblioitemnumber is not greater than 0! Using a new biblioitemnumber\n"; |
3146 |
} |
3147 |
#The real Perl LONG_MAX is 2147483646, but using 2147483640 |
3148 |
# so we can detect the imminent primary key exhaustion before it actually is exhausted. |
3149 |
elsif (! ($biblioitemnumber < 2147483640)) { |
3150 |
$error .= "C4::Biblio::_koha_add_biblioitem():> biblioitemnumber $biblioitemnumber is too large for Perl! Using a new biblioitemnumber\n"; |
3151 |
} |
3152 |
else { |
3153 |
#We have validated the biblionumber and can prepare to insert it. |
3154 |
$isBiblioitemNumberOk = 'biblioitemnumber = ?,'; |
3155 |
} |
3156 |
|
3157 |
} |
3096 |
|
3158 |
|
3097 |
my ($cn_sort) = GetClassSort( $biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} ); |
3159 |
my ($cn_sort) = GetClassSort( $biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} ); |
3098 |
my $query = "INSERT INTO biblioitems SET |
3160 |
my $query = "INSERT INTO biblioitems SET |
|
|
3161 |
$isBiblioitemNumberOk |
3099 |
biblionumber = ?, |
3162 |
biblionumber = ?, |
3100 |
volume = ?, |
3163 |
volume = ?, |
3101 |
number = ?, |
3164 |
number = ?, |
Lines 3129-3152
sub _koha_add_biblioitem {
Link Here
|
3129 |
agerestriction = ? |
3192 |
agerestriction = ? |
3130 |
"; |
3193 |
"; |
3131 |
my $sth = $dbh->prepare($query); |
3194 |
my $sth = $dbh->prepare($query); |
3132 |
$sth->execute( |
3195 |
|
3133 |
$biblioitem->{'biblionumber'}, $biblioitem->{'volume'}, $biblioitem->{'number'}, $biblioitem->{'itemtype'}, |
3196 |
if ($isBiblioitemNumberOk) { |
3134 |
$biblioitem->{'isbn'}, $biblioitem->{'issn'}, $biblioitem->{'publicationyear'}, $biblioitem->{'publishercode'}, |
3197 |
$sth->execute( |
3135 |
$biblioitem->{'volumedate'}, $biblioitem->{'volumedesc'}, $biblioitem->{'collectiontitle'}, $biblioitem->{'collectionissn'}, |
3198 |
$biblioitem->{'biblioitemnumber'}, |
3136 |
$biblioitem->{'collectionvolume'}, $biblioitem->{'editionstatement'}, $biblioitem->{'editionresponsibility'}, $biblioitem->{'illus'}, |
3199 |
$biblioitem->{'biblionumber'}, $biblioitem->{'volume'}, $biblioitem->{'number'}, $biblioitem->{'itemtype'}, |
3137 |
$biblioitem->{'pages'}, $biblioitem->{'bnotes'}, $biblioitem->{'size'}, $biblioitem->{'place'}, |
3200 |
$biblioitem->{'isbn'}, $biblioitem->{'issn'}, $biblioitem->{'publicationyear'}, $biblioitem->{'publishercode'}, |
3138 |
$biblioitem->{'lccn'}, $biblioitem->{'marc'}, $biblioitem->{'url'}, $biblioitem->{'biblioitems.cn_source'}, |
3201 |
$biblioitem->{'volumedate'}, $biblioitem->{'volumedesc'}, $biblioitem->{'collectiontitle'}, $biblioitem->{'collectionissn'}, |
3139 |
$biblioitem->{'cn_class'}, $biblioitem->{'cn_item'}, $biblioitem->{'cn_suffix'}, $cn_sort, |
3202 |
$biblioitem->{'collectionvolume'}, $biblioitem->{'editionstatement'}, $biblioitem->{'editionresponsibility'}, $biblioitem->{'illus'}, |
3140 |
$biblioitem->{'totalissues'}, $biblioitem->{'ean'}, $biblioitem->{'agerestriction'} |
3203 |
$biblioitem->{'pages'}, $biblioitem->{'bnotes'}, $biblioitem->{'size'}, $biblioitem->{'place'}, |
3141 |
); |
3204 |
$biblioitem->{'lccn'}, $biblioitem->{'marc'}, $biblioitem->{'url'}, $biblioitem->{'biblioitems.cn_source'}, |
3142 |
my $bibitemnum = $dbh->{'mysql_insertid'}; |
3205 |
$biblioitem->{'cn_class'}, $biblioitem->{'cn_item'}, $biblioitem->{'cn_suffix'}, $cn_sort, |
|
|
3206 |
$biblioitem->{'totalissues'}, $biblioitem->{'ean'}, $biblioitem->{'agerestriction'} |
3207 |
); |
3208 |
} |
3209 |
else { |
3210 |
$sth->execute( |
3211 |
$biblioitem->{'biblionumber'}, $biblioitem->{'volume'}, $biblioitem->{'number'}, $biblioitem->{'itemtype'}, |
3212 |
$biblioitem->{'isbn'}, $biblioitem->{'issn'}, $biblioitem->{'publicationyear'}, $biblioitem->{'publishercode'}, |
3213 |
$biblioitem->{'volumedate'}, $biblioitem->{'volumedesc'}, $biblioitem->{'collectiontitle'}, $biblioitem->{'collectionissn'}, |
3214 |
$biblioitem->{'collectionvolume'}, $biblioitem->{'editionstatement'}, $biblioitem->{'editionresponsibility'}, $biblioitem->{'illus'}, |
3215 |
$biblioitem->{'pages'}, $biblioitem->{'bnotes'}, $biblioitem->{'size'}, $biblioitem->{'place'}, |
3216 |
$biblioitem->{'lccn'}, $biblioitem->{'marc'}, $biblioitem->{'url'}, $biblioitem->{'biblioitems.cn_source'}, |
3217 |
$biblioitem->{'cn_class'}, $biblioitem->{'cn_item'}, $biblioitem->{'cn_suffix'}, $cn_sort, |
3218 |
$biblioitem->{'totalissues'}, $biblioitem->{'ean'}, $biblioitem->{'agerestriction'} |
3219 |
); |
3220 |
} |
3221 |
|
3222 |
$biblioitemnumber = $isBiblioitemNumberOk ? $biblioitemnumber : $dbh->{'mysql_insertid'}; |
3143 |
|
3223 |
|
3144 |
if ( $dbh->errstr ) { |
3224 |
if ( $dbh->errstr ) { |
3145 |
$error .= "ERROR in _koha_add_biblioitem $query" . $dbh->errstr; |
3225 |
$error .= "ERROR in _koha_add_biblioitem $query" . $dbh->errstr; |
|
|
3226 |
} |
3227 |
|
3228 |
if (defined $error) { |
3146 |
warn $error; |
3229 |
warn $error; |
3147 |
} |
3230 |
} |
|
|
3231 |
|
3148 |
$sth->finish(); |
3232 |
$sth->finish(); |
3149 |
return ( $bibitemnum, $error ); |
3233 |
return ( $biblioitemnumber, $error ); |
3150 |
} |
3234 |
} |
3151 |
|
3235 |
|
3152 |
=head2 _koha_delete_biblio |
3236 |
=head2 _koha_delete_biblio |