Commits (1)
...@@ -2291,10 +2291,10 @@ sub GetHistory { ...@@ -2291,10 +2291,10 @@ sub GetHistory {
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $query =" my $query ="
SELECT SELECT
COALESCE(biblio.title, deletedbiblio.title) AS title, biblio.title,
COALESCE(biblio.author, deletedbiblio.author) AS author, biblio.author,
COALESCE(biblioitems.isbn, deletedbiblioitems.isbn) AS isbn, biblioitems.isbn,
COALESCE(biblioitems.ean, deletedbiblioitems.ean) AS ean, biblioitems.ean,
aqorders.basketno, aqorders.basketno,
aqbasket.basketname, aqbasket.basketname,
aqbasket.basketgroupid, aqbasket.basketgroupid,
...@@ -2326,8 +2326,6 @@ sub GetHistory { ...@@ -2326,8 +2326,6 @@ sub GetHistory {
LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
LEFT JOIN aqbudgets ON aqorders.budget_id=aqbudgets.budget_id LEFT JOIN aqbudgets ON aqorders.budget_id=aqbudgets.budget_id
LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid
LEFT JOIN deletedbiblio ON deletedbiblio.biblionumber=aqorders.biblionumber
LEFT JOIN deletedbiblioitems ON deletedbiblioitems.biblionumber=aqorders.biblionumber
LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
"; ";
......
...@@ -318,7 +318,7 @@ sub ModBiblio { ...@@ -318,7 +318,7 @@ sub ModBiblio {
# update biblionumber and biblioitemnumber in MARC # update biblionumber and biblioitemnumber in MARC
# FIXME - this is assuming a 1 to 1 relationship between # FIXME - this is assuming a 1 to 1 relationship between
# biblios and biblioitems # biblios and biblioitems
my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?"); my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=? AND deleted_at IS NULL");
$sth->execute($biblionumber); $sth->execute($biblionumber);
my ($biblioitemnumber) = $sth->fetchrow; my ($biblioitemnumber) = $sth->fetchrow;
$sth->finish(); $sth->finish();
...@@ -387,7 +387,7 @@ sub DelBiblio { ...@@ -387,7 +387,7 @@ sub DelBiblio {
my $error; # for error handling my $error; # for error handling
# First make sure this biblio has no items attached # First make sure this biblio has no items attached
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=?"); my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=? AND deleted_at IS NULL");
$sth->execute($biblionumber); $sth->execute($biblionumber);
if ( my $itemnumber = $sth->fetchrow ) { if ( my $itemnumber = $sth->fetchrow ) {
...@@ -418,7 +418,7 @@ sub DelBiblio { ...@@ -418,7 +418,7 @@ sub DelBiblio {
ModZebra( $biblionumber, "recordDelete", "biblioserver" ); ModZebra( $biblionumber, "recordDelete", "biblioserver" );
# delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
$sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?"); $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? AND deleted_at IS NULL");
$sth->execute($biblionumber); $sth->execute($biblionumber);
while ( my $biblioitemnumber = $sth->fetchrow ) { while ( my $biblioitemnumber = $sth->fetchrow ) {
...@@ -759,7 +759,7 @@ NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebr ...@@ -759,7 +759,7 @@ NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebr
sub GetBiblioItemByBiblioNumber { sub GetBiblioItemByBiblioNumber {
my ($biblionumber) = @_; my ($biblionumber) = @_;
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("Select * FROM biblioitems WHERE biblionumber = ?"); my $sth = $dbh->prepare("Select * FROM biblioitems WHERE biblionumber = ? AND deleted_at IS NULL");
my $count = 0; my $count = 0;
my @results; my @results;
...@@ -1212,7 +1212,7 @@ sub GetMarcBiblio { ...@@ -1212,7 +1212,7 @@ sub GetMarcBiblio {
} }
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? "); my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? AND deleted_at IS NULL");
$sth->execute($biblionumber); $sth->execute($biblionumber);
my $row = $sth->fetchrow_hashref; my $row = $sth->fetchrow_hashref;
my $biblioitemnumber = $row->{'biblioitemnumber'}; my $biblioitemnumber = $row->{'biblioitemnumber'};
...@@ -2830,7 +2830,7 @@ sub EmbedItemsInMarcBiblio { ...@@ -2830,7 +2830,7 @@ sub EmbedItemsInMarcBiblio {
# ... and embed the current items # ... and embed the current items
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ? and deleted_at IS NULL");
$sth->execute($biblionumber); $sth->execute($biblionumber);
my @item_fields; my @item_fields;
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
...@@ -3160,41 +3160,8 @@ C<$biblionumber> - the biblionumber of the biblio to be deleted ...@@ -3160,41 +3160,8 @@ C<$biblionumber> - the biblionumber of the biblio to be deleted
sub _koha_delete_biblio { sub _koha_delete_biblio {
my ( $dbh, $biblionumber ) = @_; my ( $dbh, $biblionumber ) = @_;
# get all the data for this biblio my $sth = $dbh->prepare("UPDATE biblio SET deleted_at = NOW() WHERE biblionumber=?");
my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?"); return $sth->execute($biblionumber) ? undef : ($DBI::errstr || "unknown error");
$sth->execute($biblionumber);
# FIXME There is a transaction in _koha_delete_biblio_metadata
# But actually all the following should be done inside a single transaction
if ( my $data = $sth->fetchrow_hashref ) {
# save the record in deletedbiblio
# find the fields to save
my $query = "INSERT INTO deletedbiblio SET ";
my @bind = ();
foreach my $temp ( keys %$data ) {
$query .= "$temp = ?,";
push( @bind, $data->{$temp} );
}
# replace the last , by ",?)"
$query =~ s/\,$//;
my $bkup_sth = $dbh->prepare($query);
$bkup_sth->execute(@bind);
$bkup_sth->finish;
_koha_delete_biblio_metadata( $biblionumber );
# delete the biblio
my $sth2 = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?");
$sth2->execute($biblionumber);
# update the timestamp (Bugzilla 7146)
$sth2= $dbh->prepare("UPDATE deletedbiblio SET timestamp=NOW() WHERE biblionumber=?");
$sth2->execute($biblionumber);
$sth2->finish;
}
$sth->finish;
return;
} }
=head2 _koha_delete_biblioitems =head2 _koha_delete_biblioitems
...@@ -3212,38 +3179,8 @@ C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted ...@@ -3212,38 +3179,8 @@ C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted
sub _koha_delete_biblioitems { sub _koha_delete_biblioitems {
my ( $dbh, $biblioitemnumber ) = @_; my ( $dbh, $biblioitemnumber ) = @_;
my $sth = $dbh->prepare("UPDATE biblioitems SET deleted_at = NOW() WHERE biblioitemnumber=?");
# get all the data for this biblioitem return $sth->execute($biblioitemnumber) ? undef : ($DBI::errstr || 'unknown error');
my $sth = $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?");
$sth->execute($biblioitemnumber);
if ( my $data = $sth->fetchrow_hashref ) {
# save the record in deletedbiblioitems
# find the fields to save
my $query = "INSERT INTO deletedbiblioitems SET ";
my @bind = ();
foreach my $temp ( keys %$data ) {
$query .= "$temp = ?,";
push( @bind, $data->{$temp} );
}
# replace the last , by ",?)"
$query =~ s/\,$//;
my $bkup_sth = $dbh->prepare($query);
$bkup_sth->execute(@bind);
$bkup_sth->finish;
# delete the biblioitem
my $sth2 = $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?");
$sth2->execute($biblioitemnumber);
# update the timestamp (Bugzilla 7146)
$sth2= $dbh->prepare("UPDATE deletedbiblioitems SET timestamp=NOW() WHERE biblioitemnumber=?");
$sth2->execute($biblioitemnumber);
$sth2->finish;
}
$sth->finish;
return;
} }
=head2 _koha_delete_biblio_metadata =head2 _koha_delete_biblio_metadata
...@@ -3256,19 +3193,9 @@ C<$biblionumber> - the biblionumber of the biblio metadata to be deleted ...@@ -3256,19 +3193,9 @@ C<$biblionumber> - the biblionumber of the biblio metadata to be deleted
sub _koha_delete_biblio_metadata { sub _koha_delete_biblio_metadata {
my ($biblionumber) = @_; my ($biblionumber) = @_;
my $dbh = C4::Context->dbh;
my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("UPDATE biblio_metadata SET deleted_at = NOW() WHERE biblionumber=?");
my $schema = Koha::Database->new->schema; return $sth->execute($biblionumber);
$schema->txn_do(
sub {
$dbh->do( q|
INSERT INTO deletedbiblio_metadata (biblionumber, format, marcflavour, metadata)
SELECT biblionumber, format, marcflavour, metadata FROM biblio_metadata WHERE biblionumber=?
|, undef, $biblionumber );
$dbh->do( q|DELETE FROM biblio_metadata WHERE biblionumber=?|,
undef, $biblionumber );
}
);
} }
=head1 UNEXPORTED FUNCTIONS =head1 UNEXPORTED FUNCTIONS
......
...@@ -830,6 +830,7 @@ sub GetItemsForInventory { ...@@ -830,6 +830,7 @@ sub GetItemsForInventory {
FROM items FROM items
LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber
WHERE items.deleted_at IS NULL
}; };
if ($statushash){ if ($statushash){
for my $authvfield (keys %$statushash){ for my $authvfield (keys %$statushash){
...@@ -936,7 +937,7 @@ Called by C<C4::XISBN> ...@@ -936,7 +937,7 @@ Called by C<C4::XISBN>
sub GetItemsByBiblioitemnumber { sub GetItemsByBiblioitemnumber {
my ( $bibitem ) = @_; my ( $bibitem ) = @_;
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("SELECT * FROM items WHERE items.biblioitemnumber = ?") || die $dbh->errstr; my $sth = $dbh->prepare("SELECT * FROM items WHERE items.biblioitemnumber = ? AND items.deleted_at IS NULL") || die $dbh->errstr;
# Get all items attached to a biblioitem # Get all items attached to a biblioitem
my $i = 0; my $i = 0;
my @results; my @results;
...@@ -1060,7 +1061,7 @@ sub GetItemsInfo { ...@@ -1060,7 +1061,7 @@ sub GetItemsInfo {
FROM items FROM items
LEFT JOIN branches AS holding ON items.holdingbranch = holding.branchcode LEFT JOIN branches AS holding ON items.holdingbranch = holding.branchcode
LEFT JOIN branches AS home ON items.homebranch=home.branchcode LEFT JOIN branches AS home ON items.homebranch=home.branchcode
LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber AND biblio.deleted_at IS NULL
LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
LEFT JOIN issues USING (itemnumber) LEFT JOIN issues USING (itemnumber)
LEFT JOIN borrowers USING (borrowernumber) LEFT JOIN borrowers USING (borrowernumber)
...@@ -1074,7 +1075,7 @@ sub GetItemsInfo { ...@@ -1074,7 +1075,7 @@ sub GetItemsInfo {
AND localization.lang = ? AND localization.lang = ?
|; |;
$query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ; $query .= " WHERE items.biblionumber = ? AND items.deleted_at IS NULL ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
my $sth = $dbh->prepare($query); my $sth = $dbh->prepare($query);
$sth->execute($language, $biblionumber); $sth->execute($language, $biblionumber);
my $i = 0; my $i = 0;
...@@ -1181,7 +1182,7 @@ sub GetItemsLocationInfo { ...@@ -1181,7 +1182,7 @@ sub GetItemsLocationInfo {
location, itemcallnumber, cn_sort location, itemcallnumber, cn_sort
FROM items, branches as a, branches as b FROM items, branches as a, branches as b
WHERE homebranch = a.branchcode AND holdingbranch = b.branchcode WHERE homebranch = a.branchcode AND holdingbranch = b.branchcode
AND biblionumber = ? AND biblionumber = ? AND deleted_at IS NULL
ORDER BY cn_sort ASC"; ORDER BY cn_sort ASC";
my $sth = $dbh->prepare($query); my $sth = $dbh->prepare($query);
$sth->execute($biblionumber); $sth->execute($biblionumber);
...@@ -1253,7 +1254,7 @@ sub GetLastAcquisitions { ...@@ -1253,7 +1254,7 @@ sub GetLastAcquisitions {
my $number_of_itemtypes = @{$data->{itemtypes}}; my $number_of_itemtypes = @{$data->{itemtypes}};
my @where = ('WHERE 1 '); my @where = ('WHERE deleted_at IS NULL ');
$number_of_branches and push @where $number_of_branches and push @where
, 'AND holdingbranch IN (' , 'AND holdingbranch IN ('
, join(',', ('?') x $number_of_branches ) , join(',', ('?') x $number_of_branches )
...@@ -1300,7 +1301,7 @@ sub GetItemnumbersForBiblio { ...@@ -1300,7 +1301,7 @@ sub GetItemnumbersForBiblio {
my $biblionumber = shift; my $biblionumber = shift;
my @items; my @items;
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ? AND deleted_at IS NULL");
$sth->execute($biblionumber); $sth->execute($biblionumber);
while (my $result = $sth->fetchrow_hashref) { while (my $result = $sth->fetchrow_hashref) {
push @items, $result->{'itemnumber'}; push @items, $result->{'itemnumber'};
...@@ -2075,29 +2076,9 @@ sub _koha_delete_item { ...@@ -2075,29 +2076,9 @@ sub _koha_delete_item {
my ( $itemnum ) = @_; my ( $itemnum ) = @_;
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
# save the deleted item to deleteditems table
my $sth = $dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
$sth->execute($itemnum);
my $data = $sth->fetchrow_hashref();
# There is no item to delete
return 0 unless $data;
my $query = "INSERT INTO deleteditems SET ";
my @bind = ();
foreach my $key ( keys %$data ) {
next if ( $key eq 'timestamp' ); # timestamp will be set by db
$query .= "$key = ?,";
push( @bind, $data->{$key} );
}
$query =~ s/\,$//;
$sth = $dbh->prepare($query);
$sth->execute(@bind);
# delete from items table my $sth = $dbh->prepare("UPDATE items SET deleted_at = NOW() WHERE itemnumber = ?");
$sth = $dbh->prepare("DELETE FROM items WHERE itemnumber=?"); return $sth->execute($itemnum);
my $deleted = $sth->execute($itemnum);
return ( $deleted == 1 ) ? 1 : 0;
} }
=head2 _marc_from_item_hash =head2 _marc_from_item_hash
...@@ -2460,7 +2441,7 @@ sub SearchItems { ...@@ -2460,7 +2441,7 @@ sub SearchItems {
LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
LEFT JOIN biblio_metadata ON biblio_metadata.biblionumber = biblio.biblionumber LEFT JOIN biblio_metadata ON biblio_metadata.biblionumber = biblio.biblionumber
WHERE 1 WHERE deleted_at IS NULL
}; };
if (defined $where_str and $where_str ne '') { if (defined $where_str and $where_str ne '') {
$query .= qq{ AND $where_str }; $query .= qq{ AND $where_str };
...@@ -2811,7 +2792,7 @@ sub ToggleNewStatus { ...@@ -2811,7 +2792,7 @@ sub ToggleNewStatus {
SELECT items.biblionumber, items.itemnumber SELECT items.biblionumber, items.itemnumber
FROM items FROM items
LEFT JOIN biblioitems ON biblioitems.biblionumber = items.biblionumber LEFT JOIN biblioitems ON biblioitems.biblionumber = items.biblionumber
WHERE 1 WHERE deleted_at IS NULL
|; |;
for my $condition ( @$conditions ) { for my $condition ( @$conditions ) {
if ( if (
......
...@@ -1121,7 +1121,7 @@ sub IsAvailableForItemLevelRequest { ...@@ -1121,7 +1121,7 @@ sub IsAvailableForItemLevelRequest {
return 1; return 1;
} elsif ( $on_shelf_holds == 2 ) { } elsif ( $on_shelf_holds == 2 ) {
my @items = my @items =
Koha::Items->search( { biblionumber => $item->{biblionumber} } ); Koha::Items->search( { biblionumber => $item->{biblionumber}, deleted_at => undef } );
my $any_available = 0; my $any_available = 0;
...@@ -2010,7 +2010,7 @@ sub GetMaxPatronHoldsForRecord { ...@@ -2010,7 +2010,7 @@ sub GetMaxPatronHoldsForRecord {
my ( $borrowernumber, $biblionumber ) = @_; my ( $borrowernumber, $biblionumber ) = @_;
my $patron = Koha::Patrons->find($borrowernumber); my $patron = Koha::Patrons->find($borrowernumber);
my @items = Koha::Items->search( { biblionumber => $biblionumber } ); my @items = Koha::Items->search( { biblionumber => $biblionumber, deleted_at => undef } );
my $controlbranch = C4::Context->preference('ReservesControlBranch'); my $controlbranch = C4::Context->preference('ReservesControlBranch');
......
...@@ -250,7 +250,7 @@ or list of Koha::Item objects in list context. ...@@ -250,7 +250,7 @@ or list of Koha::Item objects in list context.
sub items { sub items {
my ($self) = @_; my ($self) = @_;
$self->{_items} ||= Koha::Items->search( { biblionumber => $self->biblionumber() } ); $self->{_items} ||= Koha::Items->search( { biblionumber => $self->biblionumber(), deleted_at => undef } );
return wantarray ? $self->{_items}->as_list : $self->{_items}; return wantarray ? $self->{_items}->as_list : $self->{_items};
} }
......
...@@ -79,6 +79,7 @@ sub _processrecord { ...@@ -79,6 +79,7 @@ sub _processrecord {
my $not_onloan_items = Koha::Items->search({ my $not_onloan_items = Koha::Items->search({
biblionumber => $biblionumber, biblionumber => $biblionumber,
onloan => undef, onloan => undef,
deleted_at => undef,
})->count; })->count;
# check for field 999 # check for field 999
......
...@@ -101,7 +101,7 @@ Counts up the number of biblioitems and items with itemtype (code) and hands bac ...@@ -101,7 +101,7 @@ Counts up the number of biblioitems and items with itemtype (code) and hands bac
sub can_be_deleted { sub can_be_deleted {
my ($self) = @_; my ($self) = @_;
my $nb_items = Koha::Items->search( { itype => $self->itemtype } )->count; my $nb_items = Koha::Items->search( { itype => $self->itemtype, deleted_at => undef } )->count;
my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count; my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count;
return $nb_items + $nb_biblioitems == 0 ? 1 : 0; return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
} }
......
...@@ -39,21 +39,17 @@ sub new { ...@@ -39,21 +39,17 @@ sub new {
my $sql = " my $sql = "
SELECT timestamp SELECT timestamp
FROM biblioitems FROM biblioitems
WHERE biblionumber=? WHERE biblionumber=? AND deleted_at IS NULL
"; ";
my @bind_params = ($biblionumber); my @bind_params = ($biblionumber);
if ( $items_included ) { if ( $items_included ) {
# Take latest timestamp of biblio and any items # Take latest timestamp of biblio and any items
$sql .= " $sql .= "
UNION
SELECT timestamp from deleteditems
WHERE biblionumber=?
UNION UNION
SELECT timestamp from items SELECT timestamp from items
WHERE biblionumber=? WHERE biblionumber=?
"; ";
push @bind_params, $biblionumber; push @bind_params, $biblionumber;
push @bind_params, $biblionumber;
$sql = " $sql = "
SELECT max(timestamp) SELECT max(timestamp)
FROM ($sql) bib FROM ($sql) bib
...@@ -66,8 +62,8 @@ sub new { ...@@ -66,8 +62,8 @@ sub new {
unless ( ($timestamp = $sth->fetchrow) ) { unless ( ($timestamp = $sth->fetchrow) ) {
$sql = " $sql = "
SELECT timestamp SELECT timestamp
FROM deletedbiblio FROM biblio
WHERE biblionumber=? WHERE biblionumber=? AND deleted_at IS NOT NULL
"; ";
@bind_params = ($biblionumber); @bind_params = ($biblionumber);
...@@ -75,8 +71,8 @@ sub new { ...@@ -75,8 +71,8 @@ sub new {
# Take latest timestamp among biblio and items # Take latest timestamp among biblio and items
$sql .= " $sql .= "
UNION UNION
SELECT timestamp from deleteditems SELECT timestamp from items
WHERE biblionumber=? WHERE biblionumber=? AND deleted_at IS NULL
"; ";
push @bind_params, $biblionumber; push @bind_params, $biblionumber;
$sql = " $sql = "
......
...@@ -68,12 +68,12 @@ sub GetRecords { ...@@ -68,12 +68,12 @@ sub GetRecords {
if ($include_items) { if ($include_items) {
$sql .= " $sql .= "
OR biblionumber IN (SELECT biblionumber from deleteditems WHERE timestamp >= ? AND timestamp <= ?) OR biblionumber IN (SELECT biblionumber from items WHERE timestamp >= ? AND timestamp <= ? AND deleted_at IS NOT NULL)
"; ";
push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'}); push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'});
if (!$deleted) { if (!$deleted) {
$sql .= " $sql .= "
OR biblionumber IN (SELECT biblionumber from items WHERE timestamp >= ? AND timestamp <= ?) OR biblionumber IN (SELECT biblionumber from items WHERE timestamp >= ? AND timestamp <= ? AND deleted_at IS NULL)
"; ";
push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'}); push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'});
} }
...@@ -105,7 +105,7 @@ sub GetRecords { ...@@ -105,7 +105,7 @@ sub GetRecords {
FROM ( FROM (
SELECT timestamp FROM deletedbiblio_metadata WHERE biblionumber = ? SELECT timestamp FROM deletedbiblio_metadata WHERE biblionumber = ?
UNION UNION
SELECT timestamp FROM deleteditems WHERE biblionumber = ? SELECT timestamp FROM items WHERE biblionumber = ? AND deleted_at IS NOT NULL
) bis ) bis
"; ";
} else { } else {
...@@ -114,9 +114,9 @@ sub GetRecords { ...@@ -114,9 +114,9 @@ sub GetRecords {
FROM ( FROM (
SELECT timestamp FROM biblio_metadata WHERE biblionumber = ? SELECT timestamp FROM biblio_metadata WHERE biblionumber = ?
UNION UNION
SELECT timestamp FROM deleteditems WHERE biblionumber = ? SELECT timestamp FROM items WHERE biblionumber = ? AND deleted_at IS NULL
UNION UNION
SELECT timestamp FROM items WHERE biblionumber = ? SELECT timestamp FROM items WHERE biblionumber = ? AND deleted_at IS NOT NULL
) bi ) bi
"; ";
} }
......
...@@ -246,7 +246,7 @@ sub do_check_for_previous_checkout { ...@@ -246,7 +246,7 @@ sub do_check_for_previous_checkout {
my ( $self, $item ) = @_; my ( $self, $item ) = @_;
# Find all items for bib and extract item numbers. # Find all items for bib and extract item numbers.
my @items = Koha::Items->search({biblionumber => $item->{biblionumber}}); my @items = Koha::Items->search({biblionumber => $item->{biblionumber}, deleted_at => undef });
my @item_nos; my @item_nos;
foreach my $item (@items) { foreach my $item (@items) {
push @item_nos, $item->itemnumber; push @item_nos, $item->itemnumber;
......
...@@ -108,7 +108,8 @@ if ( $op eq 'add_form' ) { ...@@ -108,7 +108,8 @@ if ( $op eq 'add_form' ) {
my $items_count = Koha::Items->search( my $items_count = Koha::Items->search(
{ -or => { { -or => {
holdingbranch => $branchcode, holdingbranch => $branchcode,
homebranch => $branchcode homebranch => $branchcode,
deleted_at => undef,
}, },
} }
)->count; )->count;
......
...@@ -88,7 +88,7 @@ if ($merge) { ...@@ -88,7 +88,7 @@ if ($merge) {
# Moving items from the other record to the reference record # Moving items from the other record to the reference record
foreach my $biblionumber (@biblionumbers) { foreach my $biblionumber (@biblionumbers) {
my $items = Koha::Items->search({ biblionumber => $biblionumber }); my $items = Koha::Items->search({ biblionumber => $biblionumber, deleted_at => undef });
while ( my $item = $items->next) { while ( my $item = $items->next) {
my $res = MoveItemFromBiblio( $item->itemnumber, $biblionumber, $ref_biblionumber ); my $res = MoveItemFromBiblio( $item->itemnumber, $biblionumber, $ref_biblionumber );
if ( not defined $res ) { if ( not defined $res ) {
......
...@@ -137,7 +137,7 @@ if ($show_results) { ...@@ -137,7 +137,7 @@ if ($show_results) {
push (@results_set, $biblio); push (@results_set, $biblio);
my $biblionumber = $biblio->{'biblionumber'}; my $biblionumber = $biblio->{'biblionumber'};
#DEBUG Notes: Grab the item numbers associated with this MARC record... #DEBUG Notes: Grab the item numbers associated with this MARC record...
my $items = Koha::Items->search({ biblionumber => $biblionumber }, { order_by => { -desc => 'itemnumber' }}); my $items = Koha::Items->search({ biblionumber => $biblionumber, deleted_at => undef }, { order_by => { -desc => 'itemnumber' }});
#DEBUG Notes: Retrieve the item data for each number... #DEBUG Notes: Retrieve the item data for each number...
while ( my $item = $items->next ) { while ( my $item = $items->next ) {
#DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data... #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
......
...@@ -45,7 +45,7 @@ cronlogaction(); ...@@ -45,7 +45,7 @@ cronlogaction();
my $members = GetBorrowersToExpunge( my $members = GetBorrowersToExpunge(
{ {
not_borrowed_since => $not_borrowed_since, not_borrowed_since => $not_borrowed_since,
expired_before => $expired_before, expired_before => $expired_before,
last_seen => $last_seen, last_seen => $last_seen,
category_code => $category_code, category_code => $category_code,
......
...@@ -103,22 +103,14 @@ $timestamp = ($timestamp) ? output_pref({ dt => dt_from_string($timestamp), date ...@@ -103,22 +103,14 @@ $timestamp = ($timestamp) ? output_pref({ dt => dt_from_string($timestamp), date
if ( $record_type eq 'bibs' ) { if ( $record_type eq 'bibs' ) {
if ( $timestamp ) { if ( $timestamp ) {
push @record_ids, $_->{biblionumber} for @{ push @record_ids, $_->{biblionumber} for @{
$dbh->selectall_arrayref(q| ( $dbh->selectall_arrayref(q|
SELECT biblio_metadata.biblionumber SELECT biblionumber
FROM biblio_metadata FROM biblioitems
LEFT JOIN items USING(biblionumber) |, { Slice => {} }, ( $timestamp ) x 4 );
WHERE biblio_metadata.timestamp >= ?
OR items.timestamp >= ?
) UNION (
SELECT biblio_metadata.biblionumber
FROM biblio_metadata
LEFT JOIN deleteditems USING(biblionumber)
WHERE biblio_metadata.timestamp >= ?
OR deleteditems.timestamp >= ?
) |, { Slice => {} }, ( $timestamp ) x 4 );
}; };
} else { } else {
my $conditions = { my $conditions = {
deleted_at => undef,
( $starting_biblionumber or $ending_biblionumber ) ( $starting_biblionumber or $ending_biblionumber )
? ( ? (
"me.biblionumber" => { "me.biblionumber" => {
...@@ -189,8 +181,8 @@ if ($deleted_barcodes) { ...@@ -189,8 +181,8 @@ if ($deleted_barcodes) {
for my $record_id ( @record_ids ) { for my $record_id ( @record_ids ) {
my $barcode = $dbh->selectall_arrayref(q| my $barcode = $dbh->selectall_arrayref(q|
SELECT DISTINCT barcode SELECT DISTINCT barcode
FROM deleteditems FROM items
WHERE deleteditems.biblionumber = ? WHERE deleteditems.biblionumber = ? AND deleted_at IS NOT NULL
|, { Slice => {} }, $record_id ); |, { Slice => {} }, $record_id );
say $_->{barcode} for @$barcode; say $_->{barcode} for @$barcode;
} }
......
...@@ -294,7 +294,7 @@ if ( $query->param('place_reserve') ) { ...@@ -294,7 +294,7 @@ if ( $query->param('place_reserve') ) {
} }
unless ( $can_place_hold_if_available_at_pickup ) { unless ( $can_place_hold_if_available_at_pickup ) {
my $items_in_this_library = Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch }); my $items_in_this_library = Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch, deleted_at => undef });
my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count; my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
my $nb_of_items_unavailable = $items_in_this_library->search({ -or => { lost => { '!=' => 0 }, damaged => { '!=' => 0 }, } }); my $nb_of_items_unavailable = $items_in_this_library->search({ -or => { lost => { '!=' => 0 }, damaged => { '!=' => 0 }, } });
if ( $items_in_this_library->count > $nb_of_items_issued + $nb_of_items_unavailable ) { if ( $items_in_this_library->count > $nb_of_items_issued + $nb_of_items_unavailable ) {
...@@ -545,7 +545,7 @@ foreach my $biblioNum (@biblionumbers) { ...@@ -545,7 +545,7 @@ foreach my $biblioNum (@biblionumbers) {
$numCopiesAvailable++; $numCopiesAvailable++;
unless ( $can_place_hold_if_available_at_pickup ) { unless ( $can_place_hold_if_available_at_pickup ) {
my $items_in_this_library = Koha::Items->search({ biblionumber => $itemInfo->{biblionumber}, holdingbranch => $itemInfo->{holdingbranch} }); my $items_in_this_library = Koha::Items->search({ biblionumber => $itemInfo->{biblionumber}, holdingbranch => $itemInfo->{holdingbranch}, deleted_at => undef });
my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count; my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
if ( $items_in_this_library->count > $nb_of_items_issued ) { if ( $items_in_this_library->count > $nb_of_items_issued ) {
push @not_available_at, $itemInfo->{holdingbranch}; push @not_available_at, $itemInfo->{holdingbranch};
......
...@@ -172,7 +172,10 @@ sub calculate { ...@@ -172,7 +172,10 @@ sub calculate {
my $barcodelike = @$filters[16]; my $barcodelike = @$filters[16];
my $barcodefilter = @$filters[17]; my $barcodefilter = @$filters[17];
my $not; my $not;
my $itemstable = ($cellvalue eq 'deleteditems') ? 'deleteditems' : 'items'; my $itemstable = 'items';
my $deleted_where = "items.deleted_at IS NULL";
$deleted_where = "1" if $cellvalue eq 'allitems';
$deleted_where = "items.deleted_at IS NOT NULL" if $cellvalue eq 'deleteditems';
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
...@@ -273,12 +276,9 @@ sub calculate { ...@@ -273,12 +276,9 @@ sub calculate {
# 1st, loop rows. # 1st, loop rows.
my $origline = $line; my $origline = $line;
$line =~ s/^items\./deleteditems./ if($cellvalue eq "deleteditems");
my $linefield; my $linefield;
if ( ( $line =~ /itemcallnumber/ ) and ($cotedigits) ) { if ( ( $line =~ /itemcallnumber/ ) and ($cotedigits) ) {
$linefield = "left($line,$cotedigits)"; $linefield = "left($line,$cotedigits)";
} elsif ( $line =~ /^deleteditems\.timestamp$/ ) {
$linefield = "DATE($line)";
} else { } else {
$linefield = $line; $linefield = $line;
} }
...@@ -286,7 +286,7 @@ sub calculate { ...@@ -286,7 +286,7 @@ sub calculate {
my $strsth = "SELECT DISTINCTROW $linefield FROM $itemstable my $strsth = "SELECT DISTINCTROW $linefield FROM $itemstable
LEFT JOIN biblioitems USING (biblioitemnumber) LEFT JOIN biblioitems USING (biblioitemnumber)
LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber) LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber)
WHERE 1 "; WHERE $deleted_where ";
$strsth .= " AND barcode $not LIKE ? " if ($barcodefilter); $strsth .= " AND barcode $not LIKE ? " if ($barcodefilter);
if (@linefilter) { if (@linefilter) {
if ( $linefilter[1] ) { if ( $linefilter[1] ) {
...@@ -335,7 +335,6 @@ sub calculate { ...@@ -335,7 +335,6 @@ sub calculate {
# 2nd, loop cols. # 2nd, loop cols.
my $origcolumn = $column; my $origcolumn = $column;
$column =~ s/^items\./deleteditems./ if($cellvalue eq "deleteditems");
my $colfield; my $colfield;
if ( ( $column =~ /itemcallnumber/ ) and ($cotedigits) ) { if ( ( $column =~ /itemcallnumber/ ) and ($cotedigits) ) {
$colfield = "left($column,$cotedigits)"; $colfield = "left($column,$cotedigits)";
...@@ -352,7 +351,7 @@ sub calculate { ...@@ -352,7 +351,7 @@ sub calculate {
USING (biblioitemnumber) USING (biblioitemnumber)
LEFT JOIN biblio LEFT JOIN biblio
ON (biblioitems.biblionumber = biblio.biblionumber) ON (biblioitems.biblionumber = biblio.biblionumber)
WHERE 1 "; WHERE $deleted_where ";
$strsth2 .= " AND barcode $not LIKE ?" if $barcodefilter; $strsth2 .= " AND barcode $not LIKE ?" if $barcodefilter;
if ( (@colfilter) and ( $colfilter[1] ) ) { if ( (@colfilter) and ( $colfilter[1] ) ) {
...@@ -418,7 +417,7 @@ sub calculate { ...@@ -418,7 +417,7 @@ sub calculate {
FROM $itemstable FROM $itemstable
LEFT JOIN biblioitems ON ($itemstable.biblioitemnumber = biblioitems.biblioitemnumber) LEFT JOIN biblioitems ON ($itemstable.biblioitemnumber = biblioitems.biblioitemnumber)
LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber) LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber)
WHERE 1 "; WHERE $deleted_where ";
my @sqlargs; my @sqlargs;
...@@ -501,13 +500,13 @@ sub calculate { ...@@ -501,13 +500,13 @@ sub calculate {
push @sqlargs, @$filters[14]; push @sqlargs, @$filters[14];
} }
if ( $cellvalue eq 'deleteditems' and @$filters[15] ) { if ( $cellvalue eq 'deleteditems' and @$filters[15] ) {
$strcalc .= " AND DATE(deleteditems.timestamp) >= ? "; $strcalc .= " AND DATE(deleted_at) >= ? ";
@$filters[15] =~ s/\*/%/g; @$filters[15] =~ s/\*/%/g;
push @sqlargs, @$filters[15]; push @sqlargs, @$filters[15];
} }
if ( $cellvalue eq 'deleteditems' and @$filters[16] ) { if ( $cellvalue eq 'deleteditems' and @$filters[16] ) {
@$filters[16] =~ s/\*/%/g; @$filters[16] =~ s/\*/%/g;
$strcalc .= " AND DATE(deleteditems.timestamp) <= ?"; $strcalc .= " AND DATE(deleted_at) <= ?";
push @sqlargs, @$filters[16]; push @sqlargs, @$filters[16];
} }
$strcalc .= " group by $linefield, $colfield order by $linefield,$colfield"; $strcalc .= " group by $linefield, $colfield order by $linefield,$colfield";
......
...@@ -115,6 +115,7 @@ if ( $op eq 'export' ) { ...@@ -115,6 +115,7 @@ if ( $op eq 'export' ) {
my $notforloanfilter = $params->{'notforloanfilter'} || undef; my $notforloanfilter = $params->{'notforloanfilter'} || undef;
my $params = { my $params = {
deleted_at => undef,
( $branchfilter ? ( homebranch => $branchfilter ) : () ), ( $branchfilter ? ( homebranch => $branchfilter ) : () ),
( (
$loststatusfilter $loststatusfilter
......