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

(-)a/admin/marc_order_accounts.pl (+9 lines)
Lines 38-43 use Koha::MarcOrderAccount; Link Here
38
use Koha::MarcOrderAccounts;
38
use Koha::MarcOrderAccounts;
39
39
40
my $input = CGI->new;
40
my $input = CGI->new;
41
our $schema = Koha::Database->new()->schema();
41
42
42
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43
    {
44
    {
Lines 60-65 if ( $op eq 'acct_form' ) { Link Here
60
    my @matchers = C4::Matcher::GetMatcherList();
61
    my @matchers = C4::Matcher::GetMatcherList();
61
    $template->param( available_matchers => \@matchers );
62
    $template->param( available_matchers => \@matchers );
62
63
64
    # Get available file transports for selection
65
    my @file_transports = $schema->resultset('FileTransport')->search(
66
        {},
67
        { order_by => { -asc => 'name' } }
68
    );
69
    $template->param( file_transports => \@file_transports );
70
63
    show_account( $input, $template );
71
    show_account( $input, $template );
64
} elsif ( $op eq 'delete_acct' ) {
72
} elsif ( $op eq 'delete_acct' ) {
65
    show_account( $input, $template );
73
    show_account( $input, $template );
Lines 82-87 if ( $op eq 'acct_form' ) { Link Here
82
            match_field        => scalar $input->param('match_field'),
90
            match_field        => scalar $input->param('match_field'),
83
            match_value        => scalar $input->param('match_value'),
91
            match_value        => scalar $input->param('match_value'),
84
            basket_name_field  => scalar $input->param('basket_name_field'),
92
            basket_name_field  => scalar $input->param('basket_name_field'),
93
            file_transport_id  => scalar $input->param('file_transport_id') || undef,
85
        };
94
        };
86
95
87
        if ( scalar $input->param('id') ) {
96
        if ( scalar $input->param('id') ) {
(-)a/installer/data/mysql/atomicupdate/bug_41020.pl (+27 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_success say_info);
3
4
return {
5
    bug_number  => "41020",
6
    description => "Add file_transport_id to marc_order_accounts",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        # Do you stuffs here
12
        $dbh->do(
13
            q{
14
            ALTER TABLE `marc_order_accounts`
15
              ADD COLUMN `file_transport_id` int(11) DEFAULT NULL AFTER `basket_name_field`,
16
              ADD KEY `marc_order_accounts_file_transport_id` (`file_transport_id`),
17
              ADD CONSTRAINT `marc_order_accounts_ibfk_file_transport`
18
                FOREIGN KEY (`file_transport_id`)
19
                REFERENCES `file_transports` (`file_transport_id`)
20
                ON DELETE SET NULL
21
                ON UPDATE CASCADE;
22
        }
23
        );
24
25
        say $out "Added column 'marc_order_accounts.file_transport_id'";
26
    },
27
};
(-)a/installer/data/mysql/kohastructure.sql (-1 / +3 lines)
Lines 4633-4643 CREATE TABLE `marc_order_accounts` ( Link Here
4633
  `match_field` varchar(10) DEFAULT NULL COMMENT 'the field that a vendor account has been mapped to in a marc record',
4633
  `match_field` varchar(10) DEFAULT NULL COMMENT 'the field that a vendor account has been mapped to in a marc record',
4634
  `match_value` varchar(50) DEFAULT NULL COMMENT 'the value to be matched against the marc record',
4634
  `match_value` varchar(50) DEFAULT NULL COMMENT 'the value to be matched against the marc record',
4635
  `basket_name_field` varchar(10) DEFAULT NULL COMMENT 'the field that a vendor can use to include a basket name that will be used to create the basket for the file',
4635
  `basket_name_field` varchar(10) DEFAULT NULL COMMENT 'the field that a vendor can use to include a basket name that will be used to create the basket for the file',
4636
  `file_transport_id` int(11) DEFAULT NULL,
4636
  PRIMARY KEY (`id`),
4637
  PRIMARY KEY (`id`),
4637
  KEY `marc_ordering_account_ibfk_1` (`vendor_id`),
4638
  KEY `marc_ordering_account_ibfk_1` (`vendor_id`),
4638
  KEY `marc_ordering_account_ibfk_2` (`budget_id`),
4639
  KEY `marc_ordering_account_ibfk_2` (`budget_id`),
4639
  CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
4640
  CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
4640
  CONSTRAINT `marc_ordering_account_ibfk_2` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
4641
  CONSTRAINT `marc_ordering_account_ibfk_2` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE,
4642
  CONSTRAINT `marc_order_accounts_ibfk_file_transport` FOREIGN KEY (`file_transport_id`) REFERENCES `file_transports` (`file_transport_id`) ON DELETE SET NULL ON UPDATE CASCADE
4641
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4643
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4642
/*!40101 SET character_set_client = @saved_cs_client */;
4644
/*!40101 SET character_set_client = @saved_cs_client */;
4643
4645
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_order_accounts.tt (+14 lines)
Lines 116-121 Link Here
116
                        <label for="description">Description: </label>
116
                        <label for="description">Description: </label>
117
                        <input type="text" name="description" id="description" size="20" value="[% account.description | html %]" />
117
                        <input type="text" name="description" id="description" size="20" value="[% account.description | html %]" />
118
                    </li>
118
                    </li>
119
                    <li>
120
                        <label for="file_transport_id">File transport: </label>
121
                        <select name="file_transport_id" id="file_transport_id">
122
                            <option value="">Select a file transport configuration</option>
123
                            [% FOREACH transport IN file_transports %]
124
                                [% IF transport.file_transport_id == account.file_transport_id %]
125
                                    <option value="[% transport.file_transport_id | html %]" selected="selected">[% transport.name | html %] ([% transport.transport | upper | html %] - [% transport.host | html %])</option>
126
                                [% ELSE %]
127
                                    <option value="[% transport.file_transport_id | html %]">[% transport.name | html %] ([% transport.transport | upper | html %] - [% transport.host | html %])</option>
128
                                [% END %]
129
                            [% END %]
130
                        </select>
131
                        <div class="hint"> Select a file transport configuration for this EDI account. File transports can be managed in <a href="/cgi-bin/koha/admin/file_transports.pl">Administration &rsaquo; File transports</a>. </div>
132
                    </li>
119
                    <li>
133
                    <li>
120
                        <label for="download_directory">Download directory: </label>
134
                        <label for="download_directory">Download directory: </label>
121
                        <input type="text" name="download_directory" id="download_directory" size="20" value="[% account.download_directory | html %]" />
135
                        <input type="text" name="download_directory" id="download_directory" size="20" value="[% account.download_directory | html %]" />
(-)a/misc/cronjobs/marc_ordering_process.pl (-8 / +66 lines)
Lines 23-29 marc_ordering_process.pl - cron script to retrieve MARC files and create order l Link Here
23
23
24
=head1 SYNOPSIS
24
=head1 SYNOPSIS
25
25
26
./marc_ordering_process.pl [-c|--confirm] [-v|--verbose]
26
./marc_ordering_process.pl [-c|--confirm] [-v|--verbose] [--dr|--delete-remote] [--rr|--rename-remote] ext]
27
27
28
or, in crontab:
28
or, in crontab:
29
# Once every day
29
# Once every day
Lines 50-55 Without this parameter no changes will be made Link Here
50
50
51
Delete the file once it has been processed
51
Delete the file once it has been processed
52
52
53
=item B<--dr|--delete-remote>
54
55
Delete the remote file once it has been downloaded
56
57
=item B<-rr|--rename-remove ext>
58
59
Rename the remote file once it has been downloaded, adding the given file extension
60
53
=back
61
=back
54
62
55
=cut
63
=cut
Lines 62-79 use File::Copy qw( copy move ); Link Here
62
use Koha::Script -cron;
70
use Koha::Script -cron;
63
use Koha::MarcOrder;
71
use Koha::MarcOrder;
64
use Koha::MarcOrderAccounts;
72
use Koha::MarcOrderAccounts;
73
use Koha::File::Transports;
65
74
66
use C4::Log qw( cronlogaction );
75
use C4::Log qw( cronlogaction );
67
76
68
my $command_line_options = join( " ", @ARGV );
77
my $command_line_options = join( " ", @ARGV );
69
cronlogaction( { info => $command_line_options } );
78
cronlogaction( { info => $command_line_options } );
70
79
71
my ( $help, $verbose, $confirm, $delete );
80
my ( $help, $verbose, $confirm, $delete, $rename_ext, $delete_remote );
72
GetOptions(
81
GetOptions(
73
    'h|help'    => \$help,
82
    'h|help'             => \$help,
74
    'v|verbose' => \$verbose,
83
    'v|verbose'          => \$verbose,
75
    'c|confirm' => \$confirm,
84
    'c|confirm'          => \$confirm,
76
    'd|delete'  => \$delete,
85
    'd|delete'           => \$delete,
86
    'dr|delete-remote'   => \$delete_remote,
87
    'rr|rename-remote=s' => \$rename_ext,
77
) || pod2usage(1);
88
) || pod2usage(1);
78
89
79
pod2usage(0) if $help;
90
pod2usage(0) if $help;
Lines 91-96 if ( scalar(@accounts) == 0 ) { Link Here
91
    print "No accounts found - you must create a MARC order account for this cronjob to run\n" if $verbose;
102
    print "No accounts found - you must create a MARC order account for this cronjob to run\n" if $verbose;
92
}
103
}
93
104
105
my $valid_file_extensions = qr/\.(mrc|marcxml|mrk)$/i;
106
94
foreach my $acct (@accounts) {
107
foreach my $acct (@accounts) {
95
    if ($verbose) {
108
    if ($verbose) {
96
        say sprintf "Starting MARC ordering process for %s", $acct->vendor->name;
109
        say sprintf "Starting MARC ordering process for %s", $acct->vendor->name;
Lines 98-105 foreach my $acct (@accounts) { Link Here
98
    }
111
    }
99
112
100
    my $working_dir = $acct->download_directory;
113
    my $working_dir = $acct->download_directory;
114
115
    my $file_transport = $acct->file_transport_id ? Koha::File::Transports->find( $acct->file_transport_id ) : undef;
116
    if ($file_transport) {
117
        if ( $file_transport->connect() ) {
118
            my $download_dir = $file_transport->download_directory;
119
120
            my $success = $download_dir ? $file_transport->change_directory($download_dir) : 1;
121
            if ( $download_dir && !$success ) {
122
                say "Failed to change to download directory: $download_dir";
123
            } else {
124
125
                # Get file list
126
                my $file_list = $file_transport->list_files();
127
                if ($file_list) {
128
129
                    # Process files matching our criteria
130
                    foreach my $file ( @{$file_list} ) {
131
                        my $filename = $file->{filename};
132
133
                        if ( $filename =~ $valid_file_extensions ) {
134
135
                            my $local_file = "$working_dir/$filename";
136
137
                            # Download the file
138
                            if ( $file_transport->download_file( $filename, $local_file ) ) {
139
                                if ($rename_ext) {
140
                                    $file_transport->rename_file( $filename, "$filename.$rename_ext" );
141
                                } elsif ($delete_remote) {
142
                                    $file_transport->delete_file($filename);
143
                                }
144
                            } else {
145
                                say "Failed to download file: $filename";
146
                            }
147
                        }
148
                    }
149
150
                } else {
151
                    say "Failed to get file list from transport";
152
                }
153
154
            }
155
        } else {
156
            say "Failed to connect to file transport: " . $file_transport->id;
157
        }
158
    }
159
101
    opendir my $dir, $working_dir or die "Can't open filepath";
160
    opendir my $dir, $working_dir or die "Can't open filepath";
102
    my @files = grep { /\.(mrc|marcxml|mrk)/i } readdir $dir;
161
    my @files = grep { /$valid_file_extensions/ } readdir $dir;
103
    closedir $dir;
162
    closedir $dir;
104
    print "No new files found\n" if scalar(@files) == 0;
163
    print "No new files found\n" if scalar(@files) == 0;
105
164
106
- 

Return to bug 41020