From 7e70202d34d75f988fbaea9b911347417c203aac Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 15 Dec 2015 13:43:47 +0000 Subject: [PATCH] Bug 15381: Remove GetAuthType and GetAuthTypeCode MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Test this patch with the previous one. Signed-off-by: Frédéric Demians Signed-off-by: Martin Renvoize Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- C4/AuthoritiesMarc.pm | 85 ++++++------------------ C4/Biblio.pm | 6 +- Koha/MetadataRecord/Authority.pm | 6 +- authorities/authorities.pl | 2 +- authorities/blinddetail-biblio-search.pl | 11 +-- authorities/detail-biblio-search.pl | 3 +- authorities/detail.pl | 3 +- authorities/merge.pl | 14 ++-- misc/migration_tools/merge_authority.pl | 4 +- opac/opac-authoritiesdetail.pl | 2 +- tools/batch_record_modification.pl | 4 +- 11 files changed, 50 insertions(+), 90 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index d80937f61a..a2e01e596c 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::Authorities; use Koha::Authority::Types; use vars qw($VERSION @ISA @EXPORT); @@ -39,8 +40,6 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( &GetTagsLabels - &GetAuthType - &GetAuthTypeCode &GetAuthMARCFromKohaField &AddAuthority @@ -300,16 +299,17 @@ sub SearchAuthorities { $reported_tag .= '$' . $_->[0] . $_->[1]; } } - my $thisauthtypecode = GetAuthTypeCode($authid); - my $thisauthtype = GetAuthType($thisauthtypecode); + + my $thisauthtypecode = Koha::Authorities->find($authid)->authtypecode; + my $thisauthtype = Koha::Authority::Types->find($thisauthtypecode); unless (defined $thisauthtype) { $thisauthtypecode = $authtypecode; - $thisauthtype = GetAuthType($authtypecode); + $thisauthtype = Koha::Authority::Types->find($thisauthtypecode); } my $summary = BuildSummary( $authrecord, $authid, $thisauthtypecode ); $newline{authtype} = defined($thisauthtype) ? - $thisauthtype->{'authtypetext'} : ''; + $thisauthtype->authtypetext : ''; $newline{summary} = $summary; $newline{even} = $counter % 2; $newline{reported_tag} = $reported_tag; @@ -367,24 +367,6 @@ sub CountUsageChildren { my ($authid) = @_; } -=head2 GetAuthTypeCode - - $authtypecode= &GetAuthTypeCode($authid) - -returns authtypecode of an authid - -=cut - -sub GetAuthTypeCode { -#AUTHfind_authtypecode - my ($authid) = @_; - my $dbh=C4::Context->dbh; - my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?"); - $sth->execute($authid); - my $authtypecode = $sth->fetchrow; - return $authtypecode; -} - =head2 GuessAuthTypeCode my $authtypecode = GuessAuthTypeCode($record); @@ -803,32 +785,6 @@ sub GetAuthority { return ($authority->record); } -=head2 GetAuthType - - $result = &GetAuthType($authtypecode) - -If the authority type specified by C<$authtypecode> exists, -returns a hashref of the type's fields. If the type -does not exist, returns undef. - -=cut - -sub GetAuthType { - my ($authtypecode) = @_; - my $dbh=C4::Context->dbh; - my $sth; - if (defined $authtypecode){ # NOTE - in MARC21 framework, '' is a valid authority - # type (FIXME but why?) - $sth=$dbh->prepare("select * from auth_types where authtypecode=?"); - $sth->execute($authtypecode); - if (my $res = $sth->fetchrow_hashref) { - return $res; - } - } - return; -} - - =head2 FindDuplicateAuthority $record= &FindDuplicateAuthority( $record, $authtypecode) @@ -896,16 +852,16 @@ sub BuildSummary { my $summary_template; # handle $authtypecode is NULL or eq "" if ($authtypecode) { - my $authref = GetAuthType($authtypecode); - $summary{authtypecode} = $authref->{authtypecode}; - $summary{type} = $authref->{authtypetext}; - $summary_template = $authref->{summary}; + my $authref = Koha::Authority::Types->find($authtypecode); + $summary{authtypecode} = $authref->authtypecode; + $summary{type} = $authref->authtypetext; + $summary_template = $authref->summary; # for MARC21, the authority type summary displays a label meant for # display if (C4::Context->preference('marcflavour') ne 'UNIMARC') { - $summary{label} = $authref->{summary}; + $summary{label} = $authref->summary; } else { - $summary{summary} = $authref->{summary}; + $summary{summary} = $authref->summary; } } my $marc21subfields = 'abcdfghjklmnopqrstuvxyz68'; @@ -1443,15 +1399,14 @@ sub merge { my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_; my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0); my $dbh=C4::Context->dbh; - my $authtypecodefrom = GetAuthTypeCode($mergefrom); - my $authtypecodeto = GetAuthTypeCode($mergeto); -# warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto "; - # return if authority does not exist + my $authtypefrom = Koha::Authority::Types->find($mergefrom); + my $authtypeto = Koha::Authority::Types->find($mergeto); + 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 $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 $auth_tag_to_report_from = $authtypefrom->auth_tag_to_report; + my $auth_tag_to_report_to = $authtypeto->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); @@ -1491,15 +1446,15 @@ sub merge { # Get All candidate Tags for the change # (This will reduce the search scope in marc records). my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?"); - $sth->execute($authtypecodefrom); + $sth->execute($authtypefrom->authtypecode); my @tags_using_authtype; while (my ($tagfield) = $sth->fetchrow) { push @tags_using_authtype,$tagfield ; } my $tag_to=0; - if ($authtypecodeto ne $authtypecodefrom){ + if ($authtypeto->authtypecode ne $authtypefrom->authtypecode){ # If many tags, take the first - $sth->execute($authtypecodeto); + $sth->execute($authtypeto->authtypecode); $tag_to=$sth->fetchrow; #warn $tag_to; } diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 919051ac6d..03ccec9890 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -39,6 +39,7 @@ use C4::Linker; use C4::OAI::Sets; use Koha::Cache; +use Koha::Authority::Types; use vars qw($VERSION @ISA @EXPORT); @@ -572,8 +573,7 @@ sub LinkBibHeadingsToAuthorities { $results{'linked'}->{ $heading->display_form() }++; } else { - my $authtypedata = - C4::AuthoritiesMarc::GetAuthType( $heading->auth_type() ); + my $authority_type = Koha::Authority::Types->find( $heading->auth_type() ); my $marcrecordauth = MARC::Record->new(); if ( C4::Context->preference('marcflavour') eq 'MARC21' ) { $marcrecordauth->leader(' nz a22 o 4500'); @@ -582,7 +582,7 @@ sub LinkBibHeadingsToAuthorities { $field->delete_subfield( code => '9' ) if defined $current_link; my $authfield = - MARC::Field->new( $authtypedata->{auth_tag_to_report}, + MARC::Field->new( $authority_type->auth_tag_to_report, '', '', "a" => "" . $field->subfield('a') ); map { $authfield->add_subfields( $_->[0] => $_->[1] ) diff --git a/Koha/MetadataRecord/Authority.pm b/Koha/MetadataRecord/Authority.pm index 8d5977192d..da218af278 100644 --- a/Koha/MetadataRecord/Authority.pm +++ b/Koha/MetadataRecord/Authority.pm @@ -41,7 +41,7 @@ use Koha::Util::MARC; use base qw(Koha::MetadataRecord); -__PACKAGE__->mk_accessors(qw( authid authtype )); +__PACKAGE__->mk_accessors(qw( authid authtypecode )); =head2 new @@ -100,7 +100,7 @@ sub get_from_authid { $authtypecode ||= C4::AuthoritiesMarc::GuessAuthTypeCode($record); my $self = $class->SUPER::new( { authid => $authid, - authtype => $authtypecode, + authtypecode => $authtypecode, schema => $marcflavour, record => $record }); @@ -139,7 +139,7 @@ sub get_from_breeding { my $self = $class->SUPER::new( { schema => $marcflavour, - authtype => $authtypecode, + authtypecode => $authtypecode, record => $record }); bless $self, $class; diff --git a/authorities/authorities.pl b/authorities/authorities.pl index eedaf66b96..2eba66ebdd 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -568,7 +568,7 @@ my $breedingid = $input->param('breedingid'); my $dbh = C4::Context->dbh; if(!$authtypecode) { - $authtypecode = $authid? &GetAuthTypeCode($authid): ''; + $authtypecode = $authid ? Koha::Authorities->find($authid)->authtypecode : ''; } my ($template, $loggedinuser, $cookie) diff --git a/authorities/blinddetail-biblio-search.pl b/authorities/blinddetail-biblio-search.pl index 033bb21d6e..cab9c74456 100755 --- a/authorities/blinddetail-biblio-search.pl +++ b/authorities/blinddetail-biblio-search.pl @@ -47,6 +47,9 @@ use CGI qw ( -utf8 ); use MARC::Record; use C4::Koha; +use Koha::Authorities; +use Koha::Authority::Types; + my $query = new CGI; my $dbh = C4::Context->dbh; @@ -55,10 +58,10 @@ my $authid = $query->param('authid'); my $index = $query->param('index'); my $tagid = $query->param('tagid'); my $relationship = $query->param('relationship'); -my $authtypecode = &GetAuthTypeCode($authid); +my $authtypecode = Koha::Authorities->find($authid)->authtypecode; my $tagslib = &GetTagsLabels( 1, $authtypecode ); -my $auth_type = GetAuthType($authtypecode); +my $auth_type = Koha::Authority::Types->find($authtypecode); my $record; if ($authid) { $record = GetAuthority($authid); @@ -79,7 +82,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my @subfield_loop; my ($indicator1, $indicator2); if ($authid) { - my @fields = $record->field( $auth_type->{auth_tag_to_report} ); + my @fields = $record->field( $auth_type->auth_tag_to_report ); my $repet = ($query->param('repet') || 1) - 1; my $field = $fields[$repet]; @@ -104,7 +107,7 @@ if ($authid) { $indicator1 = $field->indicator('1'); $indicator2 = $field->indicator('2'); } elsif (C4::Context->preference('marcflavour') eq 'MARC21') { - my $tag_from = $auth_type->{auth_tag_to_report}; + my $tag_from = $auth_type->auth_tag_to_report; my $tag_to = $index; $tag_to =~ s/^tag_(\d*)_.*$/$1/; if ($tag_to =~ /^6/) { # subject heading diff --git a/authorities/detail-biblio-search.pl b/authorities/detail-biblio-search.pl index c001081fa4..717061b2ef 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::Authorities; use Koha::Authority::Types; my $query=new CGI; @@ -58,7 +59,7 @@ my $dbh=C4::Context->dbh; my $authid = $query->param('authid'); my $index = $query->param('index'); -my $authtypecode = &GetAuthTypeCode($authid); +my $authtypecode = Koha::Authorities->find($authid)->authtypecode; my $tagslib = &GetTagsLabels(1,$authtypecode); my $record =GetAuthority($authid); diff --git a/authorities/detail.pl b/authorities/detail.pl index f4c764d98c..1ba280d38a 100755 --- a/authorities/detail.pl +++ b/authorities/detail.pl @@ -47,6 +47,7 @@ use C4::Output; use CGI qw ( -utf8 ); use MARC::Record; use C4::Koha; +use Koha::Authorities; use Koha::Authority::Types; @@ -176,7 +177,7 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user( my $authid = $query->param('authid'); -my $authtypecode = GetAuthTypeCode($authid); +my $authtypecode = Koha::Authorities->find($authid)->authtypecode; $tagslib = &GetTagsLabels(1,$authtypecode); # Build list of authtypes for showing them diff --git a/authorities/merge.pl b/authorities/merge.pl index c9da83acf8..f34e55cb1d 100755 --- a/authorities/merge.pl +++ b/authorities/merge.pl @@ -104,12 +104,12 @@ else { if ($mergereference) { my $framework; - if ( $recordObj1->authtype ne $recordObj2->authtype && $mergereference ne 'breeding' ) { + if ( $recordObj1->authtypecode ne $recordObj2->authtypecode && $mergereference ne 'breeding' ) { $framework = $input->param('frameworkcode') or push @errors, { code => 'FRAMEWORK_NOT_SELECTED' }; } else { - $framework = $recordObj1->authtype; + $framework = $recordObj1->authtypecode; } if ($mergereference eq 'breeding') { $mergereference = $authid[0]; @@ -155,7 +155,7 @@ else { title1 => $recordObj1->authorized_heading, title2 => $recordObj2->authorized_heading, ); - if ( $recordObj1->authtype ne $recordObj2->authtype ) { + if ( $recordObj1->authtypecode ne $recordObj2->authtypecode ) { my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } ); my @frameworkselect; while ( my $authority_type = $authority_types->next ) { @@ -167,10 +167,10 @@ else { } $template->param( frameworkselect => \@frameworkselect, - frameworkcode1 => $recordObj1->authtype, - frameworkcode2 => $recordObj2->authtype, - frameworklabel1 => $frameworks->{$recordObj1->authtype}->{'authtypetext'}, - frameworklabel2 => $frameworks->{$recordObj2->authtype}->{'authtypetext'}, + frameworkcode1 => $recordObj1->authtypecode, + frameworkcode2 => $recordObj2->authtypecode, + frameworklabel1 => $recordObj1->authtypetext, + frameworklabel2 => $recordObj2->authtypetext, ); } } diff --git a/misc/migration_tools/merge_authority.pl b/misc/migration_tools/merge_authority.pl index 8e0959489b..87a02f9f99 100755 --- a/misc/migration_tools/merge_authority.pl +++ b/misc/migration_tools/merge_authority.pl @@ -55,8 +55,8 @@ $|=1; # flushes output my $authfrom = GetAuthority($mergefrom); my $authto = GetAuthority($mergeto); -my $authtypecodefrom = GetAuthTypeCode($mergefrom); -my $authtypecodeto = GetAuthTypeCode($mergeto); +my $authtypecodefrom = $mergefrom->authtypecode; +my $authtypecodeto = $mergeto->authtypecode; unless ($noconfirm || $batch) { print "************\n"; diff --git a/opac/opac-authoritiesdetail.pl b/opac/opac-authoritiesdetail.pl index 048787298e..b86701290e 100755 --- a/opac/opac-authoritiesdetail.pl +++ b/opac/opac-authoritiesdetail.pl @@ -75,7 +75,7 @@ if ( ! $record ) { exit; } -my $authtypecode = &GetAuthTypeCode( $authid ); +my $authtypecode = $record->authtypecode; if ($display_hierarchy){ $template->{VARS}->{'displayhierarchy'} = $display_hierarchy; diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl index 51095c3435..2f33fbbd95 100755 --- a/tools/batch_record_modification.pl +++ b/tools/batch_record_modification.pl @@ -25,7 +25,7 @@ use List::MoreUtils qw( uniq ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); -use C4::AuthoritiesMarc qw( BuildSummary GetAuthTypeCode ModAuthority ); +use C4::AuthoritiesMarc qw( BuildSummary ModAuthority ); use C4::BackgroundJob; use C4::Biblio qw( GetMarcBiblio ModBiblio ); use C4::MarcModificationTemplates qw( GetModificationTemplateActions GetModificationTemplates ModifyRecordWithTemplate ); @@ -216,7 +216,7 @@ if ( $op eq 'form' ) { my $authority = Koha::MetadataRecord::Authority->get_from_authid( $authid ); my $record = $authority->record; ModifyRecordWithTemplate( $mmtid, $record ); - ModAuthority( $authid, $record, GetAuthTypeCode( $authid ) ); + ModAuthority( $authid, $record, $authority->authtypecode ); }; if ( $error and $error != $authid or $@ ) { push @messages, { -- 2.39.5