View | Details | Raw Unified | Return to bug 38195
Collapse All | Expand All

(-)a/Koha/Edifact/Transport.pm (-12 / +8 lines)
Lines 25-46 use Carp qw( carp ); Link Here
25
use Encode      qw( from_to );
25
use Encode      qw( from_to );
26
use File::Slurp qw( read_file );
26
use File::Slurp qw( read_file );
27
27
28
use Koha::Database;
29
use Koha::DateUtils qw( dt_from_string );
28
use Koha::DateUtils qw( dt_from_string );
30
use Koha::File::Transports;
29
use Koha::EDI::Accounts;
30
use Koha::Edifact::Files;
31
31
32
sub new {
32
sub new {
33
    my ( $class, $account_id ) = @_;
33
    my ( $class, $account_id ) = @_;
34
    my $database = Koha::Database->new();
34
    my $acct = Koha::EDI::Accounts->find($account_id);
35
    my $schema   = $database->schema();
36
    my $acct     = $schema->resultset('VendorEdiAccount')->find($account_id);
37
35
38
    # Get the file transport if configured
36
    # Cache the file transport if configured
39
    my $file_transport = $acct->file_transport_id ? Koha::File::Transports->find( $acct->file_transport_id ) : undef;
37
    my $file_transport = $acct->file_transport;
40
38
41
    my $self = {
39
    my $self = {
42
        account        => $acct,
40
        account        => $acct,
43
        schema         => $schema,
44
        file_transport => $file_transport,
41
        file_transport => $file_transport,
45
        working_dir    => C4::Context::temporary_directory,    #temporary work directory
42
        working_dir    => C4::Context::temporary_directory,    #temporary work directory
46
        transfer_date  => dt_from_string(),
43
        transfer_date  => dt_from_string(),
Lines 187-194 sub ingest { Link Here
187
    foreach my $f (@downloaded_files) {
184
    foreach my $f (@downloaded_files) {
188
185
189
        # Check file has not been downloaded already
186
        # Check file has not been downloaded already
190
        my $existing_file = $self->{schema}->resultset('EdifactMessage')->find( { filename => $f, } );
187
        my $existing_files = Koha::Edifact::Files->search( { filename => $f } );
191
        if ($existing_file) {
188
        if ( $existing_files->count ) {
192
            carp "skipping ingest of $f : filename exists";
189
            carp "skipping ingest of $f : filename exists";
193
            next;
190
            next;
194
        }
191
        }
Lines 201-207 sub ingest { Link Here
201
        }
198
        }
202
        from_to( $file_content, 'iso-8859-1', 'utf8' );
199
        from_to( $file_content, 'iso-8859-1', 'utf8' );
203
        $msg_hash->{raw_msg} = $file_content;
200
        $msg_hash->{raw_msg} = $file_content;
204
        $self->{schema}->resultset('EdifactMessage')->create($msg_hash);
201
        Koha::Edifact::File->new($msg_hash)->store();
205
    }
202
    }
206
    return;
203
    return;
207
}
204
}
208
- 

Return to bug 38195