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 1136-1142
sub GetMarcBiblio {
Link Here
|
1136 |
} |
1136 |
} |
1137 |
|
1137 |
|
1138 |
my $dbh = C4::Context->dbh; |
1138 |
my $dbh = C4::Context->dbh; |
1139 |
my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? "); |
1139 |
my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? AND deleted_at IS NULL"); |
1140 |
$sth->execute($biblionumber); |
1140 |
$sth->execute($biblionumber); |
1141 |
my $row = $sth->fetchrow_hashref; |
1141 |
my $row = $sth->fetchrow_hashref; |
1142 |
my $biblioitemnumber = $row->{'biblioitemnumber'}; |
1142 |
my $biblioitemnumber = $row->{'biblioitemnumber'}; |
Lines 2754-2760
sub EmbedItemsInMarcBiblio {
Link Here
|
2754 |
|
2754 |
|
2755 |
# ... and embed the current items |
2755 |
# ... and embed the current items |
2756 |
my $dbh = C4::Context->dbh; |
2756 |
my $dbh = C4::Context->dbh; |
2757 |
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); |
2757 |
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ? and deleted_at IS NULL"); |
2758 |
$sth->execute($biblionumber); |
2758 |
$sth->execute($biblionumber); |
2759 |
my @item_fields; |
2759 |
my @item_fields; |
2760 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
2760 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
Lines 3084-3124
C<$biblionumber> - the biblionumber of the biblio to be deleted
Link Here
|
3084 |
sub _koha_delete_biblio { |
3084 |
sub _koha_delete_biblio { |
3085 |
my ( $dbh, $biblionumber ) = @_; |
3085 |
my ( $dbh, $biblionumber ) = @_; |
3086 |
|
3086 |
|
3087 |
# get all the data for this biblio |
3087 |
my $sth = $dbh->prepare("UPDATE biblio SET deleted_at = NOW() WHERE biblionumber=?"); |
3088 |
my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?"); |
3088 |
return $sth->execute($biblionumber) ? undef : ($DBI::errstr || "unknown error"); |
3089 |
$sth->execute($biblionumber); |
|
|
3090 |
|
3091 |
# FIXME There is a transaction in _koha_delete_biblio_metadata |
3092 |
# But actually all the following should be done inside a single transaction |
3093 |
if ( my $data = $sth->fetchrow_hashref ) { |
3094 |
|
3095 |
# save the record in deletedbiblio |
3096 |
# find the fields to save |
3097 |
my $query = "INSERT INTO deletedbiblio SET "; |
3098 |
my @bind = (); |
3099 |
foreach my $temp ( keys %$data ) { |
3100 |
$query .= "$temp = ?,"; |
3101 |
push( @bind, $data->{$temp} ); |
3102 |
} |
3103 |
|
3104 |
# replace the last , by ",?)" |
3105 |
$query =~ s/\,$//; |
3106 |
my $bkup_sth = $dbh->prepare($query); |
3107 |
$bkup_sth->execute(@bind); |
3108 |
$bkup_sth->finish; |
3109 |
|
3110 |
_koha_delete_biblio_metadata( $biblionumber ); |
3111 |
|
3112 |
# delete the biblio |
3113 |
my $sth2 = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?"); |
3114 |
$sth2->execute($biblionumber); |
3115 |
# update the timestamp (Bugzilla 7146) |
3116 |
$sth2= $dbh->prepare("UPDATE deletedbiblio SET timestamp=NOW() WHERE biblionumber=?"); |
3117 |
$sth2->execute($biblionumber); |
3118 |
$sth2->finish; |
3119 |
} |
3120 |
$sth->finish; |
3121 |
return; |
3122 |
} |
3089 |
} |
3123 |
|
3090 |
|
3124 |
=head2 _koha_delete_biblioitems |
3091 |
=head2 _koha_delete_biblioitems |
Lines 3136-3173
C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted
Link Here
|
3136 |
|
3103 |
|
3137 |
sub _koha_delete_biblioitems { |
3104 |
sub _koha_delete_biblioitems { |
3138 |
my ( $dbh, $biblioitemnumber ) = @_; |
3105 |
my ( $dbh, $biblioitemnumber ) = @_; |
3139 |
|
3106 |
my $sth = $dbh->prepare("UPDATE biblioitems SET deleted_at = NOW() WHERE biblioitemnumber=?"); |
3140 |
# get all the data for this biblioitem |
3107 |
return $sth->execute($biblioitemnumber) ? undef : ($DBI::errstr || 'unknown error'); |
3141 |
my $sth = $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?"); |
|
|
3142 |
$sth->execute($biblioitemnumber); |
3143 |
|
3144 |
if ( my $data = $sth->fetchrow_hashref ) { |
3145 |
|
3146 |
# save the record in deletedbiblioitems |
3147 |
# find the fields to save |
3148 |
my $query = "INSERT INTO deletedbiblioitems SET "; |
3149 |
my @bind = (); |
3150 |
foreach my $temp ( keys %$data ) { |
3151 |
$query .= "$temp = ?,"; |
3152 |
push( @bind, $data->{$temp} ); |
3153 |
} |
3154 |
|
3155 |
# replace the last , by ",?)" |
3156 |
$query =~ s/\,$//; |
3157 |
my $bkup_sth = $dbh->prepare($query); |
3158 |
$bkup_sth->execute(@bind); |
3159 |
$bkup_sth->finish; |
3160 |
|
3161 |
# delete the biblioitem |
3162 |
my $sth2 = $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?"); |
3163 |
$sth2->execute($biblioitemnumber); |
3164 |
# update the timestamp (Bugzilla 7146) |
3165 |
$sth2= $dbh->prepare("UPDATE deletedbiblioitems SET timestamp=NOW() WHERE biblioitemnumber=?"); |
3166 |
$sth2->execute($biblioitemnumber); |
3167 |
$sth2->finish; |
3168 |
} |
3169 |
$sth->finish; |
3170 |
return; |
3171 |
} |
3108 |
} |
3172 |
|
3109 |
|
3173 |
=head2 _koha_delete_biblio_metadata |
3110 |
=head2 _koha_delete_biblio_metadata |
Lines 3180-3198
C<$biblionumber> - the biblionumber of the biblio metadata to be deleted
Link Here
|
3180 |
|
3117 |
|
3181 |
sub _koha_delete_biblio_metadata { |
3118 |
sub _koha_delete_biblio_metadata { |
3182 |
my ($biblionumber) = @_; |
3119 |
my ($biblionumber) = @_; |
3183 |
|
3120 |
my $dbh = C4::Context->dbh; |
3184 |
my $dbh = C4::Context->dbh; |
3121 |
my $sth = $dbh->prepare("UPDATE biblio_metadata SET deleted_at = NOW() WHERE biblionumber=?"); |
3185 |
my $schema = Koha::Database->new->schema; |
3122 |
return $sth->execute($biblionumber); |
3186 |
$schema->txn_do( |
|
|
3187 |
sub { |
3188 |
$dbh->do( q| |
3189 |
INSERT INTO deletedbiblio_metadata (biblionumber, format, marcflavour, metadata) |
3190 |
SELECT biblionumber, format, marcflavour, metadata FROM biblio_metadata WHERE biblionumber=? |
3191 |
|, undef, $biblionumber ); |
3192 |
$dbh->do( q|DELETE FROM biblio_metadata WHERE biblionumber=?|, |
3193 |
undef, $biblionumber ); |
3194 |
} |
3195 |
); |
3196 |
} |
3123 |
} |
3197 |
|
3124 |
|
3198 |
=head1 UNEXPORTED FUNCTIONS |
3125 |
=head1 UNEXPORTED FUNCTIONS |