Bug 15783: AddAuthorisedValue - Replace existing calls
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 10 Feb 2016 10:20:01 +0000 (10:20 +0000)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Wed, 24 Feb 2016 03:34:14 +0000 (03:34 +0000)
The C4::Koha::AddAuthorisedValue is only called twice from
reports/guided_reports.pl and insert an authorised value.
This job can be achieve easily using the Koha::AuthorisedValue module.

Test plan:
1/ Create a new guided report
2/ Use an existing group and/or subgroup of reports
3/ Save
4/ Update an existing report
5/ Use an existing group and/or subgroup of reports
6/ Save
7/ Create or update an existing report
8/ Remove its assigned group and subgroup
9/ Save

Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
reports/guided_reports.pl

index ceba539..eed8ab9 100755 (executable)
@@ -33,6 +33,7 @@ use C4::Koha qw/IsAuthorisedValueCategory GetFrameworksLoop/;
 use C4::Context;
 use C4::Log;
 use Koha::DateUtils qw/dt_from_string output_pref/;
+use Koha::AuthorisedValue;
 
 =head1 NAME
 
@@ -998,12 +999,21 @@ sub create_non_existing_group_and_subgroup {
         my $report_groups = C4::Reports::Guided::get_report_groups;
         if (not exists $report_groups->{$group}) {
             my $groupdesc = $input->param('groupdesc') // $group;
-            C4::Koha::AddAuthorisedValue('REPORT_GROUP', $group, $groupdesc);
+            Koha::AuthorisedValue->new({
+                category => 'REPORT_GROUP',
+                authorised_value => $group,
+                lib => $groupdesc,
+            })->store;
         }
         if (defined $subgroup and $subgroup ne '') {
             if (not exists $report_groups->{$group}->{subgroups}->{$subgroup}) {
                 my $subgroupdesc = $input->param('subgroupdesc') // $subgroup;
-                C4::Koha::AddAuthorisedValue('REPORT_SUBGROUP', $subgroup, $subgroupdesc, $group);
+                Koha::AuthorisedValue->new({
+                    category => 'REPORT_SUBGROUP',
+                    authorised_value => $subgroup,
+                    lib => $subgroupdesc,
+                    lib_opac => $group,
+                })->store;
             }
         }
     }