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

(-)a/C4/Items.pm (-3 / +11 lines)
Lines 648-655 sub DelItem { Link Here
648
        $biblionumber = C4::Biblio::GetBiblionumberFromItemnumber($itemnumber);
648
        $biblionumber = C4::Biblio::GetBiblionumberFromItemnumber($itemnumber);
649
    }
649
    }
650
650
651
    # If there is no biblionumber for the given itemnumber, there is nothing to delete
652
    return 0 unless $biblionumber;
653
651
    # FIXME check the item has no current issues
654
    # FIXME check the item has no current issues
652
    _koha_delete_item( $itemnumber );
655
    my $deleted = _koha_delete_item( $itemnumber );
653
656
654
    # get the MARC record
657
    # get the MARC record
655
    my $record = GetMarcBiblio($biblionumber);
658
    my $record = GetMarcBiblio($biblionumber);
Lines 657-662 sub DelItem { Link Here
657
660
658
    #search item field code
661
    #search item field code
659
    logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
662
    logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
663
    return $deleted;
660
}
664
}
661
665
662
=head2 CheckItemPreSave
666
=head2 CheckItemPreSave
Lines 2355-2360 sub _koha_delete_item { Link Here
2355
    my $sth = $dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
2359
    my $sth = $dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
2356
    $sth->execute($itemnum);
2360
    $sth->execute($itemnum);
2357
    my $data = $sth->fetchrow_hashref();
2361
    my $data = $sth->fetchrow_hashref();
2362
2363
    # There is no item to delete
2364
    return 0 unless $data;
2365
2358
    my $query = "INSERT INTO deleteditems SET ";
2366
    my $query = "INSERT INTO deleteditems SET ";
2359
    my @bind  = ();
2367
    my @bind  = ();
2360
    foreach my $key ( keys %$data ) {
2368
    foreach my $key ( keys %$data ) {
Lines 2368-2375 sub _koha_delete_item { Link Here
2368
2376
2369
    # delete from items table
2377
    # delete from items table
2370
    $sth = $dbh->prepare("DELETE FROM items WHERE itemnumber=?");
2378
    $sth = $dbh->prepare("DELETE FROM items WHERE itemnumber=?");
2371
    $sth->execute($itemnum);
2379
    my $deleted = $sth->execute($itemnum);
2372
    return;
2380
    return ( $deleted == 1 ) ? 1 : 0;
2373
}
2381
}
2374
2382
2375
=head2 _marc_from_item_hash
2383
=head2 _marc_from_item_hash
(-)a/t/db_dependent/Items/DelItem.t (-1 / +49 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
3
use MARC::Record;
4
use C4::Biblio;
5
6
use Test::More tests => 7;
7
8
BEGIN {
9
    use_ok('C4::Items');
10
}
11
12
my $dbh = C4::Context->dbh;
13
$dbh->{AutoCommit} = 0;
14
$dbh->{RaiseError} = 1;
15
16
my ( $biblionumber, $bibitemnum ) = get_biblio();
17
18
my ( $item_bibnum, $item_bibitemnum, $itemnumber );
19
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
20
  AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $biblionumber );
21
22
my $deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } );
23
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
24
my $deleted_item = GetItem($itemnumber);
25
is( $deleted_item->{itemnumber}, undef, "DelItem with biblionumber parameter - the item should be deleted." );
26
27
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
28
  AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $biblionumber );
29
$deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } );
30
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
31
$deleted_item = GetItem($itemnumber);
32
is( $deleted_item->{itemnumber}, undef, "DelItem without biblionumber parameter - the item should be deleted." );
33
34
$deleted = DelItem( { itemnumber => $itemnumber + 1} );
35
is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" );
36
37
$deleted = DelItem( { itemnumber => $itemnumber + 1, biblionumber => $biblionumber } );
38
is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" );
39
40
# Helper method to set up a Biblio.
41
sub get_biblio {
42
    my $bib = MARC::Record->new();
43
    $bib->append_fields(
44
        MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
45
        MARC::Field->new( '245', ' ', ' ', a => 'Silence in the library' ),
46
    );
47
    my ( $bibnum, $bibitemnum ) = AddBiblio( $bib, '' );
48
    return ( $bibnum, $bibitemnum );
49
}

Return to bug 12583