Bug 20272: Changes for Breeding.pm and Record.pm
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Thu, 22 Feb 2018 14:46:12 +0000 (15:46 +0100)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 2 Jul 2018 12:12:49 +0000 (12:12 +0000)
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'.

The bonus is these error messages are now translatable as they are in
the templates

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

C4/Breeding.pm
C4/Record.pm
koha-tmpl/intranet-tmpl/prog/en/includes/xslt-handler.inc [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt
koha-tmpl/opac-tmpl/bootstrap/en/includes/xslt-handler.inc [new file with mode: 0644]
t/db_dependent/Breeding.t

index a17406b..324bb7c 100644 (file)
@@ -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
     }
 }
 
index e741c4f..174731d 100644 (file)
@@ -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 (file)
index 0000000..b3e93f3
--- /dev/null
@@ -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 %]
index e926742..3e22aca 100644 (file)
@@ -83,7 +83,7 @@
                 [% FOREACH errcon IN errconn %]
                     [% IF ( errcon.error == '10000' ) %]<li>Connection failed to [% errcon.server %]</li>
                     [% ELSIF ( errcon.error == '10007' ) %]<li>Connection timeout to [% errcon.server %]</li>
-                    [% ELSIF ( errcon.error == 'xslt_err' ) %]<li>[% errcon.server %]: Warning: XSLT error on search result [% errcon.seq %]</li>
+                    [% ELSIF errcon.error.match( '^XSLTH' ) %]<li>[% errcon.server %] record [% errcon.seq %]: [% PROCESS 'xslt-handler.inc' code=errcon.error %]</li>
                     [% ELSE %]<li>[% errcon.server %] record [% errcon.seq %]: [% errcon.error %]</li>
                     [% END %]
                 [% END %]
     [% 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 (file)
index 0000000..b3e93f3
--- /dev/null
@@ -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 %]
index 6cfd684..54a9ca9 100644 (file)
@@ -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 :)' );
 }