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

(-)a/misc/stage_file.pl (-5 / +41 lines)
Lines 19-26 Link Here
19
# with this program; if not, write to the Free Software Foundation, Inc.,
19
# with this program; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
21
22
use strict;
22
use Modern::Perl;
23
use warnings;
24
BEGIN {
23
BEGIN {
25
    # find Koha's Perl modules
24
    # find Koha's Perl modules
26
    # test carefully before changing this
25
    # test carefully before changing this
Lines 31-36 BEGIN { Link Here
31
use C4::Context;
30
use C4::Context;
32
use C4::ImportBatch;
31
use C4::ImportBatch;
33
use C4::Matcher;
32
use C4::Matcher;
33
use C4::MarcModificationTemplates;
34
use Getopt::Long;
34
use Getopt::Long;
35
35
36
$| = 1;
36
$| = 1;
Lines 48-53 my $no_replace; Link Here
48
my $format = 'ISO2709';
48
my $format = 'ISO2709';
49
my $no_create;
49
my $no_create;
50
my $item_action = 'always_add';
50
my $item_action = 'always_add';
51
my $marc_mod_template = '';
52
my $marc_mod_template_id = undef;
51
53
52
my $result = GetOptions(
54
my $result = GetOptions(
53
    'encoding:s'    => \$encoding,
55
    'encoding:s'    => \$encoding,
Lines 60-68 my $result = GetOptions( Link Here
60
    'no-create'     => \$no_create,
62
    'no-create'     => \$no_create,
61
    'comment:s'     => \$batch_comment,
63
    'comment:s'     => \$batch_comment,
62
    'authorities'   => \$authorities,
64
    'authorities'   => \$authorities,
65
    'marcmodtemplate:s' => \$marc_mod_template,
63
    'h|help'        => \$want_help
66
    'h|help'        => \$want_help
64
);
67
);
65
68
69
if($marc_mod_template ne '') {
70
   my @templates = GetModificationTemplates();
71
   foreach my $this_template (@templates) {
72
       if($this_template->{'name'} eq $marc_mod_template) {
73
          if(!defined $marc_mod_template_id) {
74
               $marc_mod_template_id = $this_template->{'template_id'};
75
           } else {
76
               print "WARNING: MARC modification template name " .
77
                   "'$marc_mod_template' matches multiple templates. " .
78
                   "Please fix this issue before proceeding.\n";
79
               exit 1;
80
           }
81
       }
82
   }
83
84
   if(!defined $marc_mod_template_id ) {
85
       die "Can't locate MARC modification template '$marc_mod_template'\n";
86
   }
87
}
88
66
$record_type = 'auth' if ($authorities);
89
$record_type = 'auth' if ($authorities);
67
90
68
if (not $result or $input_file eq "" or $want_help) {
91
if (not $result or $input_file eq "" or $want_help) {
Lines 92-97 process_batch({ Link Here
92
    no_replace    => $no_replace,
115
    no_replace    => $no_replace,
93
    no_create     => $no_create,
116
    no_create     => $no_create,
94
    item_action   => $item_action,
117
    item_action   => $item_action,
118
    marc_mod_template_id => $marc_mod_template_id,
95
});
119
});
96
$dbh->commit();
120
$dbh->commit();
97
121
Lines 116-123 sub process_batch { Link Here
116
    print "... staging MARC records -- please wait\n";
140
    print "... staging MARC records -- please wait\n";
117
    #FIXME: We should really allow the use of marc modification frameworks and to_marc plugins here if possible
141
    #FIXME: We should really allow the use of marc modification frameworks and to_marc plugins here if possible
118
    my ($batch_id, $num_valid_records, $num_items, @import_errors) =
142
    my ($batch_id, $num_valid_records, $num_items, @import_errors) =
119
        BatchStageMarcRecords($record_type, $params->{encoding}, $marc_records, $params->{input_file}, undef, $params->{batch_comment}, '', $params->{add_items}, 0,
143
        BatchStageMarcRecords(
120
                              100, \&print_progress_and_commit);
144
            $record_type, $params->{encoding},
145
            $marc_records, $params->{input_file},
146
            $params->{'marc_mod_template_id'},
147
            $params->{batch_comment}, '',
148
            $params->{add_items}, 0,
149
            100, \&print_progress_and_commit);
121
    print "... finished staging MARC records\n";
150
    print "... finished staging MARC records\n";
122
151
123
    my $num_with_matches = 0;
152
    my $num_with_matches = 0;
Lines 218-223 Parameters: Link Here
218
                            the record batch; if the comment
247
                            the record batch; if the comment
219
                            has spaces in it, surround the
248
                            has spaces in it, surround the
220
                            comment with quotation marks.
249
                            comment with quotation marks.
250
    --marcmodtemplate <TEMPLATE>
251
                            This parameter allows you to specify the
252
                            name of an existing MARC modification
253
                            template to apply as the MARC records are
254
                            imported (these templates are created in
255
                            the "MARC modification templates" tool in
256
                            Koha). If not specified, no MARC modification
257
                            templates are used (default).
221
    --help or -h            show this message.
258
    --help or -h            show this message.
222
_USAGE_
259
_USAGE_
223
}
260
}
224
- 

Return to bug 19164