From dbab9bcca1da98cbc027f5310bf4621224b12089 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 21 Apr 2021 07:56:50 +0200 Subject: [PATCH] Bug 28186: Use Koha::Authority in C4::AuthoritiesMarc::AddAuthority This patch replaces the use of $dbh->do by corresponding use of Koha::Authority object Test plan: 1. Verify that creating/modifying authority still work 2. prove t/db_dependent/AuthoritiesMarc.t --- C4/AuthoritiesMarc.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 1bb808bb9c..a9d46a4470 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -623,17 +623,22 @@ sub AddAuthority { } # Save record into auth_header, update 001 + my $authority; if (!$authid ) { # Save a blank record, get authid - $dbh->do( "INSERT INTO auth_header (datecreated,marcxml) values (NOW(),?)", undef, '' ); - $authid = $dbh->last_insert_id( undef, undef, 'auth_header', 'authid' ); + $authority = Koha::Authority->new({ datecreated => \'NOW()', marcxml => '' })->store(); + $authority->discard_changes(); + $authid = $authority->authid; logaction( "AUTHORITIES", "ADD", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); + } else { + $authority = Koha::Authorities->find($authid); } + # Insert/update the recordID in MARC record $record->delete_field( $record->field('001') ); $record->insert_fields_ordered( MARC::Field->new( '001', $authid ) ); # Update - $dbh->do( "UPDATE auth_header SET authtypecode=?, marc=?, marcxml=? WHERE authid=?", undef, $authtypecode, $record->as_usmarc, $record->as_xml_record($format), $authid ) or die $DBI::errstr; + $authority->update({ authtypecode => $authtypecode, marc => $record->as_usmarc, marcxml => $record->as_xml_record($format) }); my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); $indexer->index_records( $authid, "specialUpdate", "authorityserver", $record ); -- 2.20.1