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 1138-1144
sub GetMarcBiblio {
Link Here
|
1138 |
} |
1138 |
} |
1139 |
|
1139 |
|
1140 |
my $dbh = C4::Context->dbh; |
1140 |
my $dbh = C4::Context->dbh; |
1141 |
my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? "); |
1141 |
my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? AND deleted_at IS NULL"); |
1142 |
$sth->execute($biblionumber); |
1142 |
$sth->execute($biblionumber); |
1143 |
my $row = $sth->fetchrow_hashref; |
1143 |
my $row = $sth->fetchrow_hashref; |
1144 |
my $biblioitemnumber = $row->{'biblioitemnumber'}; |
1144 |
my $biblioitemnumber = $row->{'biblioitemnumber'}; |
Lines 2761-2767
sub EmbedItemsInMarcBiblio {
Link Here
|
2761 |
|
2761 |
|
2762 |
# ... and embed the current items |
2762 |
# ... and embed the current items |
2763 |
my $dbh = C4::Context->dbh; |
2763 |
my $dbh = C4::Context->dbh; |
2764 |
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); |
2764 |
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ? and deleted_at IS NULL"); |
2765 |
$sth->execute($biblionumber); |
2765 |
$sth->execute($biblionumber); |
2766 |
my @item_fields; |
2766 |
my @item_fields; |
2767 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
2767 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
Lines 3091-3131
C<$biblionumber> - the biblionumber of the biblio to be deleted
Link Here
|
3091 |
sub _koha_delete_biblio { |
3091 |
sub _koha_delete_biblio { |
3092 |
my ( $dbh, $biblionumber ) = @_; |
3092 |
my ( $dbh, $biblionumber ) = @_; |
3093 |
|
3093 |
|
3094 |
# get all the data for this biblio |
3094 |
my $sth = $dbh->prepare("UPDATE biblio SET deleted_at = NOW() WHERE biblionumber=?"); |
3095 |
my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?"); |
3095 |
return $sth->execute($biblionumber) ? undef : ($DBI::errstr || "unknown error"); |
3096 |
$sth->execute($biblionumber); |
|
|
3097 |
|
3098 |
# FIXME There is a transaction in _koha_delete_biblio_metadata |
3099 |
# But actually all the following should be done inside a single transaction |
3100 |
if ( my $data = $sth->fetchrow_hashref ) { |
3101 |
|
3102 |
# save the record in deletedbiblio |
3103 |
# find the fields to save |
3104 |
my $query = "INSERT INTO deletedbiblio SET "; |
3105 |
my @bind = (); |
3106 |
foreach my $temp ( keys %$data ) { |
3107 |
$query .= "$temp = ?,"; |
3108 |
push( @bind, $data->{$temp} ); |
3109 |
} |
3110 |
|
3111 |
# replace the last , by ",?)" |
3112 |
$query =~ s/\,$//; |
3113 |
my $bkup_sth = $dbh->prepare($query); |
3114 |
$bkup_sth->execute(@bind); |
3115 |
$bkup_sth->finish; |
3116 |
|
3117 |
_koha_delete_biblio_metadata( $biblionumber ); |
3118 |
|
3119 |
# delete the biblio |
3120 |
my $sth2 = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?"); |
3121 |
$sth2->execute($biblionumber); |
3122 |
# update the timestamp (Bugzilla 7146) |
3123 |
$sth2= $dbh->prepare("UPDATE deletedbiblio SET timestamp=NOW() WHERE biblionumber=?"); |
3124 |
$sth2->execute($biblionumber); |
3125 |
$sth2->finish; |
3126 |
} |
3127 |
$sth->finish; |
3128 |
return; |
3129 |
} |
3096 |
} |
3130 |
|
3097 |
|
3131 |
=head2 _koha_delete_biblioitems |
3098 |
=head2 _koha_delete_biblioitems |
Lines 3143-3180
C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted
Link Here
|
3143 |
|
3110 |
|
3144 |
sub _koha_delete_biblioitems { |
3111 |
sub _koha_delete_biblioitems { |
3145 |
my ( $dbh, $biblioitemnumber ) = @_; |
3112 |
my ( $dbh, $biblioitemnumber ) = @_; |
3146 |
|
3113 |
my $sth = $dbh->prepare("UPDATE biblioitems SET deleted_at = NOW() WHERE biblioitemnumber=?"); |
3147 |
# get all the data for this biblioitem |
3114 |
return $sth->execute($biblioitemnumber) ? undef : ($DBI::errstr || 'unknown error'); |
3148 |
my $sth = $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?"); |
|
|
3149 |
$sth->execute($biblioitemnumber); |
3150 |
|
3151 |
if ( my $data = $sth->fetchrow_hashref ) { |
3152 |
|
3153 |
# save the record in deletedbiblioitems |
3154 |
# find the fields to save |
3155 |
my $query = "INSERT INTO deletedbiblioitems SET "; |
3156 |
my @bind = (); |
3157 |
foreach my $temp ( keys %$data ) { |
3158 |
$query .= "$temp = ?,"; |
3159 |
push( @bind, $data->{$temp} ); |
3160 |
} |
3161 |
|
3162 |
# replace the last , by ",?)" |
3163 |
$query =~ s/\,$//; |
3164 |
my $bkup_sth = $dbh->prepare($query); |
3165 |
$bkup_sth->execute(@bind); |
3166 |
$bkup_sth->finish; |
3167 |
|
3168 |
# delete the biblioitem |
3169 |
my $sth2 = $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?"); |
3170 |
$sth2->execute($biblioitemnumber); |
3171 |
# update the timestamp (Bugzilla 7146) |
3172 |
$sth2= $dbh->prepare("UPDATE deletedbiblioitems SET timestamp=NOW() WHERE biblioitemnumber=?"); |
3173 |
$sth2->execute($biblioitemnumber); |
3174 |
$sth2->finish; |
3175 |
} |
3176 |
$sth->finish; |
3177 |
return; |
3178 |
} |
3115 |
} |
3179 |
|
3116 |
|
3180 |
=head2 _koha_delete_biblio_metadata |
3117 |
=head2 _koha_delete_biblio_metadata |
Lines 3187-3205
C<$biblionumber> - the biblionumber of the biblio metadata to be deleted
Link Here
|
3187 |
|
3124 |
|
3188 |
sub _koha_delete_biblio_metadata { |
3125 |
sub _koha_delete_biblio_metadata { |
3189 |
my ($biblionumber) = @_; |
3126 |
my ($biblionumber) = @_; |
3190 |
|
3127 |
my $dbh = C4::Context->dbh; |
3191 |
my $dbh = C4::Context->dbh; |
3128 |
my $sth = $dbh->prepare("UPDATE biblio_metadata SET deleted_at = NOW() WHERE biblionumber=?"); |
3192 |
my $schema = Koha::Database->new->schema; |
3129 |
return $sth->execute($biblionumber); |
3193 |
$schema->txn_do( |
|
|
3194 |
sub { |
3195 |
$dbh->do( q| |
3196 |
INSERT INTO deletedbiblio_metadata (biblionumber, format, marcflavour, metadata) |
3197 |
SELECT biblionumber, format, marcflavour, metadata FROM biblio_metadata WHERE biblionumber=? |
3198 |
|, undef, $biblionumber ); |
3199 |
$dbh->do( q|DELETE FROM biblio_metadata WHERE biblionumber=?|, |
3200 |
undef, $biblionumber ); |
3201 |
} |
3202 |
); |
3203 |
} |
3130 |
} |
3204 |
|
3131 |
|
3205 |
=head1 UNEXPORTED FUNCTIONS |
3132 |
=head1 UNEXPORTED FUNCTIONS |