From a503474346182f0cfdd35557fabefddee5ec80bb 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 Signed-off-by: Owen Leonard This works, and so I'll sign off, but I'm not crazy about the workflow. Having the error message display on an otherwise empty page is not user friendly. The entry form should be redisplayed so that the user can modify the data they submitted. That really should be changed in a follow-up. Signed-off-by: Katrin Fischer --- C4/RotatingCollections.pm | 12 ++++++++++++ .../modules/rotating_collections/editCollections.tt | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/C4/RotatingCollections.pm b/C4/RotatingCollections.pm index 5126175583..ea75eaab3b 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 1247e5bb9d..9504b61e5e 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 %] -- 2.39.2