From a703aef821c864d9a32cab912d5e8f59b65261c7 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 22 Feb 2018 15:46:12 +0100 Subject: [PATCH] Bug 20272: Changes for Breeding.pm and Record.pm Content-Type: text/plain; charset=utf-8 In Breeding.pm we let Z3950Search return the xslt handler error codes back to the template. They are converted to text messages by using an new include file (added for opac and intranet now). The generic xslt_err code is now obsoleted. In Record.pm the errstr call is removed. The croak is done with the new error code in err. This seems sufficient. Test plan: [1] Run Breeding.t [2] Run Record.t [3] Add a nonexisting xslt file to one of your Z3950 targets. Search on that target and check if you see a error 'XSLT file not found'. Signed-off-by: Marcel de Rooy --- C4/Breeding.pm | 2 +- C4/Record.pm | 5 ++-- .../prog/en/includes/xslt-handler.inc | 16 +++++++++++++ .../prog/en/modules/cataloguing/z3950_search.tt | 4 ++-- .../bootstrap/en/includes/xslt-handler.inc | 16 +++++++++++++ t/db_dependent/Breeding.t | 27 +++++++--------------- 6 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/xslt-handler.inc create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/includes/xslt-handler.inc diff --git a/C4/Breeding.pm b/C4/Breeding.pm index a17406b..324bb7c 100644 --- a/C4/Breeding.pm +++ b/C4/Breeding.pm @@ -316,7 +316,7 @@ sub _do_xslt_proc { if( !$xslh->err ) { return MARC::Record->new_from_xml($xml, 'UTF-8'); } else { - return ( $marc, 'xslt_err' ); #original record in case of errors + return ( $marc, $xslh->err ); #original record in case of errors } } diff --git a/C4/Record.pm b/C4/Record.pm index af619ac..c53bc25 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -300,10 +300,9 @@ sub marc2dcxml { croak "The format argument ($format) not accepted.\n" . "Please pass a valid format (oaidc, srwdc, or rdfdc)\n"; } - my $err = $xslt_engine->err; # error number - my $errstr = $xslt_engine->errstr; # error message + my $err = $xslt_engine->err; # error code if ( $err ) { - croak "Error when processing $errstr Error number: $err\n"; + croak "Error $err while processing\n"; } else { return $output; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/xslt-handler.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/xslt-handler.inc new file mode 100644 index 0000000..b3e93f3 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/xslt-handler.inc @@ -0,0 +1,16 @@ +[% SWITCH code %] + [% CASE 'XSLTH_ERR_NO_FILE' %] + No XSLT file passed. + [% CASE 'XSLTH_ERR_FILE_NOT_FOUND' %] + XSLT file not found. + [% CASE 'XSLTH_ERR_LOADING' %] + Error while loading stylesheet. + [% CASE 'XSLTH_ERR_PARSING_CODE' %] + Error while parsing stylesheet. + [% CASE 'XSLTH_ERR_PARSING_DATA' %] + Error while parsing input. + [% CASE 'XSLTH_ERR_TRANSFORMING' %] + Error while transforming input. + [% CASE 'XSLTH_NO_STRING_PASSED' %] + No string to transform. +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt index ee05d96..7be70cf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt @@ -82,7 +82,7 @@ [% FOREACH errcon IN errconn %] [% IF ( errcon.error == '10000' ) %]
  • Connection failed to [% errcon.server %]
  • [% ELSIF ( errcon.error == '10007' ) %]
  • Connection timeout to [% errcon.server %]
  • - [% ELSIF ( errcon.error == 'xslt_err' ) %]
  • [% errcon.server %]: Warning: XSLT error on search result [% errcon.seq %]
  • + [% ELSIF errcon.error.match( '^XSLTH' ) %]
  • [% errcon.server %] record [% errcon.seq %]: [% PROCESS 'xslt-handler.inc' code=errcon.error %]
  • [% ELSE %]
  • [% errcon.server %] record [% errcon.seq %]: [% errcon.error %]
  • [% END %] [% END %] @@ -245,4 +245,4 @@ [% INCLUDE 'z3950_search.inc' %] [% END %] -[% INCLUDE 'intranet-bottom.inc' popup_window=1 %] \ No newline at end of file +[% INCLUDE 'intranet-bottom.inc' popup_window=1 %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/xslt-handler.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/xslt-handler.inc new file mode 100644 index 0000000..b3e93f3 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/xslt-handler.inc @@ -0,0 +1,16 @@ +[% SWITCH code %] + [% CASE 'XSLTH_ERR_NO_FILE' %] + No XSLT file passed. + [% CASE 'XSLTH_ERR_FILE_NOT_FOUND' %] + XSLT file not found. + [% CASE 'XSLTH_ERR_LOADING' %] + Error while loading stylesheet. + [% CASE 'XSLTH_ERR_PARSING_CODE' %] + Error while parsing stylesheet. + [% CASE 'XSLTH_ERR_PARSING_DATA' %] + Error while parsing input. + [% CASE 'XSLTH_ERR_TRANSFORMING' %] + Error while transforming input. + [% CASE 'XSLTH_NO_STRING_PASSED' %] + No string to transform. +[% END %] diff --git a/t/db_dependent/Breeding.t b/t/db_dependent/Breeding.t index 6cfd684..54a9ca9 100644 --- a/t/db_dependent/Breeding.t +++ b/t/db_dependent/Breeding.t @@ -46,7 +46,7 @@ subtest '_create_connection' => sub { }; #Group 3: testing _do_xslt_proc (part of Z3950Search) subtest '_do_xslt_proc' => sub { - plan tests => 7; + plan tests => 6; test_do_xslt(); }; @@ -162,27 +162,16 @@ sub test_do_xslt { #ready for the main test my @res = C4::Breeding::_do_xslt_proc( $biblio, $server, $engine ); - is( $res[1] && $res[1] eq 'xslt_err', undef, - 'Check error code of _do_xslt_proc'); - if( !$res[1] ) { - is( ref $res[0] eq 'MARC::Record', 1, 'Got back MARC record'); - my $sub = $res[0]->subfield('990','a')//''; - is( $sub eq 'I saw you', 1, 'Found 990a in the record'); - } else { - ok( 1, 'Skipped one test'); - ok( 1, 'Skipped another one'); - } + is( $res[1], undef, 'No error returned' ); + is( ref $res[0], 'MARC::Record', 'Got back MARC record'); + is( $res[0]->subfield('990','a'), 'I saw you', 'Found 990a in the record'); #forcing an error on the xslt side $server->{add_xslt} = 'notafile.xsl'; - warning_like - { @res = C4::Breeding::_do_xslt_proc( $biblio, $server, $engine ) } - qr/^XSLT file not found./, - '_do_xslt_proc warns it XSLT_handler problem'; - is( $res[1] && $res[1] eq 'xslt_err', 1, - 'Check error code again'); + @res = C4::Breeding::_do_xslt_proc( $biblio, $server, $engine ); + is( $res[1], Koha::XSLT_Handler::XSLTH_ERR_2, 'Error code found' ); #We still expect the original record back - is( ref $res[0] eq 'MARC::Record', 1, 'Still got back MARC record'); - is ( $res[0]->subfield('245','a') eq 'Just a title', 1, + is( ref $res[0], 'MARC::Record', 'Still got back MARC record' ); + is ( $res[0]->subfield('245','a'), 'Just a title', 'At least the title is the same :)' ); } -- 2.1.4