From 49b807bde0616372bb9a8e911957a0c93c95249b Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Fri, 14 Oct 2016 16:38:25 +0200 Subject: [PATCH] Bug 18606: Get rid of DeleteCollection --- C4/RotatingCollections.pm | 34 --------------------------------- rotating_collections/editCollections.pl | 33 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 50 deletions(-) diff --git a/C4/RotatingCollections.pm b/C4/RotatingCollections.pm index 709eaf2..c142d34 100644 --- a/C4/RotatingCollections.pm +++ b/C4/RotatingCollections.pm @@ -50,7 +50,6 @@ BEGIN { @EXPORT = qw( CreateCollection UpdateCollection - DeleteCollection GetItemsInCollection @@ -163,39 +162,6 @@ sub UpdateCollection { } -=head2 DeleteCollection - - ( $success, $errorcode, $errormessage ) = DeleteCollection( $colId ); - Deletes a collection of the given id - - Input: - $colId : id of the Archetype to be deleted - - Output: - $success: 1 if all database operations were successful, 0 otherwise - $errorCode: Code for reason of failure, good for translating errors in templates - $errorMessage: English description of error - -=cut - -sub DeleteCollection { - my ($colId) = @_; - - ## Parameter check - if ( !$colId ) { - return ( 0, 1, "NO_ID" ); - } - - my $dbh = C4::Context->dbh; - - my $sth; - - $sth = $dbh->prepare("DELETE FROM collections WHERE colId = ?"); - $sth->execute($colId) or return ( 0, 4, $sth->errstr() ); - - return 1; -} - =head2 GetCollections $collections = GetCollections(); diff --git a/rotating_collections/editCollections.pl b/rotating_collections/editCollections.pl index c8ed8ed..3b0e854 100755 --- a/rotating_collections/editCollections.pl +++ b/rotating_collections/editCollections.pl @@ -23,10 +23,13 @@ use CGI qw ( -utf8 ); use C4::Output; use C4::Auth; use C4::Context; - use C4::RotatingCollections; +use Koha::RotatingCollections; + my $query = new CGI; +my $action = $query->param('action'); +my @messages; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -39,9 +42,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -my $action = $query->param('action'); -$template->param( action => $action ); - # Create new Collection if ( $action eq 'create' ) { my $title = $query->param('title'); @@ -62,21 +62,17 @@ if ( $action eq 'create' ) { $template->param( createFailure => 1 ); $template->param( failureMessage => $errorMessage ); } -} - -## Delete a club or service -elsif ( $action eq 'delete' ) { +} elsif ( $action eq 'delete' ) { # Delete collection my $colId = $query->param('colId'); - my ( $success, $errorCode, $errorMessage ) = DeleteCollection($colId); + my $collection = Koha::RotatingCollections->find($colId); + my $deleted = eval { $collection->delete; }; - $template->param( previousActionDelete => 1 ); - if ($success) { - $template->param( deleteSuccess => 1 ); - } - else { - $template->param( deleteFailure => 1 ); - $template->param( failureMessage => $errorMessage ); + if ( $@ or not $deleted ) { + push @messages, { type => 'error', code => 'error_on_delete' }; + } else { + push @messages, { type => 'message', code => 'success_on_delete' }; } + $action = "list"; } ## Edit a club or service: grab data, put in form. @@ -114,4 +110,9 @@ elsif ( $action eq 'update' ) { } } +$template->param( + action => $action, + messages => \@messages, +); + output_html_with_http_headers $query, $cookie, $template->output; -- 2.1.4