From 7da1745132fb09e7a1c9b5091a0e59a68c5ef0bd Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 15 Dec 2015 11:59:02 +0000 Subject: [PATCH] Bug 15381: Use Koha::Authority::Types in some other places MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are 3 place where the auth_types table were requested directly from the script or a subroutine. These 3 occurrences are easy to replace with the new module. Test plan: 1/ Search for authorities and use the "did you mean" feature for authorities. Focus on the authtypecode 2/ Edit authority and biblio frameworks. The "Thesaurus" dropdown list should be correctly populated (UNIMARC only). Signed-off-by: Frédéric Demians Signed-off-by: Martin Renvoize --- C4/AuthoritiesMarc.pm | 22 ++++++---------------- admin/auth_subfields_structure.pl | 5 ++++- admin/marc_subfields_structure.pl | 12 ++++-------- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index b1a7196..c1e62aa 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -291,11 +291,7 @@ sub SearchAuthorities { my %newline; $newline{authid} = $authid; if ( !$skipmetadata ) { - my $query_auth_tag = -"SELECT auth_tag_to_report FROM auth_types WHERE authtypecode=?"; - my $sth = $dbh->prepare($query_auth_tag); - $sth->execute($authtypecode); - my $auth_tag_to_report = $sth->fetchrow; + my $auth_tag_to_report = Koha::Authority::Types->find($authtypecode)->auth_tag_to_report; my $reported_tag; my $mainentry = $authrecord->field($auth_tag_to_report); if ($mainentry) { @@ -848,10 +844,7 @@ sub FindDuplicateAuthority { # warn "IN for ".$record->as_formatted; my $dbh = C4::Context->dbh; # warn "".$record->as_formatted; - my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?"); - $sth->execute($authtypecode); - my ($auth_tag_to_report) = $sth->fetchrow; - $sth->finish; + my $auth_tag_to_report = Koha::Authority::Types->find($authtypecode)->auth_tag_to_report; # warn "record :".$record->as_formatted." auth_tag_to_report :$auth_tag_to_report"; # build a request for SearchAuthorities my $QParser; @@ -1456,12 +1449,9 @@ sub merge { return "error MARCFROM not a marcrecord ".Data::Dumper::Dumper($MARCfrom) if scalar($MARCfrom->fields()) == 0; return "error MARCTO not a marcrecord".Data::Dumper::Dumper($MARCto) if scalar($MARCto->fields()) == 0; # search the tag to report - my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?"); - $sth->execute($authtypecodefrom); - my ($auth_tag_to_report_from) = $sth->fetchrow; - $sth->execute($authtypecodeto); - my ($auth_tag_to_report_to) = $sth->fetchrow; - + my $auth_tag_to_report_from = Koha::Authority::Types->find($authtypecodefrom)->auth_tag_to_report; + my $auth_tag_to_report_to = Koha::Authority::Types->find($authtypecodeto)->auth_tag_to_report; + my @record_to; @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to); my @record_from; @@ -1499,7 +1489,7 @@ sub merge { #warn scalar(@reccache)." biblios to update"; # Get All candidate Tags for the change # (This will reduce the search scope in marc records). - $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?"); + my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?"); $sth->execute($authtypecodefrom); my @tags_using_authtype; while (my ($tagfield) = $sth->fetchrow) { diff --git a/admin/auth_subfields_structure.pl b/admin/auth_subfields_structure.pl index 6a960f2..584685b 100755 --- a/admin/auth_subfields_structure.pl +++ b/admin/auth_subfields_structure.pl @@ -25,6 +25,9 @@ use CGI qw ( -utf8 ); use C4::Context; use C4::Koha; +use Koha::Authority::Types; + +use List::MoreUtils qw( uniq ); sub string_search { my ($searchstring,$authtypecode)=@_; @@ -99,7 +102,7 @@ if ($op eq 'add_form') { push @$authorised_values, 'itemtypes'; # build thesaurus categories list - my @authtypes = (sort keys %{C4::Koha::getauthtypes()}); + my @authtypes = uniq( "", map { $_->authtypecode } Koha::Authority::Types->search ); # build value_builder list my @value_builder=(''); diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl index 5a7d356..e6d2231 100755 --- a/admin/marc_subfields_structure.pl +++ b/admin/marc_subfields_structure.pl @@ -24,6 +24,9 @@ use C4::Auth; use CGI qw ( -utf8 ); use C4::Context; +use Koha::Authority::Types; + +use List::MoreUtils qw( uniq ); sub string_search { my ( $searchstring, $frameworkcode ) = @_; @@ -138,14 +141,7 @@ if ( $op eq 'add_form' ) { push( @authorised_values, "cn_source" ); # build thesaurus categories list - $sth2->finish; - $sth2 = $dbh->prepare("select authtypecode from auth_types"); - $sth2->execute; - my @authtypes; - push @authtypes, ""; - while ( ( my $authtypecode ) = $sth2->fetchrow_array ) { - push @authtypes, $authtypecode; - } + my @authtypes = uniq( "", map { $_->authtypecode } Koha::Authority::Types->search ); # build value_builder list my @value_builder = (''); -- 2.1.4