From 224b0931bd2917a5fc935bec4cc1497dc906c8af Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 1 Oct 2025 07:46:54 +0100 Subject: [PATCH] Bug 38195: Modernise Koha::Edifact::Transport to use Koha::Objects This patch updates Koha::Edifact::Transport to use the new Koha::EDI::Accounts and Koha::Edifact::Files object classes instead of raw DBIx::Class objects. Changes: - Replaced $schema->resultset('VendorEdiAccount')->find() with Koha::EDI::Accounts->find() - Replaced resultset('EdifactMessage')->find( { filename => $f, } ); with Koha::Edifact::Files->search( { filename => $f }); - Simplified file_transport retrieval by using the relationship method from Koha::EDI::Account->file_transport() - Removed conditional logic as the relationship method handles undef cases automatically Benefits: - Cleaner code using Koha object patterns - Automatic relationship handling via accessor methods - More maintainable and consistent with rest of codebase --- Koha/Edifact/Transport.pm | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Koha/Edifact/Transport.pm b/Koha/Edifact/Transport.pm index 7ebc00a37be..6084877bfc4 100644 --- a/Koha/Edifact/Transport.pm +++ b/Koha/Edifact/Transport.pm @@ -25,22 +25,19 @@ use Carp qw( carp ); use Encode qw( from_to ); use File::Slurp qw( read_file ); -use Koha::Database; use Koha::DateUtils qw( dt_from_string ); -use Koha::File::Transports; +use Koha::EDI::Accounts; +use Koha::Edifact::Files; sub new { my ( $class, $account_id ) = @_; - my $database = Koha::Database->new(); - my $schema = $database->schema(); - my $acct = $schema->resultset('VendorEdiAccount')->find($account_id); + my $acct = Koha::EDI::Accounts->find($account_id); - # Get the file transport if configured - my $file_transport = $acct->file_transport_id ? Koha::File::Transports->find( $acct->file_transport_id ) : undef; + # Cache the file transport if configured + my $file_transport = $acct->file_transport; my $self = { account => $acct, - schema => $schema, file_transport => $file_transport, working_dir => C4::Context::temporary_directory, #temporary work directory transfer_date => dt_from_string(), @@ -187,8 +184,8 @@ sub ingest { foreach my $f (@downloaded_files) { # Check file has not been downloaded already - my $existing_file = $self->{schema}->resultset('EdifactMessage')->find( { filename => $f, } ); - if ($existing_file) { + my $existing_files = Koha::Edifact::Files->search( { filename => $f } ); + if ( $existing_files->count ) { carp "skipping ingest of $f : filename exists"; next; } @@ -201,7 +198,7 @@ sub ingest { } from_to( $file_content, 'iso-8859-1', 'utf8' ); $msg_hash->{raw_msg} = $file_content; - $self->{schema}->resultset('EdifactMessage')->create($msg_hash); + Koha::Edifact::File->new($msg_hash)->store(); } return; } -- 2.51.0