Browse Source

Bug 11592: (QA followup) Simplify code

Koha::RecordProcessor and the defined filters are supposed to bring us
joy and happiness. Let's keep the code compact, simple and clean.

This patch removes record cloning all over the place.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
16.11.x
Tomás Cohen Arazi 8 years ago
committed by Kyle M Hall
parent
commit
ea27569334
  1. 11
      catalogue/ISBDdetail.pl
  2. 7
      opac/opac-ISBDdetail.pl
  3. 7
      opac/opac-MARCdetail.pl
  4. 8
      opac/opac-basket.pl
  5. 7
      opac/opac-detail.pl
  6. 6
      opac/opac-downloadcart.pl
  7. 7
      opac/opac-downloadshelf.pl
  8. 17
      opac/opac-export.pl
  9. 6
      opac/opac-shelves.pl
  10. 29
      opac/opac-showmarc.pl

11
catalogue/ISBDdetail.pl

@ -33,8 +33,7 @@ This script needs a biblionumber as parameter
=cut =cut
use strict; use Modern::Perl;
#use warnings; FIXME - Bug 2505
use HTML::Entities; use HTML::Entities;
use C4::Auth; use C4::Auth;
@ -51,9 +50,6 @@ use C4::Acquisition qw(GetOrdersByBiblionumber);
use Koha::RecordProcessor; use Koha::RecordProcessor;
#---- Internal function
my $query = new CGI; my $query = new CGI;
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
@ -80,15 +76,14 @@ if ( not defined $biblionumber ) {
exit; exit;
} }
my $record_unfiltered = GetMarcBiblio($biblionumber,1); my $record = GetMarcBiblio($biblionumber,1);
my $record_processor = Koha::RecordProcessor->new({ my $record_processor = Koha::RecordProcessor->new({
filters => 'ViewPolicy', filters => 'ViewPolicy',
options => { options => {
interface => 'intranet', interface => 'intranet',
}, },
}); });
my $record_filtered = $record_unfiltered->clone(); $record_processor->process($record);
my $record = $record_processor->process($record_filtered);
if ( not defined $record ) { if ( not defined $record ) {
# biblionumber invalid -> report and exit # biblionumber invalid -> report and exit

7
opac/opac-ISBDdetail.pl

@ -92,14 +92,13 @@ if (scalar @items >= 1) {
} }
} }
my $record_unfiltered = GetMarcBiblio($biblionumber,1); my $record = GetMarcBiblio($biblionumber,1);
if ( ! $record_unfiltered ) { if ( ! $record ) {
print $query->redirect("/cgi-bin/koha/errors/404.pl"); print $query->redirect("/cgi-bin/koha/errors/404.pl");
exit; exit;
} }
my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
my $record_filtered = $record_unfiltered->clone(); $record_processor->process($record);
my $record = $record_processor->process($record_filtered);
# some useful variables for enhanced content; # some useful variables for enhanced content;
# in each case, we're grabbing the first value we find in # in each case, we're grabbing the first value we find in

7
opac/opac-MARCdetail.pl

