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

(-)a/misc/stage_file.pl (-5 / +47 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 strict;
23
use warnings;
23
#use warnings;
24
use Modern::Perl;
24
BEGIN {
25
BEGIN {
25
    # find Koha's Perl modules
26
    # find Koha's Perl modules
26
    # test carefully before changing this
27
    # test carefully before changing this
Lines 31-36 BEGIN { Link Here
31
use C4::Context;
32
use C4::Context;
32
use C4::ImportBatch;
33
use C4::ImportBatch;
33
use C4::Matcher;
34
use C4::Matcher;
35
use C4::MarcModificationTemplates;
34
use Getopt::Long;
36
use Getopt::Long;
35
37
36
$| = 1;
38
$| = 1;
Lines 48-53 my $no_replace; Link Here
48
my $format = 'ISO2709';
50
my $format = 'ISO2709';
49
my $no_create;
51
my $no_create;
50
my $item_action = 'always_add';
52
my $item_action = 'always_add';
53
my $marc_mod_template = '';
54
my $marc_mod_template_id = undef;
51
55
52
my $result = GetOptions(
56
my $result = GetOptions(
53
    'encoding:s'    => \$encoding,
57
    'encoding:s'    => \$encoding,
Lines 60-68 my $result = GetOptions( Link Here
60
    'no-create'     => \$no_create,
64
    'no-create'     => \$no_create,
61
    'comment:s'     => \$batch_comment,
65
    'comment:s'     => \$batch_comment,
62
    'authorities'   => \$authorities,
66
    'authorities'   => \$authorities,
67
    'marcmodtemplate:s' => \$marc_mod_template,
63
    'h|help'        => \$want_help
68
    'h|help'        => \$want_help
64
);
69
);
65
70
71
if($marc_mod_template ne '') {
72
   my @templates = GetModificationTemplates();
73
   foreach my $this_template (@templates) {
74
       if($this_template->{'name'} eq $marc_mod_template) {
75
	   $marc_mod_template_id = $this_template->{'template_id'};
76
	   last;
77
       }
78
       if($this_template->{'name'} eq $marc_mod_template) {
79
	   if($marc_mod_template_id < 0) {
80
	       $marc_mod_template_id = $this_template->{'template_id'};
81
	   } else {
82
	       print "WARNING: MARC modification template name " .
83
		   "'$marc_mod_template' matches multiple templates. " .
84
		   "Please fix this issue before proceeding.\n";
85
	       exit 1;
86
	   }
87
       }
88
   }
89
   
90
   if($marc_mod_template_id < 0) {
91
       die "Can't locate MARC modification template '$marc_mod_template'\n";
92
   }
93
}
94
66
$record_type = 'auth' if ($authorities);
95
$record_type = 'auth' if ($authorities);
67
96
68
if (not $result or $input_file eq "" or $want_help) {
97
if (not $result or $input_file eq "" or $want_help) {
Lines 92-97 process_batch({ Link Here
92
    no_replace    => $no_replace,
121
    no_replace    => $no_replace,
93
    no_create     => $no_create,
122
    no_create     => $no_create,
94
    item_action   => $item_action,
123
    item_action   => $item_action,
124
    marc_mod_template_id => $marc_mod_template_id,
95
});
125
});
96
$dbh->commit();
126
$dbh->commit();
97
127
Lines 116-123 sub process_batch { Link Here
116
    print "... staging MARC records -- please wait\n";
146
    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
147
    #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) =
148
    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,
149
        BatchStageMarcRecords(
120
                              100, \&print_progress_and_commit);
150
	    $record_type, $params->{encoding}, 
151
	    $marc_records, $params->{input_file}, 
152
	    $params->{'marc_mod_template_id'}, 
153
	    $params->{batch_comment}, '', 
154
	    $params->{add_items}, 0,
155
	    100, \&print_progress_and_commit);
121
    print "... finished staging MARC records\n";
156
    print "... finished staging MARC records\n";
122
157
123
    my $num_with_matches = 0;
158
    my $num_with_matches = 0;
Lines 218-223 Parameters: Link Here
218
                            the record batch; if the comment
253
                            the record batch; if the comment
219
                            has spaces in it, surround the
254
                            has spaces in it, surround the
220
                            comment with quotation marks.
255
                            comment with quotation marks.
256
    --marcmodtemplate <TEMPLATE>
257
                            This parameter allows you to specify the
258
                            name of an existing MARC modification
259
                            template to apply as the MARC records are
260
                            imported (these templates are created in
261
                            the "MARC modification templates" tool in
262
                            Koha). If not specified, no MARC modification
263
                            templates are used (default).
221
    --help or -h            show this message.
264
    --help or -h            show this message.
222
_USAGE_
265
_USAGE_
223
}
266
}
224
- 

Return to bug 19164