Bug 8836 [QA Followup] - Prevent multiple collections from having the same title

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

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 <katrin.fischer.83@web.de>
This commit is contained in:
Kyle M Hall 2014-10-31 06:46:53 -04:00 committed by Tomas Cohen Arazi
parent e26c8efbdb
commit a503474346
2 changed files with 16 additions and 0 deletions

View File

@ -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;

View File

@ -37,6 +37,8 @@
<p>
[% 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 @@
<p>
[% IF failureMessage == "NO_ID" %]
No collection id given.
[% ELSIF failureMessage == "DUPLICATE_TITLE" %]
Title already in use.
[% ELSE %]
[% failureMessage %]
[% END %]