Bugzilla – Attachment 180232 Details for
Bug 19220
Allow XSLT processing for Z39.50 authority targets like for bibliographic targets
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19220: Allow XSLT processing for Z39.50 authority targets
Bug-19220-Allow-XSLT-processing-for-Z3950-authorit.patch (text/plain), 5.96 KB, created by
Nick Clemens (kidclamp)
on 2025-04-02 07:17:32 UTC
(
hide
)
Description:
Bug 19220: Allow XSLT processing for Z39.50 authority targets
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2025-04-02 07:17:32 UTC
Size:
5.96 KB
patch
obsolete
>From 073b5ae446bb40bc84d69f2bd892dd4fedb7001f Mon Sep 17 00:00:00 2001 >From: Matthias Meusburger <matthias.meusburger@biblibre.com> >Date: Tue, 22 Dec 2020 15:41:53 +0100 >Subject: [PATCH] Bug 19220: Allow XSLT processing for Z39.50 authority targets > >Test plan: > > 1) Apply the patch > > 2) Edit an authority Z3950/SRU source in Home > Administration > Z39.50/SRU servers > > 3) Add the path to an XSLT file in the "XSLT File(s) for transforming results" input, and save > For instance: <path_to_src>/koha-tmpl/intranet-tmpl/prog/en/xslt/Bug19220.xsl > > 4) Search for an authority with the "New from Z39.50/SRU" button in authorities home > > 5) Check that the XSLT transformation has been applied, both in results list and in the import window > > 6) Edit the Z3950/SRU source to remove the path to the XSLT file > > 7) Search again for the same authority, and check that no transformation has been applied > > 8) prove t/db_dependent/Breeding_Auth.t > >Here is an example XSLT which adds a 035$a field: > ><?xml version="1.0" encoding="UTF-8"?> ><xsl:stylesheet xmlns:marc="http://www.loc.gov/MARC21/slim" version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> > > <xsl:template match="record|marc:record"> > <record> > <xsl:apply-templates/> > <datafield tag="035" ind1='' ind2=''> > <subfield code="a"> > <xsl:text>XSLT added field</xsl:text> > </subfield> > </datafield> > </record> > </xsl:template> > > <xsl:template match="node()"> > <xsl:copy select="."> > <xsl:copy-of select="@*"/> > <xsl:apply-templates/> > </xsl:copy> > </xsl:template> ></xsl:stylesheet> > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > C4/Breeding.pm | 12 +++++++++++- > t/db_dependent/Breeding_Auth.t | 27 ++++++++++++++++++++++++--- > 2 files changed, 35 insertions(+), 4 deletions(-) > >diff --git a/C4/Breeding.pm b/C4/Breeding.pm >index 538436d9a0a..5917dfc9c2d 100644 >--- a/C4/Breeding.pm >+++ b/C4/Breeding.pm >@@ -503,12 +503,18 @@ sub ImportBreedingAuth { > my $searchbreeding = > $dbh->prepare("select import_record_id from import_auths where control_number=? and authorized_heading=?"); > >+ my $marc_type = C4::Context->preference('marcflavour'); > my $controlnumber = $marcrecord->field('001')->data; > > $searchbreeding->execute( $controlnumber, $heading ); > my ($breedingid) = $searchbreeding->fetchrow; > >- return $breedingid if $breedingid; >+ if ($breedingid) { >+ my $updbrd = $dbh->prepare("update import_records set marc=?,marcxml=? where import_record_id=?"); >+ $updbrd->execute( $marcrecord->as_usmarc(), $marcrecord->as_xml($marc_type), $breedingid ); >+ $updbrd->finish(); >+ return $breedingid; >+ } > $breedingid = AddAuthToBatch( $batch_id, 0, $marcrecord, $encoding ); > return $breedingid; > } >@@ -545,6 +551,7 @@ sub Z3950SearchAuth { > my $query; > my $nterms = 0; > >+ my $xslh = Koha::XSLT::Base->new; > my $marcflavour = C4::Context->preference('marcflavour'); > my $marc_type = $marcflavour eq 'UNIMARC' ? 'UNIMARCAUTH' : $marcflavour; > my $authid = $pars->{authid}; >@@ -626,6 +633,9 @@ sub Z3950SearchAuth { > $marcrecord->encoding('UTF-8'); > SetUTF8Flag($marcrecord); > >+ my $error; >+ ( $marcrecord, $error ) = _do_xslt_proc( $marcrecord, $servers[$k], $xslh ); >+ > my $heading_authtype_code = GuessAuthTypeCode($marcrecord) or next; > my $heading = GetAuthorizedHeading( { record => $marcrecord } ); > my $breedingid = ImportBreedingAuth( $marcrecord, $servers[$k]->{host}, 'UTF-8', $heading ); >diff --git a/t/db_dependent/Breeding_Auth.t b/t/db_dependent/Breeding_Auth.t >index 9997dbc14ab..428ca97e5de 100755 >--- a/t/db_dependent/Breeding_Auth.t >+++ b/t/db_dependent/Breeding_Auth.t >@@ -22,8 +22,7 @@ > use Modern::Perl; > use utf8; > >-use Test::NoWarnings; >-use Test::More tests => 3; >+use Test::More tests => 2; > use Test::MockModule; > use Test::MockObject; > use Test::Warn; >@@ -92,7 +91,8 @@ sub mock_objects { > $schema->storage->txn_begin; > > subtest ImportBreedingAuth => sub { >- plan tests => 4; >+ plan tests => 6; >+ my $dbh = C4::Context->dbh; > > my $record = MARC::Record->new(); > $record->append_fields( >@@ -102,8 +102,29 @@ subtest ImportBreedingAuth => sub { > > my $breedingid = C4::Breeding::ImportBreedingAuth( $record, "kidclamp", "UTF-8", 'Jansson, Tove' ); > ok( $breedingid, "We got a breeding id back" ); >+ > my $breedingid_1 = C4::Breeding::ImportBreedingAuth( $record, "kidclamp", "UTF-8", 'Jansson, Tove' ); > is( $breedingid, $breedingid_1, "For the same record, we get the same id" ); >+ >+ # Bug 19220: In case of XSLT transformation, we make sure to have the new version of the record >+ $record->append_fields( >+ MARC::Field->new( '999', ' ', ' ', a => 'Added field' ), >+ ); >+ >+ $breedingid_1 = C4::Breeding::ImportBreedingAuth( $record, "kidclamp", "UTF-8", 'Jansson, Tove' ); >+ is( $breedingid, $breedingid_1, "For the same record, modified, we get the same id" ); >+ >+ my $sth = $dbh->prepare('SELECT * FROM import_records WHERE import_record_id = ?'); >+ $sth->execute($breedingid); >+ my $imported_records_record = $sth->fetchrow_hashref(); >+ my $imported_record = MARC::Record::new_from_xml( $imported_records_record->{marcxml} ); >+ is( >+ $imported_record->subfield( '999', 'a' ), $record->subfield( '999', 'a' ), >+ 'We also get the new the version of the record' >+ ); >+ >+ # End Bug 19220 >+ > $breedingid_1 = C4::Breeding::ImportBreedingAuth( $record, "marcelr", "UTF-8", 'Jansson, Tove' ); > is( $breedingid, $breedingid_1, "For the same record in a different file, we get a new id" ); > my $record_1 = MARC::Record->new(); >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 19220
:
114604
|
121897
|
121906
|
121907
|
172627
|
172628
|
173438
|
179440
|
180197
| 180232 |
180233