From 0245db45bd3495dd256d949f4d9338877b0c8fa4 Mon Sep 17 00:00:00 2001
From: Matthias Meusburger <matthias.meusburger@biblibre.com>
Date: Tue, 1 Apr 2025 12:44:05 +0000
Subject: [PATCH] Bug 19220, QA Follow-up: Allow XSLT processing for Z39.50
 authority targets

 - Add comment about clearing cache
 - Use Koha::Import::Record instead of SQL queries in both tests and code
---
 C4/Breeding.pm                 |  8 +++++---
 t/db_dependent/Breeding_Auth.t | 10 ++++------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/C4/Breeding.pm b/C4/Breeding.pm
index 5917dfc9c2d..938a7376573 100644
--- a/C4/Breeding.pm
+++ b/C4/Breeding.pm
@@ -509,10 +509,12 @@ sub ImportBreedingAuth {
     $searchbreeding->execute( $controlnumber, $heading );
     my ($breedingid) = $searchbreeding->fetchrow;
 
+    # This clears the cache, to make sure the record is up-to-date with the XSLT transformation
     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();
+        my $import_record = Koha::Import::Records->find($breedingid);
+        $import_record->marc( $marcrecord->as_usmarc() );
+        $import_record->marcxml( $marcrecord->as_xml($marc_type) );
+        $import_record->store();
         return $breedingid;
     }
     $breedingid = AddAuthToBatch( $batch_id, 0, $marcrecord, $encoding );
diff --git a/t/db_dependent/Breeding_Auth.t b/t/db_dependent/Breeding_Auth.t
index 428ca97e5de..bfcd1285ab8 100755
--- a/t/db_dependent/Breeding_Auth.t
+++ b/t/db_dependent/Breeding_Auth.t
@@ -114,13 +114,11 @@ subtest ImportBreedingAuth => sub {
     $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} );
+    my $imported_record     = Koha::Import::Records->find($breedingid);
+    my $imported_marcrecord = $imported_record->get_marc_record();
     is(
-        $imported_record->subfield( '999', 'a' ), $record->subfield( '999', 'a' ),
-        'We also get the new the version of the record'
+        $imported_marcrecord->subfield( '999', 'a' ), $record->subfield( '999', 'a' ),
+        'We also get the new version of the record'
     );
 
     # End Bug 19220
-- 
2.39.5