Lines 315-321
sub ModBiblio {
Link Here
|
315 |
# update biblionumber and biblioitemnumber in MARC |
315 |
# update biblionumber and biblioitemnumber in MARC |
316 |
# FIXME - this is assuming a 1 to 1 relationship between |
316 |
# FIXME - this is assuming a 1 to 1 relationship between |
317 |
# biblios and biblioitems |
317 |
# biblios and biblioitems |
318 |
my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?"); |
318 |
my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=? AND deleted_at IS NULL"); |
319 |
$sth->execute($biblionumber); |
319 |
$sth->execute($biblionumber); |
320 |
my ($biblioitemnumber) = $sth->fetchrow; |
320 |
my ($biblioitemnumber) = $sth->fetchrow; |
321 |
$sth->finish(); |
321 |
$sth->finish(); |
Lines 384-390
sub DelBiblio {
Link Here
|
384 |
my $error; # for error handling |
384 |
my $error; # for error handling |
385 |
|
385 |
|
386 |
# First make sure this biblio has no items attached |
386 |
# First make sure this biblio has no items attached |
387 |
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=?"); |
387 |
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=? AND deleted_at IS NULL"); |
388 |
$sth->execute($biblionumber); |
388 |
$sth->execute($biblionumber); |
389 |
if ( my $itemnumber = $sth->fetchrow ) { |
389 |
if ( my $itemnumber = $sth->fetchrow ) { |
390 |
|
390 |
|
Lines 415-421
sub DelBiblio {
Link Here
|
415 |
ModZebra( $biblionumber, "recordDelete", "biblioserver" ); |
415 |
ModZebra( $biblionumber, "recordDelete", "biblioserver" ); |
416 |
|
416 |
|
417 |
# delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems |
417 |
# delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems |
418 |
$sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?"); |
418 |
$sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? AND deleted_at IS NULL"); |
419 |
$sth->execute($biblionumber); |
419 |
$sth->execute($biblionumber); |
420 |
while ( my $biblioitemnumber = $sth->fetchrow ) { |
420 |
while ( my $biblioitemnumber = $sth->fetchrow ) { |
421 |
|
421 |
|
Lines 1174-1180
sub GetMarcBiblio {
Link Here
|
1174 |
} |
1174 |
} |
1175 |
|
1175 |
|
1176 |
my $dbh = C4::Context->dbh; |
1176 |
my $dbh = C4::Context->dbh; |
1177 |
my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? "); |
1177 |
my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? AND deleted_at IS NULL"); |
1178 |
$sth->execute($biblionumber); |
1178 |
$sth->execute($biblionumber); |
1179 |
my $row = $sth->fetchrow_hashref; |
1179 |
my $row = $sth->fetchrow_hashref; |
1180 |
my $biblioitemnumber = $row->{'biblioitemnumber'}; |
1180 |
my $biblioitemnumber = $row->{'biblioitemnumber'}; |
Lines 2797-2803
sub EmbedItemsInMarcBiblio {
Link Here
|
2797 |
|
2797 |
|
2798 |
# ... and embed the current items |
2798 |
# ... and embed the current items |
2799 |
my $dbh = C4::Context->dbh; |
2799 |
my $dbh = C4::Context->dbh; |
2800 |
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); |
2800 |
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ? and deleted_at IS NULL"); |
2801 |
$sth->execute($biblionumber); |
2801 |
$sth->execute($biblionumber); |
2802 |
my @item_fields; |
2802 |
my @item_fields; |
2803 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
2803 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
Lines 3127-3167
C<$biblionumber> - the biblionumber of the biblio to be deleted
Link Here
|
3127 |
sub _koha_delete_biblio { |
3127 |
sub _koha_delete_biblio { |
3128 |
my ( $dbh, $biblionumber ) = @_; |
3128 |
my ( $dbh, $biblionumber ) = @_; |
3129 |
|
3129 |
|
3130 |
# get all the data for this biblio |
3130 |
my $sth = $dbh->prepare("UPDATE biblio SET deleted_at = NOW() WHERE biblionumber=?"); |
3131 |
my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?"); |
3131 |
return $sth->execute($biblionumber) ? undef : ($DBI::errstr || "unknown error"); |
3132 |
$sth->execute($biblionumber); |
|
|
3133 |
|
3134 |
# FIXME There is a transaction in _koha_delete_biblio_metadata |
3135 |
# But actually all the following should be done inside a single transaction |
3136 |
if ( my $data = $sth->fetchrow_hashref ) { |
3137 |
|
3138 |
# save the record in deletedbiblio |
3139 |
# find the fields to save |
3140 |
my $query = "INSERT INTO deletedbiblio SET "; |
3141 |
my @bind = (); |
3142 |
foreach my $temp ( keys %$data ) { |
3143 |
$query .= "$temp = ?,"; |
3144 |
push( @bind, $data->{$temp} ); |
3145 |
} |
3146 |
|
3147 |
# replace the last , by ",?)" |
3148 |
$query =~ s/\,$//; |
3149 |
my $bkup_sth = $dbh->prepare($query); |
3150 |
$bkup_sth->execute(@bind); |
3151 |
$bkup_sth->finish; |
3152 |
|
3153 |
_koha_delete_biblio_metadata( $biblionumber ); |
3154 |
|
3155 |
# delete the biblio |
3156 |
my $sth2 = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?"); |
3157 |
$sth2->execute($biblionumber); |
3158 |
# update the timestamp (Bugzilla 7146) |
3159 |
$sth2= $dbh->prepare("UPDATE deletedbiblio SET timestamp=NOW() WHERE biblionumber=?"); |
3160 |
$sth2->execute($biblionumber); |
3161 |
$sth2->finish; |
3162 |
} |
3163 |
$sth->finish; |
3164 |
return; |
3165 |
} |
3132 |
} |
3166 |
|
3133 |
|
3167 |
=head2 _koha_delete_biblioitems |
3134 |
=head2 _koha_delete_biblioitems |
Lines 3179-3216
C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted
Link Here
|
3179 |
|
3146 |
|
3180 |
sub _koha_delete_biblioitems { |
3147 |
sub _koha_delete_biblioitems { |
3181 |
my ( $dbh, $biblioitemnumber ) = @_; |
3148 |
my ( $dbh, $biblioitemnumber ) = @_; |
3182 |
|
3149 |
my $sth = $dbh->prepare("UPDATE biblioitems SET deleted_at = NOW() WHERE biblioitemnumber=?"); |
3183 |
# get all the data for this biblioitem |
3150 |
return $sth->execute($biblioitemnumber) ? undef : ($DBI::errstr || 'unknown error'); |
3184 |
my $sth = $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?"); |
|
|
3185 |
$sth->execute($biblioitemnumber); |
3186 |
|
3187 |
if ( my $data = $sth->fetchrow_hashref ) { |
3188 |
|
3189 |
# save the record in deletedbiblioitems |
3190 |
# find the fields to save |
3191 |
my $query = "INSERT INTO deletedbiblioitems SET "; |
3192 |
my @bind = (); |
3193 |
foreach my $temp ( keys %$data ) { |
3194 |
$query .= "$temp = ?,"; |
3195 |
push( @bind, $data->{$temp} ); |
3196 |
} |
3197 |
|
3198 |
# replace the last , by ",?)" |
3199 |
$query =~ s/\,$//; |
3200 |
my $bkup_sth = $dbh->prepare($query); |
3201 |
$bkup_sth->execute(@bind); |
3202 |
$bkup_sth->finish; |
3203 |
|
3204 |
# delete the biblioitem |
3205 |
my $sth2 = $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?"); |
3206 |
$sth2->execute($biblioitemnumber); |
3207 |
# update the timestamp (Bugzilla 7146) |
3208 |
$sth2= $dbh->prepare("UPDATE deletedbiblioitems SET timestamp=NOW() WHERE biblioitemnumber=?"); |
3209 |
$sth2->execute($biblioitemnumber); |
3210 |
$sth2->finish; |
3211 |
} |
3212 |
$sth->finish; |
3213 |
return; |
3214 |
} |
3151 |
} |
3215 |
|
3152 |
|
3216 |
=head2 _koha_delete_biblio_metadata |
3153 |
=head2 _koha_delete_biblio_metadata |
Lines 3223-3241
C<$biblionumber> - the biblionumber of the biblio metadata to be deleted
Link Here
|
3223 |
|
3160 |
|
3224 |
sub _koha_delete_biblio_metadata { |
3161 |
sub _koha_delete_biblio_metadata { |
3225 |
my ($biblionumber) = @_; |
3162 |
my ($biblionumber) = @_; |
3226 |
|
3163 |
my $dbh = C4::Context->dbh; |
3227 |
my $dbh = C4::Context->dbh; |
3164 |
my $sth = $dbh->prepare("UPDATE biblio_metadata SET deleted_at = NOW() WHERE biblionumber=?"); |
3228 |
my $schema = Koha::Database->new->schema; |
3165 |
return $sth->execute($biblionumber); |
3229 |
$schema->txn_do( |
|
|
3230 |
sub { |
3231 |
$dbh->do( q| |
3232 |
INSERT INTO deletedbiblio_metadata (biblionumber, format, marcflavour, metadata) |
3233 |
SELECT biblionumber, format, marcflavour, metadata FROM biblio_metadata WHERE biblionumber=? |
3234 |
|, undef, $biblionumber ); |
3235 |
$dbh->do( q|DELETE FROM biblio_metadata WHERE biblionumber=?|, |
3236 |
undef, $biblionumber ); |
3237 |
} |
3238 |
); |
3239 |
} |
3166 |
} |
3240 |
|
3167 |
|
3241 |
=head1 UNEXPORTED FUNCTIONS |
3168 |
=head1 UNEXPORTED FUNCTIONS |