From 7283069a9d3b2ffb2edc31022d96bb4aea107098 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 15 Dec 2015 13:19:53 +0000 Subject: [PATCH] Bug 15381: Remove getauthtypes and getauthtype MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit These 2 subroutines are now not necessary anymore, we can use Koha::Authority::Types to retrieve the authority types. This patch won't be easy to test. Indeed, a lot of file are updated. To test it I would suggest to focus on the merge authority You should also confirm that the authtypecode and the authtypetext values are correctly displayed when navigating in the authority module. Signed-off-by: Frédéric Demians Signed-off-by: Martin Renvoize Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- C4/AuthoritiesMarc.pm | 1 + C4/Koha.pm | 63 ------------------- admin/auth_tag_structure.pl | 15 +---- authorities/auth_finder.pl | 17 ++--- authorities/authorities-home.pl | 21 ++----- authorities/authorities.pl | 28 +++------ authorities/detail-biblio-search.pl | 21 +++---- authorities/detail.pl | 29 ++++----- authorities/merge.pl | 30 ++------- .../value_builder/unimarc_field_210c.pl | 16 ----- .../prog/en/includes/authorities-search.inc | 26 ++++---- .../prog/en/includes/authorities-toolbar.inc | 4 +- .../en/modules/admin/auth_tag_structure.tt | 9 ++- .../prog/en/modules/authorities/merge.tt | 2 +- .../prog/en/modules/tools/export.tt | 8 +-- opac/opac-authorities-home.pl | 25 +++----- opac/opac-authoritiesdetail.pl | 22 +++---- tools/export.pl | 14 +---- 18 files changed, 89 insertions(+), 262 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index c1e62aa244..d80937f61a 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -27,6 +27,7 @@ use C4::AuthoritiesMarc::UNIMARC; use C4::Charset; use C4::Log; use Koha::MetadataRecord::Authority; +use Koha::Authority::Types; use vars qw($VERSION @ISA @EXPORT); diff --git a/C4/Koha.pm b/C4/Koha.pm index 747610677f..12ac19c55c 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -47,7 +47,6 @@ BEGIN { &get_itemtypeinfos_of &getframeworks &getframeworkinfo &GetFrameworksLoop - &getauthtypes &getauthtype &getallthemes &getFacets &displayServers @@ -355,68 +354,6 @@ END_SQL return get_infos_of( $query, 'itemtype', undef, \@itemtypes ); } -=head2 getauthtypes - - $authtypes = &getauthtypes(); - -Returns information about existing authtypes. - -build a HTML select with the following code : - -=head3 in PERL SCRIPT - - my $authtypes = getauthtypes; - my @authtypesloop; - foreach my $thisauthtype (keys %$authtypes) { - my $selected = 1 if $thisauthtype eq $authtype; - my %row =(value => $thisauthtype, - selected => $selected, - authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'}, - ); - push @authtypesloop, \%row; - } - $template->param(itemtypeloop => \@itemtypesloop); - -=head3 in TEMPLATE - -
- - "> - -
- - -=cut - -sub getauthtypes { - - # returns a reference to a hash of references to authtypes... - my %authtypes; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("select * from auth_types order by authtypetext"); - $sth->execute; - while ( my $IT = $sth->fetchrow_hashref ) { - $authtypes{ $IT->{'authtypecode'} } = $IT; - } - return ( \%authtypes ); -} - -sub getauthtype { - my ($authtypecode) = @_; - - # returns a reference to a hash of references to authtypes... - my %authtypes; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("select * from auth_types where authtypecode=?"); - $sth->execute($authtypecode); - my $res = $sth->fetchrow_hashref; - return $res; -} - =head2 getframework $frameworks = &getframework(); diff --git a/admin/auth_tag_structure.pl b/admin/auth_tag_structure.pl index c2ff126ccd..710ff913ff 100755 --- a/admin/auth_tag_structure.pl +++ b/admin/auth_tag_structure.pl @@ -27,13 +27,13 @@ use C4::Context; use C4::Output; use C4::Context; +use Koha::Authority::Types; # retrieve parameters my $input = new CGI; my $authtypecode = $input->param('authtypecode') || ''; # set to select framework my $existingauthtypecode = $input->param('existingauthtypecode') || ''; # set when we have to create a new framework (in authtype) by copying an old one (in existingauthtype) -# my $authtypeinfo = getauthtypeinfo($authtype); my $searchfield = $input->param('searchfield') || 0; my $offset = $input->param('offset') || 0; my $op = $input->param('op') || ''; @@ -54,16 +54,7 @@ my ($template, $loggedinuser, $cookie) debug => 1, }); -# get authtype list -my $authtypes = getauthtypes; -my @authtypesloop = (); -foreach my $thisauthtype ( sort keys %{$authtypes} ) { - push @authtypesloop, - { value => $thisauthtype, - selected => $thisauthtype eq $authtypecode, - authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'}, - }; -} +my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } ); my $sth; # check that authtype framework is defined in auth_tag_structure if we are on a default action @@ -83,7 +74,7 @@ if (!$op or $op eq 'authtype_create_confirm') { } } $template->param(script_name => $script_name); -$template->param(authtypeloop => \@authtypesloop); +$template->param(authority_types => $authority_types ); if ($op && $op ne 'authtype_create_confirm') { $template->param($op => 1); } else { diff --git a/authorities/auth_finder.pl b/authorities/auth_finder.pl index ea33a0352a..7c155c0349 100755 --- a/authorities/auth_finder.pl +++ b/authorities/auth_finder.pl @@ -29,6 +29,8 @@ use C4::AuthoritiesMarc; use C4::Acquisition; use C4::Koha; +use Koha::Authority::Types; + my $query = new CGI; my $op = $query->param('op') || ''; my $authtypecode = $query->param('authtypecode') || ''; @@ -49,18 +51,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -# Authority types loop -my $authtypes = C4::Koha::getauthtypes(); -my @authtypesloop; -foreach my $thisauthtype ( keys %$authtypes ) { - my %row = ( - value => $thisauthtype, - selected => ( $thisauthtype eq $authtypecode ), - authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, - index => $index, - ); - push @authtypesloop, \%row; -} +my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypetext'] } ); # If search form posted if ( $op eq "do_search" ) { @@ -173,7 +164,7 @@ $template->param( value_match => $query->param('value_match') || '', tagid => $tagid, index => $index, - authtypesloop => \@authtypesloop, + authority_types => $authority_types, authtypecode => $authtypecode, source => $source, relationship => $relationship, diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl index 6e13db6229..9e80489903 100755 --- a/authorities/authorities-home.pl +++ b/authorities/authorities-home.pl @@ -33,6 +33,8 @@ use C4::Koha; # XXX subfield_is_koha_internal_p use C4::Biblio; use C4::Search::History; +use Koha::Authority::Types; + my $query = new CGI; my $dbh = C4::Context->dbh; my $op = $query->param('op') || ''; @@ -41,22 +43,7 @@ my $authid = $query->param('authid') || ''; my ( $template, $loggedinuser, $cookie ); -my $authtypes = getauthtypes; -my @authtypesloop; -foreach my $thisauthtype ( - sort { - $authtypes->{$a}{'authtypetext'} cmp $authtypes->{$b}{'authtypetext'} - } - keys %$authtypes - ) -{ - my %row = ( - value => $thisauthtype, - selected => $thisauthtype eq $authtypecode, - authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, - ); - push @authtypesloop, \%row; -} +my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypetext'] } ); if ( $op eq "delete" ) { ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -201,7 +188,7 @@ if ( $op eq '' ) { } $template->param( - authtypesloop => \@authtypesloop, + authority_types => $authority_types, op => $op, ); diff --git a/authorities/authorities.pl b/authorities/authorities.pl index 1753de6dc4..eedaf66b96 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -31,6 +31,7 @@ use Date::Calc qw(Today); use MARC::File::USMARC; use MARC::File::XML; use C4::Biblio; +use Koha::Authority::Types; use vars qw( $tagslib); use vars qw( $authorised_values_sth); use vars qw( $is_a_modif ); @@ -659,23 +660,14 @@ if ($op eq "duplicate") authid => $authid , authtypecode=>$authtypecode, ); } -$template->param(authid => $authid, - authtypecode => $authtypecode, - linkid=>$linkid, -); - -my $authtypes = getauthtypes; -my @authtypesloop; -foreach my $thisauthtype (keys %$authtypes) { - my %row =(value => $thisauthtype, - selected => $thisauthtype eq $authtypecode, - authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, - ); - push @authtypesloop, \%row; -} +my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypetext'] } ); -$template->param(authtypesloop => \@authtypesloop, - authtypetext => $authtypes->{$authtypecode}{'authtypetext'}, - hide_marc => C4::Context->preference('hide_marc'), - ); +$template->param( + authority_types => $authority_types, + authtypecode => $authtypecode, + authid => $authid, + linkid => $linkid, + authtypetext => $authority_types->find($authtypecode)->authtypetext, + hide_marc => C4::Context->preference('hide_marc'), +); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/authorities/detail-biblio-search.pl b/authorities/detail-biblio-search.pl index c6af075d91..c001081fa4 100755 --- a/authorities/detail-biblio-search.pl +++ b/authorities/detail-biblio-search.pl @@ -50,6 +50,7 @@ use C4::Koha; # use C4::Biblio; # use C4::Catalogue; +use Koha::Authority::Types; my $query=new CGI; @@ -119,18 +120,12 @@ my @fields = $record->fields(); } $template->param("0XX" =>\@loop_data); -my $authtypes = getauthtypes; -my @authtypesloop; -foreach my $thisauthtype (keys %$authtypes) { - my %row =(value => $thisauthtype, - selected => $thisauthtype eq $authtypecode, - authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, - ); - push @authtypesloop, \%row; -} - -$template->param(authid => $authid, - authtypesloop => \@authtypesloop, index => $index, - ); +my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypetext'] } ); + +$template->param( + authid => $authid, + authority_types => $authority_types, + index => $index, +); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/authorities/detail.pl b/authorities/detail.pl index 49c575d069..f4c764d98c 100755 --- a/authorities/detail.pl +++ b/authorities/detail.pl @@ -48,6 +48,8 @@ use CGI qw ( -utf8 ); use MARC::Record; use C4::Koha; +use Koha::Authority::Types; + our ($tagslib); sub build_tabs { @@ -178,16 +180,7 @@ my $authtypecode = GetAuthTypeCode($authid); $tagslib = &GetTagsLabels(1,$authtypecode); # Build list of authtypes for showing them -my $authtypes = getauthtypes; -my @authtypesloop; - -foreach my $thisauthtype (sort { $authtypes->{$b} cmp $authtypes->{$a} } keys %$authtypes) { - my %row =(value => $thisauthtype, - selected => $thisauthtype eq $authtypecode, - authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, - ); - push @authtypesloop, \%row; -} +my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypecode']}); my $record=GetAuthority($authid); @@ -195,7 +188,7 @@ if (not defined $record) { # authid invalid $template->param ( errauthid => $authid, unknownauthid => 1, - authtypesloop => \@authtypesloop ); + authority_types => $authority_types, ); output_html_with_http_headers $query, $cookie, $template->output; exit; } @@ -218,12 +211,14 @@ chop $biblio_fields; build_tabs ($template, $record, $dbh,"",$query); -$template->param(authid => $authid, - count => $count, - biblio_fields => $biblio_fields, - authtypetext => $authtypes->{$authtypecode}{'authtypetext'}, - authtypesloop => \@authtypesloop, - ); +$template->param( + authid => $authid, + count => $count, + biblio_fields => $biblio_fields, + authtypetext => $authority_types->find($authtypecode)->authtypetext, + authtypecode => $authtypecode, + authority_types => $authority_types, +); $template->{VARS}->{marcflavour} = C4::Context->preference("marcflavour"); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/authorities/merge.pl b/authorities/merge.pl index d74abc5268..c9da83acf8 100755 --- a/authorities/merge.pl +++ b/authorities/merge.pl @@ -156,17 +156,13 @@ else { title2 => $recordObj2->authorized_heading, ); if ( $recordObj1->authtype ne $recordObj2->authtype ) { - my $frameworks = getauthtypes; + my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } ); my @frameworkselect; - foreach my $thisframeworkcode ( keys %$frameworks ) { + while ( my $authority_type = $authority_types->next ) { my %row = ( - value => $thisframeworkcode, - frameworktext => - $frameworks->{$thisframeworkcode}->{'authtypetext'}, + value => $authority_type->authtypecode, + frameworktext => $authority_type->authtypetext, ); - if ( $recordObj1->authtype eq $thisframeworkcode ) { - $row{'selected'} = 1; - } push @frameworkselect, \%row; } $template->param( @@ -181,22 +177,8 @@ else { } } -my $authtypes = getauthtypes; -my @authtypesloop; -foreach my $thisauthtype ( - sort { - $authtypes->{$a}{'authtypetext'} cmp $authtypes->{$b}{'authtypetext'} - } - keys %$authtypes - ) -{ - my %row = ( - value => $thisauthtype, - authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, - ); - push @authtypesloop, \%row; -} -$template->{VARS}->{authtypesloop} = \@authtypesloop; +my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']}); +$template->param( authority_types => $authority_types ); if (@errors) { diff --git a/cataloguing/value_builder/unimarc_field_210c.pl b/cataloguing/value_builder/unimarc_field_210c.pl index d775add86e..0d0a07016e 100755 --- a/cataloguing/value_builder/unimarc_field_210c.pl +++ b/cataloguing/value_builder/unimarc_field_210c.pl @@ -69,21 +69,6 @@ my ($input) = @_; my ($template, $loggedinuser, $cookie); my $resultsperpage; - my $authtypes = getauthtypes; - my @authtypesloop; - foreach my $thisauthtype (keys %$authtypes) { - my $selected; - if ($thisauthtype eq $authtypecode) { - $selected=1; - } - my %row =(value => $thisauthtype, - selected => $selected, - authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, - index => $index, - ); - push @authtypesloop, \%row; - } - if ($op eq "do_search") { my @marclist = $query->param('marclist'); my @and_or = $query->param('and_or'); @@ -186,7 +171,6 @@ my ($input) = @_; ); } - $template->param(authtypesloop => \@authtypesloop); $template->param(category => $category); # Print the page diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search.inc index 571e6b0c08..9be4ee0f55 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search.inc @@ -25,11 +25,11 @@ @@ -81,11 +81,11 @@ @@ -135,13 +135,13 @@
- [% IF (marcflavour == 'UNIMARC' ) %][% END %] - [% FOREACH authtypesloo IN authtypesloop %] - [% IF ( authtypesloo.selected ) %] - + [% FOREACH authority_type IN authority_types %] + [% IF authority_type.authtypecode == authtypecode %] + [% ELSE %] - + [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-toolbar.inc index be37e50402..82703272fa 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-toolbar.inc @@ -54,8 +54,8 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_tag_structure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_tag_structure.tt index 1d3f339bb1..2d9da9af55 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_tag_structure.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_tag_structure.tt @@ -187,13 +187,12 @@

Select an authority framework

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/merge.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/merge.tt index 520b9cd508..78ad394511 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/merge.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/merge.tt @@ -93,7 +93,7 @@ function changeFramework(fw) { - [% FOREACH authtypeloo IN authtypeloop %] - [% IF ( authtypeloo.selected ) %] - -[% ELSE %] - -[% END %] + [% FOREACH authority_type IN authority_types %] + [% END %] diff --git a/opac/opac-authorities-home.pl b/opac/opac-authorities-home.pl index 54c144411f..336a5fa136 100755 --- a/opac/opac-authorities-home.pl +++ b/opac/opac-authorities-home.pl @@ -31,6 +31,8 @@ use C4::AuthoritiesMarc; use C4::Koha; # XXX subfield_is_koha_internal_p use C4::Search::History; +use Koha::Authority::Types; + my $query = new CGI; my $op = $query->param('op') || ''; my $authtypecode = $query->param('authtypecode') || ''; @@ -42,21 +44,7 @@ $startfrom = 0 if ( !defined $startfrom ); my ( $template, $loggedinuser, $cookie ); my $resultsperpage; -my $authtypes = getauthtypes(); -my @authtypesloop = (); -foreach my $thisauthtype ( - sort { - $authtypes->{$a}->{'authtypetext'} - cmp $authtypes->{$b}->{'authtypetext'} - } - keys %{$authtypes} - ) { - push @authtypesloop, - { value => $thisauthtype, - selected => $thisauthtype eq $authtypecode, - authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'}, - }; -} +my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']}); if ( $op eq "do_search" ) { my @marclist = ($query->param('marclist')); @@ -179,7 +167,7 @@ if ( $op eq "do_search" ) { resultcount => scalar @$results, numbers => \@numbers, authtypecode => $authtypecode, - authtypetext => $authtypes->{$authtypecode}{'authtypetext'}, + authtypetext => $authority_types->find($authtypecode)->authtypetext, isEDITORS => $authtypecode eq 'EDITORS', ); @@ -197,7 +185,10 @@ else { } -$template->param( authtypesloop => \@authtypesloop ); +$template->param( + authority_types => $authority_types, + authtypecode => $authtypecode, +); # Print the page output_html_with_http_headers $query, $cookie, $template->output; diff --git a/opac/opac-authoritiesdetail.pl b/opac/opac-authoritiesdetail.pl index 79c70db889..048787298e 100755 --- a/opac/opac-authoritiesdetail.pl +++ b/opac/opac-authoritiesdetail.pl @@ -47,6 +47,7 @@ use CGI qw ( -utf8 ); use MARC::Record; use C4::Koha; +use Koha::Authority::Types; my $query = new CGI; @@ -83,20 +84,13 @@ if ($display_hierarchy){ my $count = CountUsage($authid); - -my $authtypes = getauthtypes(); -my @authtypesloop = (); -foreach my $thisauthtype ( keys %{$authtypes} ) { - push @authtypesloop, - { value => $thisauthtype, - selected => $thisauthtype eq $authtypecode, - authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, - }; -} -$template->{VARS}->{'authtypesloop'} = \@authtypesloop; -$template->{VARS}->{'authtypetext'} = $authtypes->{$authtypecode}{'authtypetext'}; -$template->{VARS}->{'authid'} = $authid; -$template->{VARS}->{'count'} = $count; +my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } ); +$template->param( + authority_types => $authority_types, + authtypetext => $authority_types->find($authtypecode)->authtypetext, + authid => $authid, + count => $count, +); # find the marc field/subfield used in biblio by this authority if ($show_marc) { diff --git a/tools/export.pl b/tools/export.pl index 7d96834bca..2e8b044e99 100755 --- a/tools/export.pl +++ b/tools/export.pl @@ -26,6 +26,7 @@ use C4::Csv; use C4::Koha; # GetItemTypes use C4::Output; +use Koha::Authority::Types; use Koha::Biblioitems; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); @@ -279,16 +280,7 @@ else { }; } - my $authtypes = getauthtypes; - my @authtypesloop; - foreach my $thisauthtype ( sort keys %$authtypes ) { - next unless $thisauthtype; - my %row = ( - value => $thisauthtype, - description => $authtypes->{$thisauthtype}->{'authtypetext'}, - ); - push @authtypesloop, \%row; - } + my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } ); if ( $flags->{superlibrarian} && C4::Context->config('backup_db_via_tools') @@ -313,7 +305,7 @@ else { $template->param( branchloop => \@branchloop, itemtypeloop => \@itemtypesloop, - authtypeloop => \@authtypesloop, + authority_types => $authority_types, export_remove_fields => C4::Context->preference("ExportRemoveFields"), csv_profiles => C4::Csv::GetCsvProfiles('marc'), ); -- 2.39.5