Koha/authorities/authorities-list.pl
Colin Campbell 263dded818 Bug 6752: Be stricter with utf-8 encoding of output
use encoding(UTF-8) rather than utf-8 for stricter
encoding
Marking output as ':utf8' only flags the data as utf8
using :encoding(UTF-8) also checks it as valid utf-8
see binmode in perlfunc for more details
In accordance with the robustness principle input
filehandles have not been changed as code may make
the undocumented assumption that invalid utf-8 is present
in the imput
Fixes errors reported by t/00-testcritic.t
Where feasable some filehandles have been made lexical rather than
reusing global filehandle vars

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
2012-01-27 12:11:06 +01:00

34 lines
1.2 KiB
Perl
Executable file

#!/usr/bin/perl
use strict;
use warnings;
use C4::Context;
use C4::AuthoritiesMarc;
use utf8;
use open qw[ :std :encoding(utf8) ];
my $dbh=C4::Context->dbh;
my $datatypes_query = $dbh->prepare(<<ENDSQL);
SELECT authtypecode,authtypetext,auth_tag_to_report from auth_types;
ENDSQL
$datatypes_query->execute;
my $datatypes=$datatypes_query->fetchall_arrayref({});
my %authtypes;
map { $authtypes{$_->{'authtypecode'}}={"tag"=> $_->{'auth_tag_to_report'}, "lib"=> $_->{'authtypetext'}};} @$datatypes;
my $data_query = $dbh->prepare(<<ENDSQL);
SELECT authid, authtypecode from auth_header
ENDSQL
$data_query->execute;
my $dataauthorities=$data_query->fetchall_arrayref({});
foreach my $authority (@$dataauthorities){
my $marcauthority=GetAuthority($authority->{'authid'});
my $query;
$query= "an=".$authority->{'authid'};
# search for biblios mapped
my ($err,$res,$used) = C4::Search::SimpleSearch($query,0,10);
if (defined $err) {
$used = 0;
}
if ($marcauthority && $marcauthority->field($authtypes{$authority->{'authtypecode'}}->{'tag'})){
print qq("),$marcauthority->field($authtypes{$authority->{'authtypecode'}}->{"tag"})->as_string(),qq(";),qq($authority->{'authid'};"),$authtypes{$authority->{'authtypecode'}}->{'lib'},qq(";$used\n);
}
}