[Koha-patches] [PATCH] [Bug 5791] Robust handling of deleted biblios/authorities

Tomas Cohen Arazi tomascohen at gmail.com
Tue Feb 22 20:48:34 CET 2011


---
 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 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
-<title>Koha &rsaquo; Authorities &rsaquo; Details for Authority #<!-- TMPL_VAR NAME="authid" --> (<!-- TMPL_VAR name="authtypetext" -->)</title>
+<title>Koha &rsaquo; Authorities &rsaquo; <!-- TMPL_IF NAME="unknownauthid" --> Unknown authority<!-- TMPL_ELSE -->Details for Authority #<!-- TMPL_VAR NAME="authid" --> (<!-- TMPL_VAR name="authtypetext" -->)<!-- /TMPL_IF --></title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
 <script type="text/javascript">
 
@@ -62,7 +62,7 @@ function searchauthority() {
 <body>
 <!-- TMPL_INCLUDE NAME="header.inc" -->
 <!-- TMPL_INCLUDE NAME="authorities-search.inc" -->
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/authorities/authorities-home.pl">Authorities</a> &rsaquo; Details for Authority #<!-- TMPL_VAR NAME="authid" --> (<!-- TMPL_VAR name="authtypetext" -->) </div>
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/authorities/authorities-home.pl">Authorities</a> &rsaquo; <!-- TMPL_IF NAME="unknownauthid" --> Unknown authority<!-- TMPL_ELSE--> Details for Authority #<!-- TMPL_VAR NAME="authid" --> (<!-- TMPL_VAR name="authtypetext" -->)<!-- /TMPL_IF --></div>
 
 <div id="doc" class="yui-t7">
 
@@ -103,55 +103,57 @@ function searchauthority() {
 </div>
 <!-- /TMPL_IF -->
 
-<h1>Authority #<!-- TMPL_VAR NAME="authid" --> (<!-- TMPL_VAR name="authtypetext" -->)</h1>
+<!-- TMPL_IF NAME="unknownauthid" -->
+   <div class="dialog message">The authority you requested does not exist (<!-- TMPL_VAR NAME="errauthid" -->).</div>
+<!-- TMPL_ELSE -->
 
-<div id="action">
-    
-    
-    Used in <a href="/cgi-bin/koha/catalogue/search.pl?type=intranet&amp;op=do_search&amp;q=an=<!--TMPL_VAR Name="authid" -->"><!-- TMPL_VAR name="count" --> record(s)</a>
-</div>
+	<h1>Authority #<!-- TMPL_VAR NAME="authid" --> (<!-- TMPL_VAR name="authtypetext" -->)</h1>
+	<div id="action">
+		Used in <a href="/cgi-bin/koha/catalogue/search.pl?type=intranet&amp;op=do_search&amp;q=an=<!--TMPL_VAR Name="authid" -->"><!-- TMPL_VAR name="count" --> record(s)</a>
+	</div>
 
-<div id="authoritiestabs" class="toptabs numbered">
-    <ul>
-        <!-- TMPL_LOOP name="BIG_LOOP" -->
-            <li>
-                <a href="/cgi-bin/koha/cataloguing/addbiblio.pl#tab<!-- TMPL_VAR name="number" -->XX"><!-- TMPL_VAR name="number"--></a>
-            </li>
-        <!-- /TMPL_LOOP -->
-    </ul>
+	<div id="authoritiestabs" class="toptabs numbered">
+		<ul>
+			<!-- TMPL_LOOP name="BIG_LOOP" -->
+				<li>
+					<a href="/cgi-bin/koha/cataloguing/addbiblio.pl#tab<!-- TMPL_VAR name="number" -->XX"><!-- TMPL_VAR name="number"--></a>
+				</li>
+			<!-- /TMPL_LOOP -->
+		</ul>
 
-<!-- TMPL_LOOP name="BIG_LOOP" -->
-    <div id="tab<!-- TMPL_VAR name="number" -->XX">
-    <!-- TMPL_LOOP NAME="innerloop" -->
-        <!-- TMPL_IF name="tag" -->
-            <div class="tag">
-            <div class="tag_title">
-                <!-- TMPL_VAR NAME="tag" -->
-            </div>
-        <!-- TMPL_ELSE -->
-            <div class="tag">
-        <!-- /TMPL_IF -->
-        <!-- TMPL_LOOP NAME="subfield" -->
-            <p>
-                <label class="labelsubfield">&nbsp;
-                <!-- TMPL_UNLESS name="hide_marc" --><b><!-- TMPL_VAR NAME="marc_subfield" --></b><!-- /TMPL_UNLESS -->
-                <span title="<!-- TMPL_VAR name="long_desc" -->"><!-- TMPL_VAR NAME="short_desc" --></span></label>
-                <!-- TMPL_VAR NAME="marc_value" -->
-                <!-- TMPL_IF name="link" -->
-                    <a href="/cgi-bin/koha/catalogue/search.pl?op=do_search&amp;marclist=<!-- TMPL_VAR NAME="link" -->&amp;operator==&amp;type=intranet&amp;value=<!-- TMPL_VAR NAME="marc_value" ESCAPE="URL" -->">
-                        <img border="0" src="<!-- TMPL_VAR NAME="interface" -->/<!-- TMPL_VAR NAME="theme" -->/images/filefind.png" height="15" title="Search on <!-- TMPL_VAR name="marc_value" -->">
-                    </a>
-                <!-- /TMPL_IF -->
-                <!-- TMPL_IF NAME="authority" -->
-                    <a href="/cgi-bin/koha/authorities/detail.pl?authid=<!-- TMPL_VAR name="authority" -->" class="button">Auth</a>
-                <!-- /TMPL_IF -->
-            </p>
-        <!-- /TMPL_LOOP -->
-        </div>
-    <!-- /TMPL_LOOP -->
-    </div>
-<!-- /TMPL_LOOP -->
-</div>
+	<!-- TMPL_LOOP name="BIG_LOOP" -->
+		<div id="tab<!-- TMPL_VAR name="number" -->XX">
+		<!-- TMPL_LOOP NAME="innerloop" -->
+			<!-- TMPL_IF name="tag" -->
+				<div class="tag">
+				<div class="tag_title">
+					<!-- TMPL_VAR NAME="tag" -->
+				</div>
+			<!-- TMPL_ELSE -->
+				<div class="tag">
+			<!-- /TMPL_IF -->
+			<!-- TMPL_LOOP NAME="subfield" -->
+				<p>
+					<label class="labelsubfield">&nbsp;
+					<!-- TMPL_UNLESS name="hide_marc" --><b><!-- TMPL_VAR NAME="marc_subfield" --></b><!-- /TMPL_UNLESS -->
+					<span title="<!-- TMPL_VAR name="long_desc" -->"><!-- TMPL_VAR NAME="short_desc" --></span></label>
+					<!-- TMPL_VAR NAME="marc_value" -->
+					<!-- TMPL_IF name="link" -->
+						<a href="/cgi-bin/koha/catalogue/search.pl?op=do_search&amp;marclist=<!-- TMPL_VAR NAME="link" -->&amp;operator==&amp;type=intranet&amp;value=<!-- TMPL_VAR NAME="marc_value" ESCAPE="URL" -->">
+							<img border="0" src="<!-- TMPL_VAR NAME="interface" -->/<!-- TMPL_VAR NAME="theme" -->/images/filefind.png" height="15" title="Search on <!-- TMPL_VAR name="marc_value" -->">
+						</a>
+					<!-- /TMPL_IF -->
+					<!-- TMPL_IF NAME="authority" -->
+						<a href="/cgi-bin/koha/authorities/detail.pl?authid=<!-- TMPL_VAR name="authority" -->" class="button">Auth</a>
+					<!-- /TMPL_IF -->
+				</p>
+			<!-- /TMPL_LOOP -->
+			</div>
+		<!-- /TMPL_LOOP -->
+		</div>
+	<!-- /TMPL_LOOP -->
+	</div>
+<!-- /TMPL_IF -->
 </div>
 </div>
 </div>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl
index 8f53e80..dfe483b 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl
@@ -1,5 +1,5 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
-<title>Koha &rsaquo; Catalog &rsaquo; Details for <!-- TMPL_VAR NAME="title" escape="html" --> <!-- TMPL_LOOP NAME="subtitle" --> <!-- TMPL_VAR NAME="subfield" --><!-- /TMPL_LOOP --></title>
+<title>Koha &rsaquo; Catalog &rsaquo; <!-- TMPL_IF NAME="unknownbiblionumber" -->Unknown biblio<!-- TMPL_ELSE -->Details for <!-- TMPL_VAR NAME="title" escape="html" --> <!-- TMPL_LOOP NAME="subtitle" --> <!-- TMPL_VAR NAME="subfield" --><!-- /TMPL_LOOP --><!-- /TMPL_IF --></title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" --><script type="text/JavaScript" language="JavaScript">
 //<![CDATA[
 // http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html
@@ -44,10 +44,14 @@ function verify_images() {
 <!-- TMPL_INCLUDE NAME="header.inc" -->
 <!-- TMPL_INCLUDE NAME="cat-search.inc" -->
 
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>  &rsaquo; Details for <i><!-- TMPL_VAR NAME="title" escape="html" -->  <!-- TMPL_LOOP NAME="subtitle" --> <!-- TMPL_VAR NAME="subfield" --><!-- /TMPL_LOOP --></i></div>
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>  &rsaquo; <!-- TMPL_IF NAME="unknownbiblionumber" -->Unknown biblio<!-- TMPL_ELSE --> Details for <i><!-- TMPL_VAR NAME="title" escape="html" -->  <!-- TMPL_LOOP NAME="subtitle" --> <!-- TMPL_VAR NAME="subfield" --><!-- /TMPL_LOOP --><!-- /TMPL_IF --></i></div>
 
 <div id="doc3" class="yui-t2">
-   
+
+<!-- TMPL_IF NAME="unknownbiblionumber" -->
+	<div class="dialog message">The biblio you requested does not exist (<!-- TMPL_VAR NAME="biblionumber" -->).</div>
+<!-- TMPL_ELSE -->
+
    <div id="bd">
     <div id="yui-main">
     <div class="yui-b">
@@ -506,5 +510,6 @@ function verify_images() {
 <div class="yui-b">
 <!-- TMPL_INCLUDE NAME="biblio-view-menu.inc" -->
 </div>
+<!-- /TMPL_IF -->
 </div>
 <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
-- 
1.7.1



More information about the Koha-patches mailing list