From fd48d5c7a1d6e98f589691267302f93fecc563f3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 15 Jul 2015 17:26:09 +0100 Subject: [PATCH] Bug 14544: Get rid of ModShelf Signed-off-by: Alex Arnaud Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- C4/VirtualShelves.pm | 56 --------------------------------------- C4/VirtualShelves/Page.pm | 20 +++++++------- 2 files changed, 10 insertions(+), 66 deletions(-) diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index e7201f0134..c0bc12d07c 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -42,7 +42,6 @@ BEGIN { @EXPORT = qw( &GetShelves &GetShelfContents &AddToShelf - &ModShelf &ShelfPossibleAction &DelFromShelf &GetBibliosShelves @@ -307,61 +306,6 @@ sub AddToShelf { $sth->execute( $shelfnumber ); } -=head2 ModShelf - -my $result= ModShelf($shelfnumber, $hashref) - -Where $hashref->{column} = param - -Modify the value into virtualshelves table with values given -from hashref, which each key of the hashref should be -the name of a column of virtualshelves. -Fields like shelfnumber or owner cannot be changed. - -Returns 1 if the action seemed to be successful. - -=cut - -sub ModShelf { - my ($shelfnumber,$hashref) = @_; - my $dbh = C4::Context->dbh; - - my $query= "SELECT * FROM virtualshelves WHERE shelfnumber=?"; - my $sth = $dbh->prepare($query); - $sth->execute($shelfnumber); - my $oldrecord= $sth->fetchrow_hashref; - return 0 unless $oldrecord; #not found? - - #initialize missing hash values to silence warnings - foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) { - $hashref->{$_}= undef unless exists $hashref->{$_}; - } - - #if name or category changes, the name should be tested - if($hashref->{shelfname} || $hashref->{category}) { - unless(_CheckShelfName( - $hashref->{shelfname}//$oldrecord->{shelfname}, - $hashref->{category}//$oldrecord->{category}, - $oldrecord->{owner}, - $shelfnumber )) { - return 0; #name check failed - } - } - - #only the following fields from the hash may be changed - $query= "UPDATE virtualshelves SET shelfname=?, category=?, sortfield=?, allow_add=?, allow_delete_own=?, allow_delete_other=? WHERE shelfnumber=?"; - $sth = $dbh->prepare($query); - $sth->execute( - $hashref->{shelfname}//$oldrecord->{shelfname}, - $hashref->{category}//$oldrecord->{category}, - $hashref->{sortfield}//$oldrecord->{sortfield}, - $hashref->{allow_add}//$oldrecord->{allow_add}, - $hashref->{allow_delete_own}//$oldrecord->{allow_delete_own}, - $hashref->{allow_delete_other}//$oldrecord->{allow_delete_other}, - $shelfnumber ); - return $@? 0: 1; -} - =head2 ShelfPossibleAction ShelfPossibleAction($loggedinuser, $shelfnumber, $action); diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index 8d7bb5f94f..59d201cbb7 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -180,17 +180,17 @@ sub shelfpage { push @paramsloop, { nopermission => $shelfnumber }; last SWITCH; } - my $shelf = { - shelfname => $query->param('shelfname'), - sortfield => $query->param('sortfield'), - allow_add => $query->param('allow_add'), - allow_delete_own => $query->param('allow_delete_own'), - allow_delete_other => $query->param('allow_delete_other'), - }; - if($query->param('category')) { #optional - $shelf->{category}= $query->param('category'); + my $shelf = Koha::Virtualshelves->find( $shelfnumber ); + $shelf->shelfname($query->param('shelfname')); + $shelf->sortfield($query->param('sortfield')); + $shelf->allow_add($query->param('allow_add')); + $shelf->allow_delete_own($query->param('allow_delete_own')); + $shelf->allow_delete_other($query->param('allow_delete_other')); + if( my $category = $query->param('category')) { #optional + $shelf->category($category); } - unless(ModShelf($shelfnumber, $shelf )) { + eval { $shelf->store }; + if ( $@ ) { push @paramsloop, {modifyfailure => $shelf->{shelfname}}; last SWITCH; } -- 2.39.5