From c329ecbd431fb3dd3ca0581e224d7eb6f7c4e741 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 2 Dec 2016 04:08:45 +0000 Subject: [PATCH] Bug 17208: Checking if classification source or filing rule already exists before adding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To test: 1) Go to Admin -> Classification sources 2) Attempt to reproduce bug before applying patch. Notice the message saying the add was successful, but was not added to the table 3) Apply patch and refresh page (restart plack if necessary) 4) Add new classification source with same code as existing one. Notice you are now told that the add failed. 5) Confirm adding new classification source with unique code works 6) Add new classification filing rule with same code as existing one. Notice you are told that add failed. 7) Confirm adding new classification filing rule with unique code works Sponsored-by: Catalyst IT Followed test plan, works as expected. Signed-off-by: Marc VĂ©ron --- C4/ClassSource.pm | 12 ++++++++++-- admin/classsources.pl | 16 ++++++++++++---- .../intranet-tmpl/prog/en/modules/admin/classsources.tt | 6 ++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/C4/ClassSource.pm b/C4/ClassSource.pm index bb78074..245f958 100644 --- a/C4/ClassSource.pm +++ b/C4/ClassSource.pm @@ -112,12 +112,16 @@ sub GetClassSources { sub AddClassSource { my ($cn_source, $description, $used, $class_sort_rule) = @_; + my $exists = GetClassSource($cn_source); + if ($exists) { + return 0; + } my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("INSERT INTO `class_sources` (`cn_source`, `description`, `used`, `class_sort_rule`) VALUES (?, ?, ?, ?)"); $sth->execute($cn_source, $description, $used, $class_sort_rule); - + return 1; } =head2 GetClassSource @@ -224,12 +228,16 @@ sub GetClassSortRules { sub AddClassSortRule { my ($class_sort_rule, $description, $sort_routine) = @_; + my $exists = GetClassSortRule($class_sort_rule); + if ($exists) { + return 0; + } my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("INSERT INTO `class_sort_rules` (`class_sort_rule`, `description`, `sort_routine`) VALUES (?, ?, ?)"); $sth->execute($class_sort_rule, $description, $sort_routine); - + return 1; } =head2 GetClassSortRule diff --git a/admin/classsources.pl b/admin/classsources.pl index cc2fe87..74e682a 100755 --- a/admin/classsources.pl +++ b/admin/classsources.pl @@ -118,8 +118,12 @@ sub add_class_source_form { sub add_class_source { my ($template, $source_code, $description, $used, $sort_rule) = @_; - AddClassSource($source_code, $description, $used, $sort_rule); - $template->param(added_source => $source_code); + my $success = AddClassSource($source_code, $description, $used, $sort_rule); + if ($success > 0) { + $template->param(added_source => $source_code); + } else { + $template->param(failed_add_source => $source_code); + } } sub edit_class_source_form { @@ -189,8 +193,12 @@ sub add_class_sort_rule_form { sub add_class_sort_rule { my ($template, $rule_code, $description, $sort_routine) = @_; - AddClassSortRule($rule_code, $description, $sort_routine); - $template->param(added_rule => $rule_code); + my $success = AddClassSortRule($rule_code, $description, $sort_routine); + if ($success > 0) { + $template->param(added_rule => $rule_code); + } else { + $template->param(failed_add_rule => $rule_code); + } } sub delete_sort_rule_form { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/classsources.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/classsources.tt index 2785ebb..b44cd4b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/classsources.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/classsources.tt @@ -199,6 +199,9 @@ [% IF ( deleted_source ) %]
Deleted classification source [% deleted_source %]
[% END %] +[% IF ( failed_add_source ) %] +
Failed to add classification source [% failed_add_source %]. Perhaps the code already exists?
+[% END %] @@ -231,6 +234,9 @@ [% IF ( deleted_rule ) %]
Deleted filing rule [% deleted_rule %]
[% END %] +[% IF ( failed_add_rule ) %] +
Failed to add filing rule [% failed_add_rule %]. Perhaps the code already exists?
+[% END %]
Code
-- 2.1.4
Code