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

(-)a/misc/stage_file.pl (-15 / +32 lines)
Lines 81-112 unless (-r $input_file) { Link Here
81
81
82
my $dbh = C4::Context->dbh;
82
my $dbh = C4::Context->dbh;
83
$dbh->{AutoCommit} = 0;
83
$dbh->{AutoCommit} = 0;
84
process_batch($format, $input_file, $record_type, $match, $add_items, $batch_comment);
84
process_batch({
85
    format        => $format,
86
    input_file    => $input_file,
87
    record_type   => $record_type,
88
    match         => $match,
89
    add_items     => $add_items,
90
    batch_comment => $batch_comment,
91
    encoding      => $encoding,
92
    no_replace    => $no_replace,
93
    no_create     => $no_create,
94
    item_action   => $item_action,
95
});
85
$dbh->commit();
96
$dbh->commit();
86
97
87
exit 0;
98
exit 0;
88
99
89
sub process_batch {
100
sub process_batch {
90
    my ($format, $input_file, $record_type, $match, $add_items, $batch_comment) = @_;
101
    my ( $params ) = @_;  #Possible params are: format input_file record_type match add_items batch_comment encoding no_replace no_create item_action
102
    my $format = $params->{format} // '';
103
    my $record_type = $params->{record_type} // 'biblio';
91
104
92
    my ( $errors, $marc_records );
105
    my ( $errors, $marc_records );
93
    ( $errors, $marc_records ) = C4::ImportBatch::RecordsFromISO2709File($input_file, $record_type, $encoding) if $format eq 'ISO2709';
106
    if( $format eq 'ISO2709' ) {
94
    ( $errors, $marc_records ) = C4::ImportBatch::RecordsFromMARCXMLFile($input_file, $encoding) if $format eq 'MARCXML';
107
        ( $errors, $marc_records ) = C4::ImportBatch::RecordsFromISO2709File(
108
            $params->{input_file}, $record_type, $params->{encoding} );
109
    } elsif( $format eq 'MARCXML' ) {
110
        ( $errors, $marc_records ) = C4::ImportBatch::RecordsFromMARCXMLFile(
111
            $params->{input_file}, $params->{encoding} );
112
    }
95
    warn ( join ',', @$errors ) if @$errors;
113
    warn ( join ',', @$errors ) if @$errors;
96
    my $num_input_records = ($marc_records) ? scalar(@$marc_records) : 0;
114
    my $num_input_records = ($marc_records) ? scalar(@$marc_records) : 0;
97
115
98
    print "... staging MARC records -- please wait\n";
116
    print "... staging MARC records -- please wait\n";
99
    #FIXME: We should really allow the use of marc modification frameworks and to_marc plugins here if possible
117
    #FIXME: We should really allow the use of marc modification frameworks and to_marc plugins here if possible
100
    my ($batch_id, $num_valid_records, $num_items, @import_errors) =
118
    my ($batch_id, $num_valid_records, $num_items, @import_errors) =
101
        BatchStageMarcRecords($record_type, $encoding, $marc_records, $input_file, undef, undef, $batch_comment, '', $add_items, 0,
119
        BatchStageMarcRecords($record_type, $params->{encoding}, $marc_records, $params->{input_file}, undef, undef, $params->{batch_comment}, '', $params->{add_items}, 0,
102
                              100, \&print_progress_and_commit);
120
                              100, \&print_progress_and_commit);
103
    print "... finished staging MARC records\n";
121
    print "... finished staging MARC records\n";
104
122
105
    my $num_with_matches = 0;
123
    my $num_with_matches = 0;
106
    if ($match) {
124
    if ( $params->{match} ) {
107
        my $matcher = C4::Matcher->fetch($match) ;
125
        my $matcher = C4::Matcher->fetch( $params->{match} );
108
        if (defined $matcher) {
126
        if (defined $matcher) {
109
            SetImportBatchMatcher($batch_id, $match);
127
            SetImportBatchMatcher( $batch_id, $params->{match} );
110
        } elsif ($record_type eq 'biblio')  {
128
        } elsif ($record_type eq 'biblio')  {
111
            $matcher = C4::Matcher->new($record_type);
129
            $matcher = C4::Matcher->new($record_type);
112
            $matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, '');
130
            $matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, '');
Lines 114-122 sub process_batch { Link Here
114
                                            '245', 'a', -1, 0, '');
132
                                            '245', 'a', -1, 0, '');
115
        }
133
        }
116
        # set default record overlay behavior
134
        # set default record overlay behavior
117
        SetImportBatchOverlayAction($batch_id, ($no_replace) ? 'ignore' : 'replace');
135
        SetImportBatchOverlayAction( $batch_id, $params->{no_replace} ? 'ignore' : 'replace' );
118
        SetImportBatchNoMatchAction($batch_id, ($no_create) ? 'ignore' : 'create_new');
136
        SetImportBatchNoMatchAction( $batch_id, $params->{no_create} ? 'ignore' : 'create_new' );
119
        SetImportBatchItemAction($batch_id, $item_action);
137
        SetImportBatchItemAction( $batch_id, $params->{item_action} );
120
        print "... looking for matches with records already in database\n";
138
        print "... looking for matches with records already in database\n";
121
        $num_with_matches = BatchFindDuplicates($batch_id, $matcher, 10, 100, \&print_progress_and_commit);
139
        $num_with_matches = BatchFindDuplicates($batch_id, $matcher, 10, 100, \&print_progress_and_commit);
122
        print "... finished looking for matches\n";
140
        print "... finished looking for matches\n";
Lines 127-145 sub process_batch { Link Here
127
145
128
MARC record staging report
146
MARC record staging report
129
------------------------------------
147
------------------------------------
130
Input file:                 $input_file
148
Input file:                 $params->{input_file}
131
Record type:                $record_type
149
Record type:                $record_type
132
Number of input records:    $num_input_records
150
Number of input records:    $num_input_records
133
Number of valid records:    $num_valid_records
151
Number of valid records:    $num_valid_records
134
Number of invalid records:  $num_invalid_records
152
Number of invalid records:  $num_invalid_records
135
_SUMMARY_
153
_SUMMARY_
136
    if ($match) {
154
    if( $params->{match} ) {
137
        print "Number of records matched:  $num_with_matches\n";
155
        print "Number of records matched:  $num_with_matches\n";
138
    } else {
156
    } else {
139
        print "Incoming records not matched against existing records (--match option not supplied)\n";
157
        print "Incoming records not matched against existing records (--match option not supplied)\n";
140
    }
158
    }
141
    if ($record_type eq 'biblio') {
159
    if ($record_type eq 'biblio') {
142
        if ($add_items) {
160
        if ( $params->{add_items} ) {
143
            print "Number of items parsed:  $num_items\n";
161
            print "Number of items parsed:  $num_items\n";
144
        } else {
162
        } else {
145
            print "No items parsed (--add-items option not supplied)\n";
163
            print "No items parsed (--add-items option not supplied)\n";
146
- 

Return to bug 10407