From 6b23243360cfb1fb28aff82e06d035ebfbacb993 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 22 Feb 2011 16:46:46 -0300 Subject: [PATCH] [Bug 5791] Robust handling of deleted biblios/authorities Content-Type: text/plain; charset="utf-8" --- authorities/detail.pl | 110 +++++++++++--------- catalogue/detail.pl | 21 +++-- .../prog/en/modules/authorities/detail.tmpl | 98 +++++++++--------- .../prog/en/modules/catalogue/detail.tmpl | 11 ++- 4 files changed, 131 insertions(+), 109 deletions(-) diff --git a/authorities/detail.pl b/authorities/detail.pl index f92e04b..9849f31 100755 --- a/authorities/detail.pl +++ b/authorities/detail.pl @@ -175,53 +175,65 @@ my $authid = $query->param('authid'); my $authtypecode = &GetAuthTypeCode($authid); -$tagslib = &GetTagsLabels(1,$authtypecode); - -my $record; -if (C4::Context->preference("AuthDisplayHierarchy")){ - my $trees=BuildUnimarcHierarchies($authid); - my @trees = split /;/,$trees ; - push @trees,$trees unless (@trees); - my @loophierarchies; - foreach my $tree (@trees){ - my @tree=split /,/,$tree; - push @tree,$tree unless (@tree); - my $cnt=0; - my @loophierarchy; - foreach my $element (@tree){ - my $elementdata = GetAuthority($element); - $record= $elementdata if ($authid==$element); - push @loophierarchy, BuildUnimarcHierarchy($elementdata,"child".$cnt, $authid); - $cnt++; - } - push @loophierarchies, { 'loopelement' =>\@loophierarchy}; - } - $template->param( - 'displayhierarchy' =>C4::Context->preference("AuthDisplayHierarchy"), - 'loophierarchies' =>\@loophierarchies, - ); -} else { - $record=GetAuthority($authid); -} -my $count = CountUsage($authid); - -# find the marc field/subfield used in biblio by this authority -my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?"); -$sth->execute($authtypecode); -my $biblio_fields; -while (my ($tagfield) = $sth->fetchrow) { - $biblio_fields.= $tagfield."9,"; -} -chop $biblio_fields; +if ( defined $authtypecode ) { + # authid is valid + $tagslib = &GetTagsLabels(1,$authtypecode); + + my $record; + if (C4::Context->preference("AuthDisplayHierarchy")){ + my $trees=BuildUnimarcHierarchies($authid); + my @trees = split /;/,$trees ; + push @trees,$trees unless (@trees); + my @loophierarchies; + foreach my $tree (@trees){ + my @tree=split /,/,$tree; + push @tree,$tree unless (@tree); + my $cnt=0; + my @loophierarchy; + foreach my $element (@tree){ + my $elementdata = GetAuthority($element); + $record= $elementdata if ($authid==$element); + push @loophierarchy, BuildUnimarcHierarchy($elementdata,"child".$cnt, $authid); + $cnt++; + } + push @loophierarchies, { 'loopelement' =>\@loophierarchy}; + } + $template->param( + 'displayhierarchy' =>C4::Context->preference("AuthDisplayHierarchy"), + 'loophierarchies' =>\@loophierarchies, + ); + } else { + $record=GetAuthority($authid); + } + + my $count = CountUsage($authid); + + # find the marc field/subfield used in biblio by this authority + my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?"); + $sth->execute($authtypecode); + my $biblio_fields; + while (my ($tagfield) = $sth->fetchrow) { + $biblio_fields.= $tagfield."9,"; + } + chop $biblio_fields; + + # loop through each tab 0 through 9 + # for (my $tabloop = 0; $tabloop<=10;$tabloop++) { + # loop through each tag + build_tabs ($template, $record, $dbh,"",$query); + + $template->param(authid => $authid, + count => $count, + biblio_fields => $biblio_fields, + ); -# fill arrays -my @loop_data =(); -my $tag; -# loop through each tab 0 through 9 -# for (my $tabloop = 0; $tabloop<=10;$tabloop++) { -# loop through each tag - build_tabs ($template, $record, $dbh,"",$query); +} else { + # authid invalid + # set default $authtypecode + $authtypecode = ''; + $template->param ( errauthid => $authid,unknownauthid => 1 ); +} my $authtypes = getauthtypes; my @authtypesloop; @@ -233,11 +245,9 @@ foreach my $thisauthtype (sort { $authtypes->{$b} cmp $authtypes->{$a} } keys %$ push @authtypesloop, \%row; } -$template->param(authid => $authid, - count => $count, - biblio_fields => $biblio_fields, +$template->param ( authtypetext => $authtypes->{$authtypecode}{'authtypetext'}, authtypesloop => \@authtypesloop, - ); -output_html_with_http_headers $query, $cookie, $template->output; +); +output_html_with_http_headers $query, $cookie, $template->output; \ No newline at end of file diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 6ee79e6..6682482 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -52,11 +52,21 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( ); my $biblionumber = $query->param('biblionumber'); -my $fw = GetFrameworkCode($biblionumber); ## get notes and subjects from MARC record -my $marcflavour = C4::Context->preference("marcflavour"); -my $record = GetMarcBiblio($biblionumber); +my $record = GetMarcBiblio($biblionumber); + +if ( not defined $record ) { + # biblionumber invalid -> report and exit + $template->param( unknownbiblionumber => 1, + biblionumber => $biblionumber + ); + output_html_with_http_headers $query, $cookie, $template->output; + exit; +} + +my $fw = GetFrameworkCode($biblionumber); +my $marcflavour = C4::Context->preference("marcflavour"); # XSLT processing of some stuff if (C4::Context->preference("XSLTDetailsDisplay") ) { @@ -81,11 +91,6 @@ $template->param( normalized_isbn => $isbn, ); -unless (defined($record)) { - print $query->redirect("/cgi-bin/koha/errors/404.pl"); - exit; -} - my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); my $marcisbnsarray = GetMarcISBN( $record, $marcflavour ); my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tmpl index 417581c..c51e697 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tmpl @@ -1,5 +1,5 @@ -Koha › Authorities › Details for Authority #<!-- TMPL_VAR NAME="authid" --> (<!-- TMPL_VAR name="authtypetext" -->) +Koha › Authorities › <!-- TMPL_IF NAME="unknownauthid" --> Unknown authority<!-- TMPL_ELSE -->Details for Authority #<!-- TMPL_VAR NAME="authid" --> (<!-- TMPL_VAR name="authtypetext" -->)<!-- /TMPL_IF -->