From 78a9a236f7205f291d40b3336ce47184c3412421 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 31 Oct 2014 06:46:53 -0400 Subject: [PATCH] Bug 8836 [QA Followup] - Prevent multiple collections from having the same title --- C4/RotatingCollections.pm | 12 ++++++++++++ .../rotating_collections/editCollections.tt | 4 ++++ 2 files changed, 16 insertions(+), 0 deletions(-) diff --git a/C4/RotatingCollections.pm b/C4/RotatingCollections.pm index f287994..1299f2e 100644 --- a/C4/RotatingCollections.pm +++ b/C4/RotatingCollections.pm @@ -27,6 +27,7 @@ use Modern::Perl; use C4::Context; use C4::Circulation; use C4::Reserves qw(CheckReserves); +use Koha::Database; use DBI; @@ -84,9 +85,14 @@ BEGIN { sub CreateCollection { my ( $title, $description ) = @_; + my $schema = Koha::Database->new()->schema(); + my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title }); + ## Check for all neccessary parameters if ( !$title ) { return ( 0, 1, "NO_TITLE" ); + } elsif ( $duplicate_titles ) { + return ( 0, 2, "DUPLICATE_TITLE" ); } $description ||= q{}; @@ -127,6 +133,9 @@ Updates a collection sub UpdateCollection { my ( $colId, $title, $description ) = @_; + my $schema = Koha::Database->new()->schema(); + my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title, -not => { colId => $colId } }); + ## Check for all neccessary parameters if ( !$colId ) { return ( 0, 1, "NO_ID" ); @@ -134,6 +143,9 @@ sub UpdateCollection { if ( !$title ) { return ( 0, 2, "NO_TITLE" ); } + if ( $duplicate_titles ) { + return ( 0, 3, "DUPLICATE_TITLE" ); + } my $dbh = C4::Context->dbh; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt index 1247e5b..9504b61 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt @@ -37,6 +37,8 @@

[% IF failureMessage == "NO_TITLE" %] No title entered. + [% ELSIF failureMessage == "DUPLICATE_TITLE" %] + Title already in use. [% ELSIF failureMessage == "NO_DESCRIPTION" %] No description entered. [% ELSE %] @@ -70,6 +72,8 @@

[% IF failureMessage == "NO_ID" %] No collection id given. + [% ELSIF failureMessage == "DUPLICATE_TITLE" %] + Title already in use. [% ELSE %] [% failureMessage %] [% END %] -- 1.7.2.5