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