From e9913fb0d3a034aa064955b20e49da306724f648 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Fri, 14 Oct 2016 18:00:19 +0200 Subject: [PATCH] Bug 18606: Get rid of CreateCollection --- C4/RotatingCollections.pm | 46 --------------------------------- rotating_collections/editCollections.pl | 30 ++++++++++----------- 2 files changed, 15 insertions(+), 61 deletions(-) diff --git a/C4/RotatingCollections.pm b/C4/RotatingCollections.pm index c1bd2e9..0f1ef69 100644 --- a/C4/RotatingCollections.pm +++ b/C4/RotatingCollections.pm @@ -48,7 +48,6 @@ BEGIN { require Exporter; @ISA = qw( Exporter ); @EXPORT = qw( - CreateCollection UpdateCollection GetItemsInCollection @@ -61,51 +60,6 @@ BEGIN { ); } -=head2 CreateCollection - ( $success, $errorcode, $errormessage ) = CreateCollection( $title, $description ); - Creates a new collection - - Input: - $title: short description of the club or service - $description: long description of the club or service - - 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 CreateCollection { - my ( $title, $description ) = @_; - - my $schema = Koha::Database->new()->schema(); - my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title }); - - ## Check for all necessary parameters - if ( !$title ) { - return ( 0, 1, "NO_TITLE" ); - } elsif ( $duplicate_titles ) { - return ( 0, 2, "DUPLICATE_TITLE" ); - } - - $description ||= q{}; - - my $success = 1; - - my $dbh = C4::Context->dbh; - - my $sth; - $sth = $dbh->prepare( - "INSERT INTO collections ( colId, colTitle, colDesc ) - VALUES ( NULL, ?, ? )" - ); - $sth->execute( $title, $description ) or return ( 0, 3, $sth->errstr() ); - - return 1; - -} - =head2 UpdateCollection ( $success, $errorcode, $errormessage ) = UpdateCollection( $colId, $title, $description ); diff --git a/rotating_collections/editCollections.pl b/rotating_collections/editCollections.pl index bd4b917..b4dcba6 100755 --- a/rotating_collections/editCollections.pl +++ b/rotating_collections/editCollections.pl @@ -47,21 +47,22 @@ if ( $action eq 'create' ) { my $title = $query->param('title'); my $description = $query->param('description'); - my ( $createdSuccessfully, $errorCode, $errorMessage ) = - CreateCollection( $title, $description ); - - $template->param( - previousActionCreate => 1, - createdTitle => $title, + my $collection = Koha::RotatingCollection->new( + { colTitle => $title, + colDesc => $description, + } ); - if ($createdSuccessfully) { - $template->param( createSuccess => 1 ); - } - else { - $template->param( createFailure => 1 ); - $template->param( failureMessage => $errorMessage ); + eval { $collection->store; }; + + if ($@) { + push @messages, { type => 'error', code => 'error_on_insert' }; + } else { + push @messages, { type => 'message', code => 'success_on_insert' }; } + + $action = "list"; + } elsif ( $action eq 'delete' ) { # Delete collection my $colId = $query->param('colId'); my $collection = Koha::RotatingCollections->find($colId); @@ -72,11 +73,10 @@ if ( $action eq 'create' ) { } else { push @messages, { type => 'message', code => 'success_on_delete' }; } + $action = "list"; -} -## Edit a club or service: grab data, put in form. -elsif ( $action eq 'edit' ) { +} elsif ( $action eq 'edit' ) { # Edit page of collection my $collection = Koha::RotatingCollections->find($query->param('colId')); $template->param( -- 2.1.4