@ -85,14 +85,13 @@ my $tagslib = &GetMarcStructure( 0, $itemtype );
my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField('items.itemnumber',$itemtype); my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField('items.itemnumber',$itemtype);
my $biblio = GetBiblioData($biblionumber); my $biblio = GetBiblioData($biblionumber);
$biblionumber = $biblio->{biblionumber}; $biblionumber = $biblio->{biblionumber};
my $record_unfiltered = GetMarcBiblio($biblionumber, 1); my $record = GetMarcBiblio($biblionumber, 1);
if ( ! $record_unfiltered ) { if ( ! $record ) {
print $query->redirect("/cgi-bin/koha/errors/404.pl"); print $query->redirect("/cgi-bin/koha/errors/404.pl");
exit; exit;
} }
my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
my $record_filtered = $record_unfiltered->clone(); $record_processor->process($record);
my $record = $record_processor->process($record_filtered);
# open template # open template
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my ( $template, $loggedinuser, $cookie ) = get_template_and_user(

8
opac/opac-basket.pl

@ -15,9 +15,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>. # along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use strict;
use warnings;
use CGI qw ( -utf8 ); use CGI qw ( -utf8 );
use C4::Koha; use C4::Koha;
use C4::Biblio; use C4::Biblio;
@ -64,9 +63,8 @@ foreach my $biblionumber ( @bibs ) {
my $dat = &GetBiblioData($biblionumber); my $dat = &GetBiblioData($biblionumber);
next unless $dat; next unless $dat;
my $record_unfiltered = &GetMarcBiblio($biblionumber); my $record = &GetMarcBiblio($biblionumber);
my $record_filtered = $record_unfiltered->clone(); $record_processor->process($record);
my $record = $record_processor->process($record_filtered);
next unless $record; next unless $record;
my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );

7
opac/opac-detail.pl

@ -84,14 +84,13 @@ if (scalar @all_items >= 1) {
} }
} }
my $record_unfiltered = GetMarcBiblio($biblionumber); my $record = GetMarcBiblio($biblionumber);
if ( ! $record_unfiltered ) { if ( ! $record ) {
print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
exit; exit;
} }
my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
my $record_filtered = $record_unfiltered->clone(); $record_processor->process($record);
my $record = $record_processor->process($record_filtered);
# redirect if opacsuppression is enabled and biblio is suppressed # redirect if opacsuppression is enabled and biblio is suppressed
if (C4::Context->preference('OpacSuppression')) { if (C4::Context->preference('OpacSuppression')) {

6
opac/opac-downloadcart.pl

@ -68,10 +68,8 @@ if ($bib_list && $format) {
}); });
foreach my $biblio (@bibs) { foreach my $biblio (@bibs) {
my $record_unfiltered = GetMarcBiblio($biblio, 1); my $record = GetMarcBiblio($biblio, 1);
my $record_filtered = $record_unfiltered->clone(); $record_processor->process($record);
my $record =
$record_processor->process($record_filtered);
next unless $record; next unless $record;

7
opac/opac-downloadshelf.pl

@ -62,7 +62,7 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) {
my $contents = $shelf->get_contents; my $contents = $shelf->get_contents;
my $marcflavour = C4::Context->preference('marcflavour'); my $marcflavour = C4::Context->preference('marcflavour');
my $output; my $output;
my $extension; my $extension;
my $type; my $type;
@ -82,9 +82,8 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) {
while ( my $content = $contents->next ) { while ( my $content = $contents->next ) {
my $biblionumber = $content->biblionumber->biblionumber; my $biblionumber = $content->biblionumber->biblionumber;
my $record_unfiltered = GetMarcBiblio($biblionumber, 1); my $record = GetMarcBiblio($biblionumber, 1);
my $record_filtered = $record_unfiltered->clone(); $record_processor->process($record);
my $record = $record_processor->process($record_filtered);
next unless $record; next unless $record;
if ($format eq 'iso2709') { if ($format eq 'iso2709') {

17
opac/opac-export.pl

@ -35,9 +35,11 @@ my $biblionumber = $query->param("bib")||0;
$biblionumber = int($biblionumber); $biblionumber = int($biblionumber);
my $error = q{}; my $error = q{};
my $marc_unfiltered; my $include_items = ($format =~ /bibtex/) ? 0 : 1;
$marc_unfiltered = GetMarcBiblio($biblionumber, 1) if $biblionumber; my $marc = GetMarcBiblio($biblionumber, $include_items)
if(!$marc_unfiltered) { if $biblionumber;
if(!$marc) {
print $query->redirect("/cgi-bin/koha/errors/404.pl"); print $query->redirect("/cgi-bin/koha/errors/404.pl");
exit; exit;
} }
@ -45,12 +47,7 @@ if(!$marc_unfiltered) {
# ASSERT: There is a biblionumber, because GetMarcBiblio returned something. # ASSERT: There is a biblionumber, because GetMarcBiblio returned something.
my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
my $marc_filtered = $marc_unfiltered->clone(); $record_processor->process($marc);
my $marc = $record_processor->process($marc_filtered);
my $marc_noitems_unfiltered = GetMarcBiblio($biblionumber);
my $marc_noitems_filtered = $marc_noitems_unfiltered->clone();
my $marc_noitems = $record_processor->process($marc_noitems_filtered);
if ($format =~ /endnote/) { if ($format =~ /endnote/) {
$marc = marc2endnote($marc); $marc = marc2endnote($marc);
@ -69,7 +66,7 @@ elsif ($format =~ /ris/) {
$format = 'ris'; $format = 'ris';
} }
elsif ($format =~ /bibtex/) { elsif ($format =~ /bibtex/) {
$marc = marc2bibtex($marc_noitems,$biblionumber); $marc = marc2bibtex($marc,$biblionumber);
$format = 'bibtex'; $format = 'bibtex';
} }
elsif ($format =~ /dc$/) { elsif ($format =~ /dc$/) {

6
opac/opac-shelves.pl

@ -18,6 +18,7 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>. # along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl; use Modern::Perl;
use CGI qw ( -utf8 ); use CGI qw ( -utf8 );
use C4::Auth; use C4::Auth;
use C4::Biblio; use C4::Biblio;
@ -259,9 +260,8 @@ if ( $op eq 'view' ) {
while ( my $content = $contents->next ) { while ( my $content = $contents->next ) {
my $biblionumber = $content->biblionumber->biblionumber; my $biblionumber = $content->biblionumber->biblionumber;
my $this_item = GetBiblioData($biblionumber); my $this_item = GetBiblioData($biblionumber);
my $record_unfiltered = GetMarcBiblio($biblionumber); my $record = GetMarcBiblio($biblionumber);
my $record_filtered = $record_unfiltered->clone(); $record_processor->process($record);
my $record = $record_processor->process($record_filtered);
if ( $xslfile ) { if ( $xslfile ) {
$this_item->{XSLTBloc} = XSLTParse4Display( $biblionumber, $record, "OPACXSLTListsDisplay", $this_item->{XSLTBloc} = XSLTParse4Display( $biblionumber, $record, "OPACXSLTListsDisplay",

29
opac/opac-showmarc.pl

@ -39,34 +39,29 @@ $biblionumber = int($biblionumber);
my $importid= $input->param('importid'); my $importid= $input->param('importid');
my $view= $input->param('viewas') || 'marc'; my $view= $input->param('viewas') || 'marc';
my $record_unfiltered; my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
my $record;
if ($importid) { if ($importid) {
my ($marc) = GetImportRecordMarc($importid); my ($marc) = GetImportRecordMarc($importid);
$record_unfiltered = MARC::Record->new_from_usmarc($marc); $record = MARC::Record->new_from_usmarc($marc);
} }
else { else {
$record_unfiltered = GetMarcBiblio($biblionumber); $record = GetMarcBiblio($biblionumber);
my $frameworkcode = GetFrameworkCode($biblionumber);
$record_processor->options({ frameworkcode => $frameworkcode});
} }
if(!ref $record_unfiltered) {
if(!ref $record) {
print $input->redirect("/cgi-bin/koha/errors/404.pl"); print $input->redirect("/cgi-bin/koha/errors/404.pl");
exit; exit;
} }
my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); $record_processor->process($record);
my $record_filtered = $record_unfiltered->clone();
my $record = $record_processor->process($record_filtered);
if ($view eq 'card' || $view eq 'html') { if ($view eq 'card' || $view eq 'html') {
# FIXME: GetXmlBiblio needs filtering later. my $xml = $record->as_xml;
my $xml = $importid ? $record->as_xml(): GetXmlBiblio($biblionumber); my $xsl = $view eq 'card' ? 'compact.xsl' : 'plainMARC.xsl';
if (!$importid && $view eq 'html') {
my $unfiltered_record = MARC::Record->new_from_xml($xml);
my $frameworkcode = GetFrameworkCode($biblionumber);
$record_processor->options({ frameworkcode => $frameworkcode});
my $filtered_record = $record_processor->process($unfiltered_record);
$xml = $filtered_record->as_xml();
}
my $xsl = $view eq 'card' ? 'compact.xsl' : 'plainMARC.xsl';
my $htdocs = C4::Context->config('opachtdocs'); my $htdocs = C4::Context->config('opachtdocs');
my ($theme, $lang) = C4::Templates::themelanguage($htdocs, $xsl, 'opac', $input); my ($theme, $lang) = C4::Templates::themelanguage($htdocs, $xsl, 'opac', $input);
$xsl = "$htdocs/$theme/$lang/xslt/$xsl"; $xsl = "$htdocs/$theme/$lang/xslt/$xsl";

Loading…
Cancel
Save