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

(-)a/C4/Acquisition.pm (-1 / +1 lines)
Lines 1790-1796 sub DelOrder { Link Here
1790
1790
1791
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1791
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1792
    foreach my $itemnumber (@itemnumbers){
1792
    foreach my $itemnumber (@itemnumbers){
1793
        my $delcheck = C4::Items::DelItemCheck( $dbh, $bibnum, $itemnumber );
1793
        my $delcheck = C4::Items::DelItemCheck( $bibnum, $itemnumber );
1794
1794
1795
        if($delcheck != 1) {
1795
        if($delcheck != 1) {
1796
            $error->{'delitem'} = 1;
1796
            $error->{'delitem'} = 1;
(-)a/C4/ImportBatch.pm (-1 / +1 lines)
Lines 923-929 sub BatchRevertItems { Link Here
923
    $sth->bind_param(1, $import_record_id);
923
    $sth->bind_param(1, $import_record_id);
924
    $sth->execute();
924
    $sth->execute();
925
    while (my $row = $sth->fetchrow_hashref()) {
925
    while (my $row = $sth->fetchrow_hashref()) {
926
        my $error = DelItemCheck($dbh, $biblionumber, $row->{'itemnumber'});
926
        my $error = DelItemCheck( $biblionumber, $row->{'itemnumber'});
927
        if ($error == 1){
927
        if ($error == 1){
928
            my $updsth = $dbh->prepare("UPDATE import_items SET status = ? WHERE import_items_id = ?");
928
            my $updsth = $dbh->prepare("UPDATE import_items SET status = ? WHERE import_items_id = ?");
929
            $updsth->bind_param(1, 'reverted');
929
            $updsth->bind_param(1, 'reverted');
(-)a/C4/Items.pm (-10 / +6 lines)
Lines 2311-2317 sub MoveItemFromBiblio { Link Here
2311
2311
2312
=head2 ItemSafeToDelete
2312
=head2 ItemSafeToDelete
2313
2313
2314
   ItemSafeToDelete($dbh, $biblionumber, $itemnumber);
2314
   ItemSafeToDelete( $biblionumber, $itemnumber);
2315
2315
2316
Exported function (core API) for checking whether an item record is safe to delete.
2316
Exported function (core API) for checking whether an item record is safe to delete.
2317
2317
Lines 2328-2336 returns 1 if the item is safe to delete, Link Here
2328
=cut
2328
=cut
2329
2329
2330
sub ItemSafeToDelete {
2330
sub ItemSafeToDelete {
2331
    my ( $dbh, $biblionumber, $itemnumber ) = @_;
2331
    my ( $biblionumber, $itemnumber ) = @_;
2332
    my $status;
2332
    my $status;
2333
    $dbh ||= C4::Context->dbh;
2333
    my $dbh = C4::Context->dbh;
2334
2334
2335
    my $error;
2335
    my $error;
2336
2336
Lines 2384-2404 sub ItemSafeToDelete { Link Here
2384
2384
2385
=head2 DelItemCheck
2385
=head2 DelItemCheck
2386
2386
2387
   DelItemCheck($dbh, $biblionumber, $itemnumber);
2387
   DelItemCheck( $biblionumber, $itemnumber);
2388
2388
2389
Exported function (core API) for deleting an item record in Koha if there no current issue.
2389
Exported function (core API) for deleting an item record in Koha if there no current issue.
2390
2390
2391
DelItemCheck wraps ItemSafeToDelete around DelItem.
2391
DelItemCheck wraps ItemSafeToDelete around DelItem.
2392
2392
2393
It takes a database handle, biblionumber and itemnumber as arguments:
2394
2395
    DelItemCheck(  $dbh, $biblionumber, $itemnumber );
2396
2397
=cut
2393
=cut
2398
2394
2399
sub DelItemCheck {
2395
sub DelItemCheck {
2400
    my ( $dbh, $biblionumber, $itemnumber ) = @_;
2396
    my ( $biblionumber, $itemnumber ) = @_;
2401
    my $status = ItemSafeToDelete( $dbh, $biblionumber, $itemnumber );
2397
    my $status = ItemSafeToDelete( $biblionumber, $itemnumber );
2402
2398
2403
    if ( $status == 1 ) {
2399
    if ( $status == 1 ) {
2404
        DelItem(
2400
        DelItem(
(-)a/cataloguing/additem.pl (-2 / +2 lines)
Lines 622-628 if ($op eq "additem") { Link Here
622
} elsif ($op eq "delitem") {
622
} elsif ($op eq "delitem") {
623
#-------------------------------------------------------------------------------
623
#-------------------------------------------------------------------------------
624
    # check that there is no issue on this item before deletion.
624
    # check that there is no issue on this item before deletion.
625
    $error = &DelItemCheck($dbh,$biblionumber,$itemnumber);
625
    $error = &DelItemCheck( $biblionumber,$itemnumber);
626
    if($error == 1){
626
    if($error == 1){
627
        print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
627
        print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
628
    }else{
628
    }else{
Lines 639-645 if ($op eq "additem") { Link Here
639
        my $items = &GetItemsByBiblioitemnumber( $biblioitem->{biblioitemnumber} );
639
        my $items = &GetItemsByBiblioitemnumber( $biblioitem->{biblioitemnumber} );
640
640
641
        foreach my $item (@$items) {
641
        foreach my $item (@$items) {
642
            $error =&DelItemCheck( $dbh, $biblionumber, $item->{itemnumber} );
642
            $error =&DelItemCheck( $biblionumber, $item->{itemnumber} );
643
            $itemfail =$item;
643
            $itemfail =$item;
644
        if($error == 1){
644
        if($error == 1){
645
            next
645
            next
(-)a/misc/cronjobs/delete_items.pl (-2 / +2 lines)
Lines 57-65 $GLOBAL->{sth}->{target_items}->execute(); Link Here
57
57
58
DELITEM: while ( my $item = $GLOBAL->{sth}->{target_items}->fetchrow_hashref() ) {
58
DELITEM: while ( my $item = $GLOBAL->{sth}->{target_items}->fetchrow_hashref() ) {
59
59
60
    my $status = C4::Items::ItemSafeToDelete( $dbh, $item->{itemnumber}, $item->{biblionumber} );
60
    my $status = C4::Items::ItemSafeToDelete( $item->{itemnumber}, $item->{biblionumber} );
61
    if( $status == 1 )  {
61
    if( $status == 1 )  {
62
        C4::Items::DelItemCheck( $dbh, $item->{itemnumber}, $item->{biblionumber} );
62
        C4::Items::DelItemCheck( $item->{itemnumber}, $item->{biblionumber} );
63
        verbose "Deleting '$item->{itemnumber}'";
63
        verbose "Deleting '$item->{itemnumber}'";
64
    } else {
64
    } else {
65
        verbose "Item '$item->{itemnumber}' not deletd: $status";
65
        verbose "Item '$item->{itemnumber}' not deletd: $status";
(-)a/t/db_dependent/Circulation/IsItemIssued.t (-2 / +2 lines)
Lines 44-50 AddIssue($borrower, 'i_dont_exist'); Link Here
44
is ( IsItemIssued( $item->{itemnumber} ), 1, "item is now on loan" );
44
is ( IsItemIssued( $item->{itemnumber} ), 1, "item is now on loan" );
45
45
46
is(
46
is(
47
    DelItemCheck($dbh, $biblionumber, $itemnumber),
47
    DelItemCheck( $biblionumber, $itemnumber),
48
    'book_on_loan',
48
    'book_on_loan',
49
    'item that is on loan cannot be deleted',
49
    'item that is on loan cannot be deleted',
50
);
50
);
Lines 53-59 AddReturn('i_dont_exist', $library->{branchcode}); Link Here
53
is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
53
is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
54
54
55
is(
55
is(
56
    DelItemCheck($dbh, $biblionumber, $itemnumber),
56
    DelItemCheck( $biblionumber, $itemnumber),
57
    1,
57
    1,
58
    'item that is not on loan can be deleted',
58
    'item that is not on loan can be deleted',
59
);
59
);
(-)a/t/db_dependent/Items_DelItemCheck.t (-9 / +9 lines)
Lines 72-84 my $item = $builder->build( Link Here
72
AddIssue( $patron, $item->{barcode} );
72
AddIssue( $patron, $item->{barcode} );
73
73
74
is(
74
is(
75
    ItemSafeToDelete($dbh, $biblio->{biblionumber}, $item->{itemnumber} ),
75
    ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
76
    'book_on_loan',
76
    'book_on_loan',
77
    'ItemSafeToDelete reports item on loan',
77
    'ItemSafeToDelete reports item on loan',
78
);
78
);
79
79
80
is(
80
is(
81
    DelItemCheck($dbh, $biblio->{biblionumber}, $item->{itemnumber} ),
81
    DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} ),
82
    'book_on_loan',
82
    'book_on_loan',
83
    'item that is on loan cannot be deleted',
83
    'item that is on loan cannot be deleted',
84
);
84
);
Lines 92-104 t::lib::Mocks::mock_preference('IndependentBranches', 1); Link Here
92
ModItem( { homebranch => $branch2->{branchcode}, holdingbranch => $branch2->{branchcode} }, $biblio->{biblionumber}, $item->{itemnumber} );
92
ModItem( { homebranch => $branch2->{branchcode}, holdingbranch => $branch2->{branchcode} }, $biblio->{biblionumber}, $item->{itemnumber} );
93
93
94
is(
94
is(
95
    ItemSafeToDelete($dbh, $biblio->{biblionumber}, $item->{itemnumber} ),
95
    ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
96
    'not_same_branch',
96
    'not_same_branch',
97
    'ItemSafeToDelete reports IndependentBranches restriction',
97
    'ItemSafeToDelete reports IndependentBranches restriction',
98
);
98
);
99
99
100
is(
100
is(
101
    DelItemCheck($dbh, $biblio->{biblionumber}, $item->{itemnumber} ),
101
    DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} ),
102
    'not_same_branch',
102
    'not_same_branch',
103
    'IndependentBranches prevents deletion at another branch',
103
    'IndependentBranches prevents deletion at another branch',
104
);
104
);
Lines 113-125 ModItem( { homebranch => $branch->{branchcode}, holdingbranch => $branch->{branc Link Here
113
    $module->mock( GetAnalyticsCount => sub { return 1 } );
113
    $module->mock( GetAnalyticsCount => sub { return 1 } );
114
114
115
    is(
115
    is(
116
        ItemSafeToDelete($dbh, $biblio->{biblionumber}, $item->{itemnumber} ),
116
        ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
117
        'linked_analytics',
117
        'linked_analytics',
118
        'ItemSafeToDelete reports linked analytics',
118
        'ItemSafeToDelete reports linked analytics',
119
    );
119
    );
120
120
121
    is(
121
    is(
122
        DelItemCheck($dbh, $biblio->{biblionumber}, $item->{itemnumber} ),
122
        DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} ),
123
        'linked_analytics',
123
        'linked_analytics',
124
        'Linked analytics prevents deletion of item',
124
        'Linked analytics prevents deletion of item',
125
    );
125
    );
Lines 127-143 ModItem( { homebranch => $branch->{branchcode}, holdingbranch => $branch->{branc Link Here
127
}
127
}
128
128
129
is(
129
is(
130
    ItemSafeToDelete($dbh, $biblio->{biblionumber}, $item->{itemnumber} ),
130
    ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
131
    1,
131
    1,
132
    'ItemSafeToDelete shows item safe to delete'
132
    'ItemSafeToDelete shows item safe to delete'
133
);
133
);
134
134
135
DelItemCheck( $dbh, $biblio->{biblionumber}, $item->{itemnumber} );
135
DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} );
136
136
137
my $test_item = GetItem( $item->{itemnumber} );
137
my $test_item = GetItem( $item->{itemnumber} );
138
138
139
is( $test_item->{itemnumber}, undef,
139
is( $test_item->{itemnumber}, undef,
140
    "DelItemCheck should delete item if 'do_not_commit' not set"
140
    "DelItemCheck should delete item if ItemSafeToDelete returns true"
141
);
141
);
142
142
143
# End of testing
143
# End of testing
(-)a/t/db_dependent/Reserves.t (-1 / +1 lines)
Lines 371-377 is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 1 Link Here
371
# avoiding the not_same_branch error
371
# avoiding the not_same_branch error
372
t::lib::Mocks::mock_preference('IndependentBranches', 0);
372
t::lib::Mocks::mock_preference('IndependentBranches', 0);
373
is(
373
is(
374
    DelItemCheck($dbh, $bibnum, $itemnumber),
374
    DelItemCheck( $bibnum, $itemnumber),
375
    'book_reserved',
375
    'book_reserved',
376
    'item that is captured to fill a hold cannot be deleted',
376
    'item that is captured to fill a hold cannot be deleted',
377
);
377
);
(-)a/tools/batchMod.pl (-1 / +1 lines)
Lines 166-172 if ($op eq "action") { Link Here
166
		$job->progress($i) if $runinbackground;
166
		$job->progress($i) if $runinbackground;
167
		my $itemdata = GetItem($itemnumber);
167
		my $itemdata = GetItem($itemnumber);
168
        if ( $del ){
168
        if ( $del ){
169
			my $return = DelItemCheck(C4::Context->dbh, $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
169
            my $return = DelItemCheck( $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
170
			if ($return == 1) {
170
			if ($return == 1) {
171
			    $deleted_items++;
171
			    $deleted_items++;
172
			} else {
172
			} else {
(-)a/tools/batch_delete_records.pl (-2 / +1 lines)
Lines 159-165 if ( $op eq 'form' ) { Link Here
159
            # Delete items
159
            # Delete items
160
            my @itemnumbers = @{ C4::Items::GetItemnumbersForBiblio( $biblionumber ) };
160
            my @itemnumbers = @{ C4::Items::GetItemnumbersForBiblio( $biblionumber ) };
161
            ITEMNUMBER: for my $itemnumber ( @itemnumbers ) {
161
            ITEMNUMBER: for my $itemnumber ( @itemnumbers ) {
162
                my $error = eval { C4::Items::DelItemCheck( $dbh, $biblionumber, $itemnumber ) };
162
                my $error = eval { C4::Items::DelItemCheck( $biblionumber, $itemnumber ) };
163
                if ( $error != 1 or $@ ) {
163
                if ( $error != 1 or $@ ) {
164
                    push @messages, {
164
                    push @messages, {
165
                        type => 'error',
165
                        type => 'error',
166
- 

Return to bug 14504