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

(-)a/C4/VirtualShelves.pm (-21 / +3 lines)
Lines 44-50 BEGIN { Link Here
44
            &AddToShelf
44
            &AddToShelf
45
            &ModShelf
45
            &ModShelf
46
            &ShelfPossibleAction
46
            &ShelfPossibleAction
47
            &DelFromShelf &DelShelf
47
            &DelFromShelf
48
            &GetBibliosShelves
48
            &GetBibliosShelves
49
            &AddShare &AcceptShare &RemoveShare &IsSharedList
49
            &AddShare &AcceptShare &RemoveShare &IsSharedList
50
    );
50
    );
Lines 508-531 sub DelFromShelf { Link Here
508
    return $t;
508
    return $t;
509
}
509
}
510
510
511
=head2 DelShelf
512
513
  $Number = DelShelf($shelfnumber);
514
515
This function deletes the shelf number, and all of it's content.
516
Authorization to do so MUST have been checked before calling, while using
517
ShelfPossibleAction with manage parameter.
518
519
=cut
520
521
sub DelShelf {
522
    my ($shelfnumber)= @_;
523
    return unless $shelfnumber && $shelfnumber =~ /^\d+$/;
524
    my $dbh = C4::Context->dbh;
525
    my $sth = $dbh->prepare("DELETE FROM virtualshelves WHERE shelfnumber=?");
526
    return $sth->execute($shelfnumber);
527
}
528
529
=head2 GetBibliosShelves
511
=head2 GetBibliosShelves
530
512
531
This finds all the public lists that this bib record is in.
513
This finds all the public lists that this bib record is in.
Lines 596-603 sub HandleDelBorrower { Link Here
596
    #Instead of deleting we could also disown lists (based on a pref).
578
    #Instead of deleting we could also disown lists (based on a pref).
597
    #In that way we could save shared and public lists.
579
    #In that way we could save shared and public lists.
598
    #The current table constraints support that idea now.
580
    #The current table constraints support that idea now.
599
    #This pref should then govern the results of other routines such as
581
    #This pref should then govern the results of other routines/methods such as
600
    #DelShelf too.
582
    #Koha::Virtualshelf->new->delete too.
601
}
583
}
602
584
603
=head2 AddShare
585
=head2 AddShare
(-)a/C4/VirtualShelves/Page.pm (-1 / +1 lines)
Lines 418-424 sub shelfpage { Link Here
418
                    $name = $shelflist->{$number}->{'shelfname'};
418
                    $name = $shelflist->{$number}->{'shelfname'};
419
                    delete $shelflist->{$number};
419
                    delete $shelflist->{$number};
420
                }
420
                }
421
                unless ( DelShelf($number) ) {
421
                unless( Koha::Virtualshelves->find($number)->delete ) {
422
                    push( @paramsloop, { delete_fail => $name } );
422
                    push( @paramsloop, { delete_fail => $name } );
423
                    last;
423
                    last;
424
                }
424
                }
(-)a/t/db_dependent/VirtualShelves.t (-3 / +3 lines)
Lines 173-187 for my $i (0..9) { Link Here
173
    is(IsSharedList($sh),$n? 1: '', "Checked IsSharedList for shelf $sh");
173
    is(IsSharedList($sh),$n? 1: '', "Checked IsSharedList for shelf $sh");
174
}
174
}
175
175
176
#----------------TEST DelShelf & DelFromShelf functions------------------------#
176
#----------------TEST Koha::Virtualshelf->delete & DelFromShelf functions------------------------#
177
177
178
for my $i (0..9){
178
for my $i (0..9){
179
    my $shelfnumber = $shelves[$i]->{number};
179
    my $shelfnumber = $shelves[$i]->{number};
180
    if($shelfnumber<0) {
180
    if($shelfnumber<0) {
181
        ok(1, 'Skip DelShelf for shelf -1');
181
        ok(1, 'Skip Koha::Virtualshelf->delete for shelf -1');
182
        next;
182
        next;
183
    }
183
    }
184
    my $status = DelShelf($shelfnumber);
184
    my $status = Koha::Virtualshelves->find($shelfnumber)->delete;
185
    is($status, 1, "deleted shelf $shelfnumber and its contents");
185
    is($status, 1, "deleted shelf $shelfnumber and its contents");
186
}
186
}
187
187
(-)a/t/db_dependent/Virtualshelves.t (-2 / +6 lines)
Lines 18-24 $dbh->do(q|DELETE FROM virtualshelves|); Link Here
18
my $builder = t::lib::TestBuilder->new;
18
my $builder = t::lib::TestBuilder->new;
19
19
20
subtest 'CRUD' => sub {
20
subtest 'CRUD' => sub {
21
    plan tests => 11;
21
    plan tests => 13;
22
    my $patron = $builder->build({
22
    my $patron = $builder->build({
23
        source => 'Borrower',
23
        source => 'Borrower',
24
    });
24
    });
Lines 72-75 subtest 'CRUD' => sub { Link Here
72
    )->store;
72
    )->store;
73
    $number_of_shelves = Koha::Virtualshelves->search->count;
73
    $number_of_shelves = Koha::Virtualshelves->search->count;
74
    is( $number_of_shelves, 2, 'Another patron should be able to create a shelf with an existing shelfname');
74
    is( $number_of_shelves, 2, 'Another patron should be able to create a shelf with an existing shelfname');
75
76
    my $is_deleted = Koha::Virtualshelves->find( $shelf->shelfnumber )->delete;
77
    is( $is_deleted, 1, 'The shelf has been deleted correctly' );
78
    $number_of_shelves = Koha::Virtualshelves->search->count;
79
    is( $number_of_shelves, 1, 'To be sure the shelf has been deleted' );
75
};
80
};
76
- 

Return to bug 14544