View | Details | Raw Unified | Return to bug 20271
Collapse All | Expand All

(-)a/C4/Acquisition.pm (-6 / +4 lines)
Lines 2291-2300 sub GetHistory { Link Here
2291
    my $dbh   = C4::Context->dbh;
2291
    my $dbh   = C4::Context->dbh;
2292
    my $query ="
2292
    my $query ="
2293
        SELECT
2293
        SELECT
2294
            COALESCE(biblio.title,     deletedbiblio.title)     AS title,
2294
            biblio.title,
2295
            COALESCE(biblio.author,    deletedbiblio.author)    AS author,
2295
            biblio.author,
2296
            COALESCE(biblioitems.isbn, deletedbiblioitems.isbn) AS isbn,
2296
            biblioitems.isbn,
2297
            COALESCE(biblioitems.ean,  deletedbiblioitems.ean)  AS ean,
2297
            biblioitems.ean,
2298
            aqorders.basketno,
2298
            aqorders.basketno,
2299
            aqbasket.basketname,
2299
            aqbasket.basketname,
2300
            aqbasket.basketgroupid,
2300
            aqbasket.basketgroupid,
Lines 2326-2333 sub GetHistory { Link Here
2326
        LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
2326
        LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
2327
        LEFT JOIN aqbudgets ON aqorders.budget_id=aqbudgets.budget_id
2327
        LEFT JOIN aqbudgets ON aqorders.budget_id=aqbudgets.budget_id
2328
        LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid
2328
        LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid
2329
        LEFT JOIN deletedbiblio ON deletedbiblio.biblionumber=aqorders.biblionumber
2330
        LEFT JOIN deletedbiblioitems ON deletedbiblioitems.biblionumber=aqorders.biblionumber
2331
        LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
2329
        LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
2332
        ";
2330
        ";
2333
2331
(-)a/C4/Biblio.pm (-86 / +13 lines)
Lines 318-324 sub ModBiblio { Link Here
318
    # update biblionumber and biblioitemnumber in MARC
318
    # update biblionumber and biblioitemnumber in MARC
319
    # FIXME - this is assuming a 1 to 1 relationship between
319
    # FIXME - this is assuming a 1 to 1 relationship between
320
    # biblios and biblioitems
320
    # biblios and biblioitems
321
    my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
321
    my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=? AND deleted_at IS NULL");
322
    $sth->execute($biblionumber);
322
    $sth->execute($biblionumber);
323
    my ($biblioitemnumber) = $sth->fetchrow;
323
    my ($biblioitemnumber) = $sth->fetchrow;
324
    $sth->finish();
324
    $sth->finish();
Lines 387-393 sub DelBiblio { Link Here
387
    my $error;    # for error handling
387
    my $error;    # for error handling
388
388
389
    # First make sure this biblio has no items attached
389
    # First make sure this biblio has no items attached
390
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=?");
390
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=? AND deleted_at IS NULL");
391
    $sth->execute($biblionumber);
391
    $sth->execute($biblionumber);
392
    if ( my $itemnumber = $sth->fetchrow ) {
392
    if ( my $itemnumber = $sth->fetchrow ) {
393
393
Lines 418-424 sub DelBiblio { Link Here
418
    ModZebra( $biblionumber, "recordDelete", "biblioserver" );
418
    ModZebra( $biblionumber, "recordDelete", "biblioserver" );
419
419
420
    # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
420
    # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
421
    $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
421
    $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? AND deleted_at IS NULL");
422
    $sth->execute($biblionumber);
422
    $sth->execute($biblionumber);
423
    while ( my $biblioitemnumber = $sth->fetchrow ) {
423
    while ( my $biblioitemnumber = $sth->fetchrow ) {
424
424
Lines 759-765 NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebr Link Here
759
sub GetBiblioItemByBiblioNumber {
759
sub GetBiblioItemByBiblioNumber {
760
    my ($biblionumber) = @_;
760
    my ($biblionumber) = @_;
761
    my $dbh            = C4::Context->dbh;
761
    my $dbh            = C4::Context->dbh;
762
    my $sth            = $dbh->prepare("Select * FROM biblioitems WHERE biblionumber = ?");
762
    my $sth            = $dbh->prepare("Select * FROM biblioitems WHERE biblionumber = ? AND deleted_at IS NULL");
763
    my $count          = 0;
763
    my $count          = 0;
764
    my @results;
764
    my @results;
765
765
Lines 1212-1218 sub GetMarcBiblio { Link Here
1212
    }
1212
    }
1213
1213
1214
    my $dbh          = C4::Context->dbh;
1214
    my $dbh          = C4::Context->dbh;
1215
    my $sth          = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? ");
1215
    my $sth          = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? AND deleted_at IS NULL");
1216
    $sth->execute($biblionumber);
1216
    $sth->execute($biblionumber);
1217
    my $row     = $sth->fetchrow_hashref;
1217
    my $row     = $sth->fetchrow_hashref;
1218
    my $biblioitemnumber = $row->{'biblioitemnumber'};
1218
    my $biblioitemnumber = $row->{'biblioitemnumber'};
Lines 2830-2836 sub EmbedItemsInMarcBiblio { Link Here
2830
2830
2831
    # ... and embed the current items
2831
    # ... and embed the current items
2832
    my $dbh = C4::Context->dbh;
2832
    my $dbh = C4::Context->dbh;
2833
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
2833
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ? and deleted_at IS NULL");
2834
    $sth->execute($biblionumber);
2834
    $sth->execute($biblionumber);
2835
    my @item_fields;
2835
    my @item_fields;
2836
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2836
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
Lines 3160-3200 C<$biblionumber> - the biblionumber of the biblio to be deleted Link Here
3160
sub _koha_delete_biblio {
3160
sub _koha_delete_biblio {
3161
    my ( $dbh, $biblionumber ) = @_;
3161
    my ( $dbh, $biblionumber ) = @_;
3162
3162
3163
    # get all the data for this biblio
3163
    my $sth = $dbh->prepare("UPDATE biblio SET deleted_at = NOW() WHERE biblionumber=?");
3164
    my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?");
3164
    return $sth->execute($biblionumber) ? undef : ($DBI::errstr || "unknown error");
3165
    $sth->execute($biblionumber);
3166
3167
    # FIXME There is a transaction in _koha_delete_biblio_metadata
3168
    # But actually all the following should be done inside a single transaction
3169
    if ( my $data = $sth->fetchrow_hashref ) {
3170
3171
        # save the record in deletedbiblio
3172
        # find the fields to save
3173
        my $query = "INSERT INTO deletedbiblio SET ";
3174
        my @bind  = ();
3175
        foreach my $temp ( keys %$data ) {
3176
            $query .= "$temp = ?,";
3177
            push( @bind, $data->{$temp} );
3178
        }
3179
3180
        # replace the last , by ",?)"
3181
        $query =~ s/\,$//;
3182
        my $bkup_sth = $dbh->prepare($query);
3183
        $bkup_sth->execute(@bind);
3184
        $bkup_sth->finish;
3185
3186
        _koha_delete_biblio_metadata( $biblionumber );
3187
3188
        # delete the biblio
3189
        my $sth2 = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?");
3190
        $sth2->execute($biblionumber);
3191
        # update the timestamp (Bugzilla 7146)
3192
        $sth2= $dbh->prepare("UPDATE deletedbiblio SET timestamp=NOW() WHERE biblionumber=?");
3193
        $sth2->execute($biblionumber);
3194
        $sth2->finish;
3195
    }
3196
    $sth->finish;
3197
    return;
3198
}
3165
}
3199
3166
3200
=head2 _koha_delete_biblioitems
3167
=head2 _koha_delete_biblioitems
Lines 3212-3249 C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted Link Here
3212
3179
3213
sub _koha_delete_biblioitems {
3180
sub _koha_delete_biblioitems {
3214
    my ( $dbh, $biblioitemnumber ) = @_;
3181
    my ( $dbh, $biblioitemnumber ) = @_;
3215
3182
    my $sth = $dbh->prepare("UPDATE biblioitems SET deleted_at = NOW() WHERE biblioitemnumber=?");
3216
    # get all the data for this biblioitem
3183
    return $sth->execute($biblioitemnumber) ? undef : ($DBI::errstr || 'unknown error');
3217
    my $sth = $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?");
3218
    $sth->execute($biblioitemnumber);
3219
3220
    if ( my $data = $sth->fetchrow_hashref ) {
3221
3222
        # save the record in deletedbiblioitems
3223
        # find the fields to save
3224
        my $query = "INSERT INTO deletedbiblioitems SET ";
3225
        my @bind  = ();
3226
        foreach my $temp ( keys %$data ) {
3227
            $query .= "$temp = ?,";
3228
            push( @bind, $data->{$temp} );
3229
        }
3230
3231
        # replace the last , by ",?)"
3232
        $query =~ s/\,$//;
3233
        my $bkup_sth = $dbh->prepare($query);
3234
        $bkup_sth->execute(@bind);
3235
        $bkup_sth->finish;
3236
3237
        # delete the biblioitem
3238
        my $sth2 = $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?");
3239
        $sth2->execute($biblioitemnumber);
3240
        # update the timestamp (Bugzilla 7146)
3241
        $sth2= $dbh->prepare("UPDATE deletedbiblioitems SET timestamp=NOW() WHERE biblioitemnumber=?");
3242
        $sth2->execute($biblioitemnumber);
3243
        $sth2->finish;
3244
    }
3245
    $sth->finish;
3246
    return;
3247
}
3184
}
3248
3185
3249
=head2 _koha_delete_biblio_metadata
3186
=head2 _koha_delete_biblio_metadata
Lines 3256-3274 C<$biblionumber> - the biblionumber of the biblio metadata to be deleted Link Here
3256
3193
3257
sub _koha_delete_biblio_metadata {
3194
sub _koha_delete_biblio_metadata {
3258
    my ($biblionumber) = @_;
3195
    my ($biblionumber) = @_;
3259
3196
    my $dbh = C4::Context->dbh;
3260
    my $dbh    = C4::Context->dbh;
3197
    my $sth = $dbh->prepare("UPDATE biblio_metadata SET deleted_at = NOW() WHERE biblionumber=?");
3261
    my $schema = Koha::Database->new->schema;
3198
    return $sth->execute($biblionumber);
3262
    $schema->txn_do(
3263
        sub {
3264
            $dbh->do( q|
3265
                INSERT INTO deletedbiblio_metadata (biblionumber, format, marcflavour, metadata)
3266
                SELECT biblionumber, format, marcflavour, metadata FROM biblio_metadata WHERE biblionumber=?
3267
            |,  undef, $biblionumber );
3268
            $dbh->do( q|DELETE FROM biblio_metadata WHERE biblionumber=?|,
3269
                undef, $biblionumber );
3270
        }
3271
    );
3272
}
3199
}
3273
3200
3274
=head1 UNEXPORTED FUNCTIONS
3201
=head1 UNEXPORTED FUNCTIONS
(-)a/C4/Items.pm (-30 / +11 lines)
Lines 830-835 sub GetItemsForInventory { Link Here
830
        FROM items
830
        FROM items
831
        LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
831
        LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
832
        LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber
832
        LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber
833
        WHERE items.deleted_at IS NULL
833
    };
834
    };
834
    if ($statushash){
835
    if ($statushash){
835
        for my $authvfield (keys %$statushash){
836
        for my $authvfield (keys %$statushash){
Lines 936-942 Called by C<C4::XISBN> Link Here
936
sub GetItemsByBiblioitemnumber {
937
sub GetItemsByBiblioitemnumber {
937
    my ( $bibitem ) = @_;
938
    my ( $bibitem ) = @_;
938
    my $dbh = C4::Context->dbh;
939
    my $dbh = C4::Context->dbh;
939
    my $sth = $dbh->prepare("SELECT * FROM items WHERE items.biblioitemnumber = ?") || die $dbh->errstr;
940
    my $sth = $dbh->prepare("SELECT * FROM items WHERE items.biblioitemnumber = ? AND items.deleted_at IS NULL") || die $dbh->errstr;
940
    # Get all items attached to a biblioitem
941
    # Get all items attached to a biblioitem
941
    my $i = 0;
942
    my $i = 0;
942
    my @results; 
943
    my @results; 
Lines 1060-1066 sub GetItemsInfo { Link Here
1060
     FROM items
1061
     FROM items
1061
     LEFT JOIN branches AS holding ON items.holdingbranch = holding.branchcode
1062
     LEFT JOIN branches AS holding ON items.holdingbranch = holding.branchcode
1062
     LEFT JOIN branches AS home ON items.homebranch=home.branchcode
1063
     LEFT JOIN branches AS home ON items.homebranch=home.branchcode
1063
     LEFT JOIN biblio      ON      biblio.biblionumber     = items.biblionumber
1064
     LEFT JOIN biblio      ON      biblio.biblionumber     = items.biblionumber AND biblio.deleted_at IS NULL
1064
     LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
1065
     LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
1065
     LEFT JOIN issues USING (itemnumber)
1066
     LEFT JOIN issues USING (itemnumber)
1066
     LEFT JOIN borrowers USING (borrowernumber)
1067
     LEFT JOIN borrowers USING (borrowernumber)
Lines 1074-1080 sub GetItemsInfo { Link Here
1074
        AND localization.lang = ?
1075
        AND localization.lang = ?
1075
    |;
1076
    |;
1076
1077
1077
    $query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1078
    $query .= " WHERE items.biblionumber = ? AND items.deleted_at IS NULL ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1078
    my $sth = $dbh->prepare($query);
1079
    my $sth = $dbh->prepare($query);
1079
    $sth->execute($language, $biblionumber);
1080
    $sth->execute($language, $biblionumber);
1080
    my $i = 0;
1081
    my $i = 0;
Lines 1181-1187 sub GetItemsLocationInfo { Link Here
1181
			    location, itemcallnumber, cn_sort
1182
			    location, itemcallnumber, cn_sort
1182
		     FROM items, branches as a, branches as b
1183
		     FROM items, branches as a, branches as b
1183
		     WHERE homebranch = a.branchcode AND holdingbranch = b.branchcode 
1184
		     WHERE homebranch = a.branchcode AND holdingbranch = b.branchcode 
1184
		     AND biblionumber = ?
1185
		     AND biblionumber = ? AND deleted_at IS NULL
1185
		     ORDER BY cn_sort ASC";
1186
		     ORDER BY cn_sort ASC";
1186
	my $sth = $dbh->prepare($query);
1187
	my $sth = $dbh->prepare($query);
1187
        $sth->execute($biblionumber);
1188
        $sth->execute($biblionumber);
Lines 1253-1259 sub GetLastAcquisitions { Link Here
1253
	my $number_of_itemtypes   = @{$data->{itemtypes}};
1254
	my $number_of_itemtypes   = @{$data->{itemtypes}};
1254
	
1255
	
1255
	
1256
	
1256
	my @where = ('WHERE 1 '); 
1257
	my @where = ('WHERE deleted_at IS NULL ');
1257
	$number_of_branches and push @where
1258
	$number_of_branches and push @where
1258
	   , 'AND holdingbranch IN (' 
1259
	   , 'AND holdingbranch IN (' 
1259
	   , join(',', ('?') x $number_of_branches )
1260
	   , join(',', ('?') x $number_of_branches )
Lines 1300-1306 sub GetItemnumbersForBiblio { Link Here
1300
    my $biblionumber = shift;
1301
    my $biblionumber = shift;
1301
    my @items;
1302
    my @items;
1302
    my $dbh = C4::Context->dbh;
1303
    my $dbh = C4::Context->dbh;
1303
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
1304
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ? AND deleted_at IS NULL");
1304
    $sth->execute($biblionumber);
1305
    $sth->execute($biblionumber);
1305
    while (my $result = $sth->fetchrow_hashref) {
1306
    while (my $result = $sth->fetchrow_hashref) {
1306
        push @items, $result->{'itemnumber'};
1307
        push @items, $result->{'itemnumber'};
Lines 2075-2103 sub _koha_delete_item { Link Here
2075
    my ( $itemnum ) = @_;
2076
    my ( $itemnum ) = @_;
2076
2077
2077
    my $dbh = C4::Context->dbh;
2078
    my $dbh = C4::Context->dbh;
2078
    # save the deleted item to deleteditems table
2079
    my $sth = $dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
2080
    $sth->execute($itemnum);
2081
    my $data = $sth->fetchrow_hashref();
2082
2083
    # There is no item to delete
2084
    return 0 unless $data;
2085
2086
    my $query = "INSERT INTO deleteditems SET ";
2087
    my @bind  = ();
2088
    foreach my $key ( keys %$data ) {
2089
        next if ( $key eq 'timestamp' ); # timestamp will be set by db
2090
        $query .= "$key = ?,";
2091
        push( @bind, $data->{$key} );
2092
    }
2093
    $query =~ s/\,$//;
2094
    $sth = $dbh->prepare($query);
2095
    $sth->execute(@bind);
2096
2079
2097
    # delete from items table
2080
    my $sth = $dbh->prepare("UPDATE items SET deleted_at = NOW() WHERE itemnumber = ?");
2098
    $sth = $dbh->prepare("DELETE FROM items WHERE itemnumber=?");
2081
    return $sth->execute($itemnum);
2099
    my $deleted = $sth->execute($itemnum);
2100
    return ( $deleted == 1 ) ? 1 : 0;
2101
}
2082
}
2102
2083
2103
=head2 _marc_from_item_hash
2084
=head2 _marc_from_item_hash
Lines 2460-2466 sub SearchItems { Link Here
2460
          LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
2441
          LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
2461
          LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
2442
          LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
2462
          LEFT JOIN biblio_metadata ON biblio_metadata.biblionumber = biblio.biblionumber
2443
          LEFT JOIN biblio_metadata ON biblio_metadata.biblionumber = biblio.biblionumber
2463
          WHERE 1
2444
          WHERE deleted_at IS NULL
2464
    };
2445
    };
2465
    if (defined $where_str and $where_str ne '') {
2446
    if (defined $where_str and $where_str ne '') {
2466
        $query .= qq{ AND $where_str };
2447
        $query .= qq{ AND $where_str };
Lines 2811-2817 sub ToggleNewStatus { Link Here
2811
            SELECT items.biblionumber, items.itemnumber
2792
            SELECT items.biblionumber, items.itemnumber
2812
            FROM items
2793
            FROM items
2813
            LEFT JOIN biblioitems ON biblioitems.biblionumber = items.biblionumber
2794
            LEFT JOIN biblioitems ON biblioitems.biblionumber = items.biblionumber
2814
            WHERE 1
2795
            WHERE deleted_at IS NULL
2815
        |;
2796
        |;
2816
        for my $condition ( @$conditions ) {
2797
        for my $condition ( @$conditions ) {
2817
            if (
2798
            if (
(-)a/C4/Reserves.pm (-2 / +2 lines)
Lines 1121-1127 sub IsAvailableForItemLevelRequest { Link Here
1121
        return 1;
1121
        return 1;
1122
    } elsif ( $on_shelf_holds == 2 ) {
1122
    } elsif ( $on_shelf_holds == 2 ) {
1123
        my @items =
1123
        my @items =
1124
          Koha::Items->search( { biblionumber => $item->{biblionumber} } );
1124
          Koha::Items->search( { biblionumber => $item->{biblionumber}, deleted_at => undef } );
1125
1125
1126
        my $any_available = 0;
1126
        my $any_available = 0;
1127
1127
Lines 2010-2016 sub GetMaxPatronHoldsForRecord { Link Here
2010
    my ( $borrowernumber, $biblionumber ) = @_;
2010
    my ( $borrowernumber, $biblionumber ) = @_;
2011
2011
2012
    my $patron = Koha::Patrons->find($borrowernumber);
2012
    my $patron = Koha::Patrons->find($borrowernumber);
2013
    my @items = Koha::Items->search( { biblionumber => $biblionumber } );
2013
    my @items = Koha::Items->search( { biblionumber => $biblionumber, deleted_at => undef } );
2014
2014
2015
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
2015
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
2016
2016
(-)a/Koha/Biblio.pm (-1 / +1 lines)
Lines 250-256 or list of Koha::Item objects in list context. Link Here
250
sub items {
250
sub items {
251
    my ($self) = @_;
251
    my ($self) = @_;
252
252
253
    $self->{_items} ||= Koha::Items->search( { biblionumber => $self->biblionumber() } );
253
    $self->{_items} ||= Koha::Items->search( { biblionumber => $self->biblionumber(), deleted_at => undef } );
254
254
255
    return wantarray ? $self->{_items}->as_list : $self->{_items};
255
    return wantarray ? $self->{_items}->as_list : $self->{_items};
256
}
256
}
(-)a/Koha/Filter/MARC/EmbedItemsAvailability.pm (+1 lines)
Lines 79-84 sub _processrecord { Link Here
79
    my $not_onloan_items = Koha::Items->search({
79
    my $not_onloan_items = Koha::Items->search({
80
        biblionumber => $biblionumber,
80
        biblionumber => $biblionumber,
81
        onloan => undef,
81
        onloan => undef,
82
        deleted_at => undef,
82
    })->count;
83
    })->count;
83
84
84
    # check for field 999
85
    # check for field 999
(-)a/Koha/ItemType.pm (-1 / +1 lines)
Lines 101-107 Counts up the number of biblioitems and items with itemtype (code) and hands bac Link Here
101
101
102
sub can_be_deleted {
102
sub can_be_deleted {
103
    my ($self) = @_;
103
    my ($self) = @_;
104
    my $nb_items = Koha::Items->search( { itype => $self->itemtype } )->count;
104
    my $nb_items = Koha::Items->search( { itype => $self->itemtype, deleted_at => undef } )->count;
105
    my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count;
105
    my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count;
106
    return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
106
    return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
107
}
107
}
(-)a/Koha/OAI/Server/GetRecord.pm (-9 / +5 lines)
Lines 39-59 sub new { Link Here
39
    my $sql = "
39
    my $sql = "
40
        SELECT timestamp
40
        SELECT timestamp
41
        FROM   biblioitems
41
        FROM   biblioitems
42
        WHERE  biblionumber=?
42
        WHERE  biblionumber=? AND deleted_at IS NULL
43
    ";
43
    ";
44
    my @bind_params = ($biblionumber);
44
    my @bind_params = ($biblionumber);
45
    if ( $items_included ) {
45
    if ( $items_included ) {
46
        # Take latest timestamp of biblio and any items
46
        # Take latest timestamp of biblio and any items
47
        $sql .= "
47
        $sql .= "
48
            UNION
48
            UNION
49
            SELECT timestamp from deleteditems
50
            WHERE biblionumber=?
51
            UNION
52
            SELECT timestamp from items
49
            SELECT timestamp from items
53
            WHERE biblionumber=?
50
            WHERE biblionumber=?
54
        ";
51
        ";
55
        push @bind_params, $biblionumber;
52
        push @bind_params, $biblionumber;
56
        push @bind_params, $biblionumber;
57
        $sql = "
53
        $sql = "
58
            SELECT max(timestamp)
54
            SELECT max(timestamp)
59
            FROM ($sql) bib
55
            FROM ($sql) bib
Lines 66-73 sub new { Link Here
66
    unless ( ($timestamp = $sth->fetchrow) ) {
62
    unless ( ($timestamp = $sth->fetchrow) ) {
67
        $sql = "
63
        $sql = "
68
            SELECT timestamp
64
            SELECT timestamp
69
            FROM deletedbiblio
65
            FROM biblio
70
            WHERE biblionumber=?
66
            WHERE biblionumber=? AND deleted_at IS NOT NULL
71
        ";
67
        ";
72
        @bind_params = ($biblionumber);
68
        @bind_params = ($biblionumber);
73
69
Lines 75-82 sub new { Link Here
75
            # Take latest timestamp among biblio and items
71
            # Take latest timestamp among biblio and items
76
            $sql .= "
72
            $sql .= "
77
                UNION
73
                UNION
78
                SELECT timestamp from deleteditems
74
                SELECT timestamp from items
79
                WHERE biblionumber=?
75
                WHERE biblionumber=? AND deleted_at IS NULL
80
            ";
76
            ";
81
            push @bind_params, $biblionumber;
77
            push @bind_params, $biblionumber;
82
            $sql = "
78
            $sql = "
(-)a/Koha/OAI/Server/ListBase.pm (-5 / +5 lines)
Lines 68-79 sub GetRecords { Link Here
68
68
69
        if ($include_items) {
69
        if ($include_items) {
70
            $sql .= "
70
            $sql .= "
71
                OR biblionumber IN (SELECT biblionumber from deleteditems WHERE timestamp >= ? AND timestamp <= ?)
71
                OR biblionumber IN (SELECT biblionumber from items WHERE timestamp >= ? AND timestamp <= ? AND deleted_at IS NOT NULL)
72
            ";
72
            ";
73
            push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'});
73
            push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'});
74
            if (!$deleted) {
74
            if (!$deleted) {
75
                $sql .= "
75
                $sql .= "
76
                    OR biblionumber IN (SELECT biblionumber from items WHERE timestamp >= ? AND timestamp <= ?)
76
                    OR biblionumber IN (SELECT biblionumber from items WHERE timestamp >= ? AND timestamp <= ? AND deleted_at IS NULL)
77
                ";
77
                ";
78
                push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'});
78
                push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'});
79
            }
79
            }
Lines 105-111 sub GetRecords { Link Here
105
                FROM (
105
                FROM (
106
                    SELECT timestamp FROM deletedbiblio_metadata WHERE biblionumber = ?
106
                    SELECT timestamp FROM deletedbiblio_metadata WHERE biblionumber = ?
107
                    UNION
107
                    UNION
108
                    SELECT timestamp FROM deleteditems WHERE biblionumber = ?
108
                    SELECT timestamp FROM items WHERE biblionumber = ? AND deleted_at IS NOT NULL
109
                ) bis
109
                ) bis
110
            ";
110
            ";
111
        } else {
111
        } else {
Lines 114-122 sub GetRecords { Link Here
114
                FROM (
114
                FROM (
115
                    SELECT timestamp FROM biblio_metadata WHERE biblionumber = ?
115
                    SELECT timestamp FROM biblio_metadata WHERE biblionumber = ?
116
                    UNION
116
                    UNION
117
                    SELECT timestamp FROM deleteditems WHERE biblionumber = ?
117
                    SELECT timestamp FROM items WHERE biblionumber = ? AND deleted_at IS NULL
118
                    UNION
118
                    UNION
119
                    SELECT timestamp FROM items WHERE biblionumber = ?
119
                    SELECT timestamp FROM items WHERE biblionumber = ? AND deleted_at IS NOT NULL
120
                ) bi
120
                ) bi
121
            ";
121
            ";
122
        }
122
        }
(-)a/Koha/Patron.pm (-1 / +1 lines)
Lines 246-252 sub do_check_for_previous_checkout { Link Here
246
    my ( $self, $item ) = @_;
246
    my ( $self, $item ) = @_;
247
247
248
    # Find all items for bib and extract item numbers.
248
    # Find all items for bib and extract item numbers.
249
    my @items = Koha::Items->search({biblionumber => $item->{biblionumber}});
249
    my @items = Koha::Items->search({biblionumber => $item->{biblionumber}, deleted_at => undef });
250
    my @item_nos;
250
    my @item_nos;
251
    foreach my $item (@items) {
251
    foreach my $item (@items) {
252
        push @item_nos, $item->itemnumber;
252
        push @item_nos, $item->itemnumber;
(-)a/admin/branches.pl (-1 / +2 lines)
Lines 108-114 if ( $op eq 'add_form' ) { Link Here
108
    my $items_count = Koha::Items->search(
108
    my $items_count = Koha::Items->search(
109
        {   -or => {
109
        {   -or => {
110
                holdingbranch => $branchcode,
110
                holdingbranch => $branchcode,
111
                homebranch    => $branchcode
111
                homebranch    => $branchcode,
112
                deleted_at    => undef,
112
            },
113
            },
113
        }
114
        }
114
    )->count;
115
    )->count;
(-)a/cataloguing/merge.pl (-1 / +1 lines)
Lines 88-94 if ($merge) { Link Here
88
88
89
    # Moving items from the other record to the reference record
89
    # Moving items from the other record to the reference record
90
    foreach my $biblionumber (@biblionumbers) {
90
    foreach my $biblionumber (@biblionumbers) {
91
        my $items = Koha::Items->search({ biblionumber => $biblionumber });
91
        my $items = Koha::Items->search({ biblionumber => $biblionumber, deleted_at => undef });
92
        while ( my $item = $items->next) {
92
        while ( my $item = $items->next) {
93
            my $res = MoveItemFromBiblio( $item->itemnumber, $biblionumber, $ref_biblionumber );
93
            my $res = MoveItemFromBiblio( $item->itemnumber, $biblionumber, $ref_biblionumber );
94
            if ( not defined $res ) {
94
            if ( not defined $res ) {
(-)a/labels/label-item-search.pl (-1 / +1 lines)
Lines 137-143 if ($show_results) { Link Here
137
        push (@results_set, $biblio);
137
        push (@results_set, $biblio);
138
        my $biblionumber = $biblio->{'biblionumber'};
138
        my $biblionumber = $biblio->{'biblionumber'};
139
        #DEBUG Notes: Grab the item numbers associated with this MARC record...
139
        #DEBUG Notes: Grab the item numbers associated with this MARC record...
140
        my $items = Koha::Items->search({ biblionumber => $biblionumber }, { order_by => { -desc => 'itemnumber' }});
140
        my $items = Koha::Items->search({ biblionumber => $biblionumber, deleted_at => undef }, { order_by => { -desc => 'itemnumber' }});
141
        #DEBUG Notes: Retrieve the item data for each number...
141
        #DEBUG Notes: Retrieve the item data for each number...
142
        while ( my $item = $items->next ) {
142
        while ( my $item = $items->next ) {
143
            #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
143
            #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
(-)a/misc/cronjobs/delete_patrons.pl (-1 / +1 lines)
Lines 45-51 cronlogaction(); Link Here
45
45
46
my $members = GetBorrowersToExpunge(
46
my $members = GetBorrowersToExpunge(
47
    {
47
    {
48
        not_borrowed_since => $not_borrowed_since,
48
        not_borrowed_since   => $not_borrowed_since,
49
        expired_before       => $expired_before,
49
        expired_before       => $expired_before,
50
        last_seen            => $last_seen,
50
        last_seen            => $last_seen,
51
        category_code        => $category_code,
51
        category_code        => $category_code,
(-)a/misc/export_records.pl (-15 / +7 lines)
Lines 103-124 $timestamp = ($timestamp) ? output_pref({ dt => dt_from_string($timestamp), date Link Here
103
if ( $record_type eq 'bibs' ) {
103
if ( $record_type eq 'bibs' ) {
104
    if ( $timestamp ) {
104
    if ( $timestamp ) {
105
        push @record_ids, $_->{biblionumber} for @{
105
        push @record_ids, $_->{biblionumber} for @{
106
            $dbh->selectall_arrayref(q| (
106
            $dbh->selectall_arrayref(q|
107
                SELECT biblio_metadata.biblionumber
107
                SELECT biblionumber
108
                FROM biblio_metadata
108
                FROM biblioitems
109
                  LEFT JOIN items USING(biblionumber)
109
             |, { Slice => {} }, ( $timestamp ) x 4 );
110
                WHERE biblio_metadata.timestamp >= ?
111
                  OR items.timestamp >= ?
112
            ) UNION (
113
                SELECT biblio_metadata.biblionumber
114
                FROM biblio_metadata
115
                  LEFT JOIN deleteditems USING(biblionumber)
116
                WHERE biblio_metadata.timestamp >= ?
117
                  OR deleteditems.timestamp >= ?
118
            ) |, { Slice => {} }, ( $timestamp ) x 4 );
119
        };
110
        };
120
    } else {
111
    } else {
121
        my $conditions = {
112
        my $conditions = {
113
            deleted_at => undef,
122
            ( $starting_biblionumber or $ending_biblionumber )
114
            ( $starting_biblionumber or $ending_biblionumber )
123
                ? (
115
                ? (
124
                    "me.biblionumber" => {
116
                    "me.biblionumber" => {
Lines 189-196 if ($deleted_barcodes) { Link Here
189
    for my $record_id ( @record_ids ) {
181
    for my $record_id ( @record_ids ) {
190
        my $barcode = $dbh->selectall_arrayref(q|
182
        my $barcode = $dbh->selectall_arrayref(q|
191
            SELECT DISTINCT barcode
183
            SELECT DISTINCT barcode
192
            FROM deleteditems
184
            FROM items
193
            WHERE deleteditems.biblionumber = ?
185
            WHERE deleteditems.biblionumber = ? AND deleted_at IS NOT NULL
194
        |, { Slice => {} }, $record_id );
186
        |, { Slice => {} }, $record_id );
195
        say $_->{barcode} for @$barcode;
187
        say $_->{barcode} for @$barcode;
196
    }
188
    }
(-)a/opac/opac-reserve.pl (-2 / +2 lines)
Lines 294-300 if ( $query->param('place_reserve') ) { Link Here
294
        }
294
        }
295
295
296
        unless ( $can_place_hold_if_available_at_pickup ) {
296
        unless ( $can_place_hold_if_available_at_pickup ) {
297
            my $items_in_this_library = Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch });
297
            my $items_in_this_library = Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch, deleted_at => undef });
298
            my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
298
            my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
299
            my $nb_of_items_unavailable = $items_in_this_library->search({ -or => { lost => { '!=' => 0 }, damaged => { '!=' => 0 }, } });
299
            my $nb_of_items_unavailable = $items_in_this_library->search({ -or => { lost => { '!=' => 0 }, damaged => { '!=' => 0 }, } });
300
            if ( $items_in_this_library->count > $nb_of_items_issued + $nb_of_items_unavailable ) {
300
            if ( $items_in_this_library->count > $nb_of_items_issued + $nb_of_items_unavailable ) {
Lines 545-551 foreach my $biblioNum (@biblionumbers) { Link Here
545
            $numCopiesAvailable++;
545
            $numCopiesAvailable++;
546
546
547
            unless ( $can_place_hold_if_available_at_pickup ) {
547
            unless ( $can_place_hold_if_available_at_pickup ) {
548
                my $items_in_this_library = Koha::Items->search({ biblionumber => $itemInfo->{biblionumber}, holdingbranch => $itemInfo->{holdingbranch} });
548
                my $items_in_this_library = Koha::Items->search({ biblionumber => $itemInfo->{biblionumber}, holdingbranch => $itemInfo->{holdingbranch}, deleted_at => undef });
549
                my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
549
                my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
550
                if ( $items_in_this_library->count > $nb_of_items_issued ) {
550
                if ( $items_in_this_library->count > $nb_of_items_issued ) {
551
                    push @not_available_at, $itemInfo->{holdingbranch};
551
                    push @not_available_at, $itemInfo->{holdingbranch};
(-)a/reports/catalogue_stats.pl (-10 / +9 lines)
Lines 172-178 sub calculate { Link Here
172
    my $barcodelike   = @$filters[16];
172
    my $barcodelike   = @$filters[16];
173
    my $barcodefilter = @$filters[17];
173
    my $barcodefilter = @$filters[17];
174
    my $not;
174
    my $not;
175
    my $itemstable = ($cellvalue eq 'deleteditems') ? 'deleteditems' : 'items';
175
    my $itemstable = 'items';
176
    my $deleted_where = "items.deleted_at IS NULL";
177
    $deleted_where = "1" if $cellvalue eq 'allitems';
178
    $deleted_where = "items.deleted_at IS NOT NULL" if $cellvalue eq 'deleteditems';
176
179
177
    my $dbh = C4::Context->dbh;
180
    my $dbh = C4::Context->dbh;
178
181
Lines 273-284 sub calculate { Link Here
273
276
274
    # 1st, loop rows.
277
    # 1st, loop rows.
275
    my $origline = $line;
278
    my $origline = $line;
276
    $line =~ s/^items\./deleteditems./ if($cellvalue eq "deleteditems");
277
    my $linefield;
279
    my $linefield;
278
    if ( ( $line =~ /itemcallnumber/ ) and ($cotedigits) ) {
280
    if ( ( $line =~ /itemcallnumber/ ) and ($cotedigits) ) {
279
        $linefield = "left($line,$cotedigits)";
281
        $linefield = "left($line,$cotedigits)";
280
    } elsif ( $line =~ /^deleteditems\.timestamp$/ ) {
281
        $linefield = "DATE($line)";
282
    } else {
282
    } else {
283
        $linefield = $line;
283
        $linefield = $line;
284
    }
284
    }
Lines 286-292 sub calculate { Link Here
286
    my $strsth = "SELECT DISTINCTROW $linefield FROM $itemstable
286
    my $strsth = "SELECT DISTINCTROW $linefield FROM $itemstable
287
                    LEFT JOIN biblioitems USING (biblioitemnumber)
287
                    LEFT JOIN biblioitems USING (biblioitemnumber)
288
                    LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber)
288
                    LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber)
289
                  WHERE 1 ";
289
                  WHERE $deleted_where ";
290
    $strsth .= " AND barcode $not LIKE ? " if ($barcodefilter);
290
    $strsth .= " AND barcode $not LIKE ? " if ($barcodefilter);
291
    if (@linefilter) {
291
    if (@linefilter) {
292
        if ( $linefilter[1] ) {
292
        if ( $linefilter[1] ) {
Lines 335-341 sub calculate { Link Here
335
335
336
    # 2nd, loop cols.
336
    # 2nd, loop cols.
337
    my $origcolumn = $column;
337
    my $origcolumn = $column;
338
    $column =~ s/^items\./deleteditems./ if($cellvalue eq "deleteditems");
339
    my $colfield;
338
    my $colfield;
340
    if ( ( $column =~ /itemcallnumber/ ) and ($cotedigits) ) {
339
    if ( ( $column =~ /itemcallnumber/ ) and ($cotedigits) ) {
341
        $colfield = "left($column,$cotedigits)";
340
        $colfield = "left($column,$cotedigits)";
Lines 352-358 sub calculate { Link Here
352
            USING (biblioitemnumber)
351
            USING (biblioitemnumber)
353
        LEFT JOIN biblio
352
        LEFT JOIN biblio
354
            ON (biblioitems.biblionumber = biblio.biblionumber)
353
            ON (biblioitems.biblionumber = biblio.biblionumber)
355
        WHERE 1 ";
354
        WHERE $deleted_where ";
356
    $strsth2 .= " AND barcode $not LIKE ?" if $barcodefilter;
355
    $strsth2 .= " AND barcode $not LIKE ?" if $barcodefilter;
357
356
358
    if ( (@colfilter) and ( $colfilter[1] ) ) {
357
    if ( (@colfilter) and ( $colfilter[1] ) ) {
Lines 418-424 sub calculate { Link Here
418
        FROM $itemstable
417
        FROM $itemstable
419
        LEFT JOIN biblioitems ON ($itemstable.biblioitemnumber = biblioitems.biblioitemnumber)
418
        LEFT JOIN biblioitems ON ($itemstable.biblioitemnumber = biblioitems.biblioitemnumber)
420
        LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber)
419
        LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber)
421
        WHERE 1 ";
420
        WHERE $deleted_where ";
422
421
423
    my @sqlargs;
422
    my @sqlargs;
424
423
Lines 501-513 sub calculate { Link Here
501
        push @sqlargs, @$filters[14];
500
        push @sqlargs, @$filters[14];
502
    }
501
    }
503
    if ( $cellvalue eq 'deleteditems' and @$filters[15] ) {
502
    if ( $cellvalue eq 'deleteditems' and @$filters[15] ) {
504
        $strcalc .= " AND DATE(deleteditems.timestamp) >= ? ";
503
        $strcalc .= " AND DATE(deleted_at) >= ? ";
505
        @$filters[15] =~ s/\*/%/g;
504
        @$filters[15] =~ s/\*/%/g;
506
        push @sqlargs, @$filters[15];
505
        push @sqlargs, @$filters[15];
507
    }
506
    }
508
    if ( $cellvalue eq 'deleteditems' and @$filters[16] ) {
507
    if ( $cellvalue eq 'deleteditems' and @$filters[16] ) {
509
        @$filters[16] =~ s/\*/%/g;
508
        @$filters[16] =~ s/\*/%/g;
510
        $strcalc .= " AND DATE(deleteditems.timestamp) <= ?";
509
        $strcalc .= " AND DATE(deleted_at) <= ?";
511
        push @sqlargs, @$filters[16];
510
        push @sqlargs, @$filters[16];
512
    }
511
    }
513
    $strcalc .= " group by $linefield, $colfield order by $linefield,$colfield";
512
    $strcalc .= " group by $linefield, $colfield order by $linefield,$colfield";
(-)a/reports/itemslost.pl (-1 / +1 lines)
Lines 115-120 if ( $op eq 'export' ) { Link Here
115
    my $notforloanfilter = $params->{'notforloanfilter'} || undef;
115
    my $notforloanfilter = $params->{'notforloanfilter'} || undef;
116
116
117
    my $params = {
117
    my $params = {
118
        deleted_at => undef,
118
        ( $branchfilter ? ( homebranch => $branchfilter ) : () ),
119
        ( $branchfilter ? ( homebranch => $branchfilter ) : () ),
119
        (
120
        (
120
            $loststatusfilter
121
            $loststatusfilter
121
- 

Return to bug 20271