Bug 14544: Get rid of DelShelf
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 15 Jul 2015 16:16:34 +0000 (17:16 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Thu, 5 Nov 2015 12:58:00 +0000 (09:58 -0300)
Signed-off-by: Alex Arnaud <alex.arnaud@biblibre.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/VirtualShelves.pm
C4/VirtualShelves/Page.pm
t/db_dependent/VirtualShelves.t
t/db_dependent/Virtualshelves.t

index 0f5e900..e7201f0 100644 (file)
@@ -44,7 +44,7 @@ BEGIN {
             &AddToShelf
             &ModShelf
             &ShelfPossibleAction
-            &DelFromShelf &DelShelf
+            &DelFromShelf
             &GetBibliosShelves
             &AddShare &AcceptShare &RemoveShare &IsSharedList
     );
@@ -508,24 +508,6 @@ sub DelFromShelf {
     return $t;
 }
 
-=head2 DelShelf
-
-  $Number = DelShelf($shelfnumber);
-
-This function deletes the shelf number, and all of it's content.
-Authorization to do so MUST have been checked before calling, while using
-ShelfPossibleAction with manage parameter.
-
-=cut
-
-sub DelShelf {
-    my ($shelfnumber)= @_;
-    return unless $shelfnumber && $shelfnumber =~ /^\d+$/;
-    my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("DELETE FROM virtualshelves WHERE shelfnumber=?");
-    return $sth->execute($shelfnumber);
-}
-
 =head2 GetBibliosShelves
 
 This finds all the public lists that this bib record is in.
@@ -596,8 +578,8 @@ sub HandleDelBorrower {
     #Instead of deleting we could also disown lists (based on a pref).
     #In that way we could save shared and public lists.
     #The current table constraints support that idea now.
-    #This pref should then govern the results of other routines such as
-    #DelShelf too.
+    #This pref should then govern the results of other routines/methods such as
+    #Koha::Virtualshelf->new->delete too.
 }
 
 =head2 AddShare
index 9e3b39d..8d7bb5f 100644 (file)
@@ -418,7 +418,7 @@ sub shelfpage {
                     $name = $shelflist->{$number}->{'shelfname'};
                     delete $shelflist->{$number};
                 }
-                unless ( DelShelf($number) ) {
+                unless( Koha::Virtualshelves->find($number)->delete ) {
                     push( @paramsloop, { delete_fail => $name } );
                     last;
                 }
index 07933c5..f4dc31d 100755 (executable)
@@ -173,15 +173,15 @@ for my $i (0..9) {
     is(IsSharedList($sh),$n? 1: '', "Checked IsSharedList for shelf $sh");
 }
 
-#----------------TEST DelShelf & DelFromShelf functions------------------------#
+#----------------TEST Koha::Virtualshelf->delete & DelFromShelf functions------------------------#
 
 for my $i (0..9){
     my $shelfnumber = $shelves[$i]->{number};
     if($shelfnumber<0) {
-        ok(1, 'Skip DelShelf for shelf -1');
+        ok(1, 'Skip Koha::Virtualshelf->delete for shelf -1');
         next;
     }
-    my $status = DelShelf($shelfnumber);
+    my $status = Koha::Virtualshelves->find($shelfnumber)->delete;
     is($status, 1, "deleted shelf $shelfnumber and its contents");
 }
 
index bfd2dc0..407011f 100644 (file)
@@ -18,7 +18,7 @@ $dbh->do(q|DELETE FROM virtualshelves|);
 my $builder = t::lib::TestBuilder->new;
 
 subtest 'CRUD' => sub {
-    plan tests => 11;
+    plan tests => 13;
     my $patron = $builder->build({
         source => 'Borrower',
     });
@@ -72,4 +72,9 @@ subtest 'CRUD' => sub {
     )->store;
     $number_of_shelves = Koha::Virtualshelves->search->count;
     is( $number_of_shelves, 2, 'Another patron should be able to create a shelf with an existing shelfname');
+
+    my $is_deleted = Koha::Virtualshelves->find( $shelf->shelfnumber )->delete;
+    is( $is_deleted, 1, 'The shelf has been deleted correctly' );
+    $number_of_shelves = Koha::Virtualshelves->search->count;
+    is( $number_of_shelves, 1, 'To be sure the shelf has been deleted' );
 };