From 98f638bb14d0a5763e45ee32c5bc07756324c6e1 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 25 Jun 2008 11:30:01 -0500 Subject: [PATCH] bug 2254 [1/3]: fixed GetAuthType(); avoid crash Improved C4::AuthoritiesMarc::GetAuthType() so that it returns either a hashref (if the authority type exists) or undef (if it does not exist). The same accessor should not be used to either return a single value or all values of a settings list. Note that all existing clients of GetAuthType are expecting either a single hashref or undef; none of them expected the arrayref that could be returned by the previous version of the accessor. When BiblioAddsAuthorities is ON, addbiblio.pl now checks the return value of GetAuthType and no longer crashes as follows if the MARC framework specifies an invalid authority type for a given subfield: Can't coerce array into hash at .../cataloging/addbiblio.pl line 738. No documentation changes. Signed-off-by: Joshua Ferraro --- C4/AuthoritiesMarc.pm | 29 ++++++++++++----------------- cataloguing/addbiblio.pl | 1 + 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index e89ed612c4..023cda00eb 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -698,14 +698,14 @@ sub GetAuthority { =over 4 -$result= &GetAuthType( $authtypecode) -If $authtypecode is not "" then - Returns hashref to authtypecode information -else - returns ref to array of hashref information of all Authtypes +$result = &GetAuthType($authtypecode) =back +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 { @@ -713,19 +713,14 @@ sub GetAuthType { my $dbh=C4::Context->dbh; my $sth; if (defined $authtypecode){ # NOTE - in MARC21 framework, '' is a valid authority - # type - $sth=$dbh->prepare("select * from auth_types where authtypecode=?"); - $sth->execute($authtypecode); - } else { - $sth=$dbh->prepare("select * from auth_types"); - $sth->execute; - } - my $res=$sth->fetchall_arrayref({}); - if (scalar(@$res)==1){ - return $res->[0]; - } else { - return $res; + # 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; } diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 441fdf9540..ca07b26966 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -767,6 +767,7 @@ AND (authtypecode IS NOT NULL AND authtypecode<>\"\")|); ###NOTICE : This is only valid if a subfield is linked to one and only one authtypecode ###NOTICE : This can be a problem. We should also look into other types and rejected forms. my $authtypedata=GetAuthType($data->{authtypecode}); + next unless $authtypedata; my $marcrecordauth=MARC::Record->new(); my $authfield=MARC::Field->new($authtypedata->{auth_tag_to_report},'','',"a"=>"".$field->subfield('a')); map { $authfield->add_subfields($_->[0]=>$_->[1]) if ($_->[0]=~/[A-z]/ && $_->[0] ne "a" )} $field->subfields(); -- 2.39.5