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

(-)a/C4/ImportBatch.pm (-1 / +112 lines)
Lines 77-82 BEGIN { Link Here
77
    SetImportRecordStatus
77
    SetImportRecordStatus
78
    GetImportRecordMatches
78
    GetImportRecordMatches
79
    SetImportRecordMatches
79
    SetImportRecordMatches
80
    GetImportMarcAction
81
    SetImportMarcAction
80
	);
82
	);
81
}
83
}
82
84
Lines 206-212 sub AddImportBatch { Link Here
206
    my (@fields, @vals);
208
    my (@fields, @vals);
207
    foreach (qw( matcher_id template_id branchcode
209
    foreach (qw( matcher_id template_id branchcode
208
                 overlay_action nomatch_action item_action
210
                 overlay_action nomatch_action item_action
209
                 import_status batch_type file_name comments record_type )) {
211
                 import_status batch_type file_name comments record_type marctag )) {
212
210
        if (exists $params->{$_}) {
213
        if (exists $params->{$_}) {
211
            push @fields, $_;
214
            push @fields, $_;
212
            push @vals, $params->{$_};
215
            push @vals, $params->{$_};
Lines 220-225 sub AddImportBatch { Link Here
220
    return $dbh->{'mysql_insertid'};
223
    return $dbh->{'mysql_insertid'};
221
}
224
}
222
225
226
=head2 GetImportMarcAction
227
228
  my $marctag = GetImportMarcAction($batch_id);
229
230
=cut
231
232
sub GetImportMarcAction {
233
    my ($batch_id) = @_;
234
    my $dbh = C4::Context->dbh;
235
    my $sth = $dbh->prepare("SELECT * FROM import_batches WHERE import_batch_id = ?");
236
    $sth->execute($batch_id);
237
    return $sth->fetchrow_hashref;
238
}
239
240
=head2 SetImportMarcAction
241
242
  SetImportMarcAction($batch_id, $marctag);
243
244
=cut
245
246
sub SetImportMarcAction {
247
    my ($batch_id, $marctag) = @_;
248
    my $dbh = C4::Context->dbh;
249
    my $sth = $dbh->prepare("UPDATE import_batches SET marctag = ? WHERE import_batch_id = ?");
250
    $sth->execute($marctag, $batch_id);
251
    return;
252
}
253
223
=head2 GetImportBatch 
254
=head2 GetImportBatch 
224
255
225
  my $row = GetImportBatch($batch_id);
256
  my $row = GetImportBatch($batch_id);
Lines 334-339 sub BatchStageMarcRecords { Link Here
334
    my $branch_code = shift;
365
    my $branch_code = shift;
335
    my $parse_items = shift;
366
    my $parse_items = shift;
336
    my $leave_as_staging = shift;
367
    my $leave_as_staging = shift;
368
    my $marctag = shift;
337
369
338
    # optional callback to monitor status 
370
    # optional callback to monitor status 
339
    # of job
371
    # of job
Lines 353-358 sub BatchStageMarcRecords { Link Here
353
            file_name => $file_name,
385
            file_name => $file_name,
354
            comments => $comments,
386
            comments => $comments,
355
            record_type => $record_type,
387
            record_type => $record_type,
388
            marctag => $marctag,
356
        } );
389
        } );
357
    if ($parse_items) {
390
    if ($parse_items) {
358
        SetImportBatchItemAction($batch_id, 'always_add');
391
        SetImportBatchItemAction($batch_id, 'always_add');
Lines 617-622 sub BatchCommitRecords { Link Here
617
            $sth->execute($recordid, $rowref->{'import_record_id'});
650
            $sth->execute($recordid, $rowref->{'import_record_id'});
618
            $sth->finish();
651
            $sth->finish();
619
            SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
652
            SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
653
        } elsif ($record_result eq 'appendmarctag') {
654
            $num_updated++;
655
            $recordid = $record_match;
656
            my $tag = GetImportMarcAction($batch_id);
657
            my $marctag = $tag->{'marctag'};
658
            my $mtag = substr($marctag,0,3);
659
            my $sub = substr($marctag,3);
660
            my $oldxml;
661
            if ($record_type eq 'biblio') {
662
                my ($count, $oldbiblio) = GetBiblio($recordid);
663
                $oldxml = GetXmlBiblio($recordid);
664
                my $old_marc = MARC::Record->new_from_xml(StripNonXmlChars($oldxml), 'UTF-8', $rowref->{'encoding'}, $marc_type);
665
                foreach my $item_field ($old_marc->field($item_tag)) {
666
                    $old_marc->delete_field($item_field);
667
                }
668
                $oldxml = $old_marc->as_xml($marc_type);
669
670
                my $sth=$dbh->prepare("SELECT * FROM marc_tag_structure WHERE tagfield=? AND frameworkcode=?");
671
                if ($oldbiblio->{'frameworkcode'} eq '') {
672
                    $sth->execute($mtag,'');
673
                } else {
674
                    $sth->execute($mtag,$oldbiblio->{'frameworkcode'});
675
                }
676
                my $data=$sth->fetchrow_hashref;
677
678
                if ($data->{'repeatable'} == 0) {
679
                    my $new_marc = $old_marc->field($mtag);
680
                    my $newvalue = $marc_record->field($mtag)->subfield($sub);
681
                    my $oldvalue = $old_marc->field($mtag)->subfield($sub);
682
                    ##checking value if value is not duplicate update the marc tag.
683
                    if ($oldvalue ne $newvalue) {
684
                        $new_marc->delete_subfield(code => $sub);
685
                        my $new_field = $marc_record->field($mtag);
686
                        $new_field->update( $sub => $newvalue );
687
                        $old_marc->insert_fields_ordered($new_field);
688
                    }
689
                } elsif($data->{'repeatable'} == 1 ) {
690
                   my @value;
691
                   my $i =0;
692
                   my @oldvalue;
693
                   my $j=0;
694
                   foreach my $field_marc ($marc_record->field($mtag)) {
695
                       @value[$i] = $field_marc->subfield($sub);
696
                       $i = $i + 1;
697
                   }
698
                   foreach my $oldm ($old_marc->field($mtag)) {
699
                       @oldvalue[$j] = $oldm->subfield($sub);
700
                       $j = $j + 1;
701
                   }
702
                   for my $index (0 .. $#value) {
703
                       #checking for duplicate values
704
                       if ($value[$index] ne $oldvalue[$index]) {
705
                           my $new = MARC::Field->new($mtag,'','',$sub => $value[$index]);
706
                           $old_marc->insert_fields_ordered($new);
707
                       }
708
                   }
709
                }
710
                ModBiblio($old_marc, $recordid, $oldbiblio->{'frameworkcode'});
711
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
712
713
                if ($item_result eq 'create_new') {
714
                    my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid);
715
                    $num_items_added = $bib_items_added;
716
                    $num_items_errored = $bib_items_errored;
717
                }
718
            } else {
719
                $oldxml = GetAuthorityXML($recordid);
720
                ModAuthority($recordid, $marc_record, GuessAuthTypeCode($marc_record));
721
                $query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?";
722
            }
723
            my $sth = $dbh->prepare("UPDATE import_records SET marcxml_old = ? WHERE import_record_id = ?");
724
            $sth->execute($oldxml, $rowref->{'import_record_id'});
725
            $sth = $dbh->prepare($query);
726
            $sth->execute($recordid, $rowref->{'import_record_id'});
727
            SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
728
            SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
620
        } elsif ($record_result eq 'replace') {
729
        } elsif ($record_result eq 'replace') {
621
            $num_updated++;
730
            $num_updated++;
622
            $recordid = $record_match;
731
            $recordid = $record_match;
Lines 1504-1509 sub _get_commit_action { Link Here
1504
                $bib_result  = 'create_new';
1613
                $bib_result  = 'create_new';
1505
            } elsif ($overlay_action eq 'ignore') {
1614
            } elsif ($overlay_action eq 'ignore') {
1506
                $bib_result  = 'ignore';
1615
                $bib_result  = 'ignore';
1616
            } elsif ($overlay_action eq 'appendmarctag') {
1617
                $bib_result  = 'appendmarctag';
1507
            }
1618
            }
1508
         if($item_action eq 'always_add' or $item_action eq 'add_only_for_matches'){
1619
         if($item_action eq 'always_add' or $item_action eq 'add_only_for_matches'){
1509
                $item_result = 'create_new';
1620
                $item_result = 'create_new';
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-overlay-action.inc (-1 / +20 lines)
Lines 1-4 Link Here
1
          <select name="overlay_action" id="overlay_action">
1
<script type="text/javascript">
2
    function toggle() {
3
        var a = document.getElementById('overlay_action').value;
4
        if (a == 'appendmarctag') {
5
            document.getElementById('marctag').style.visibility = 'visible';
6
            document.getElementById('marctag').style.display = 'block';
7
        } else {
8
            document.getElementById('marctag').style.visibility = 'hidden';
9
            document.getElementById('marctag').style.display = 'none';
10
        }
11
    }
12
</script>
13
          <select name="overlay_action" id="overlay_action" onchange="toggle()">
2
            [% IF ( overlay_action_replace ) %]
14
            [% IF ( overlay_action_replace ) %]
3
                <option value="replace"  selected="selected">
15
                <option value="replace"  selected="selected">
4
            [% ELSE %]
16
            [% ELSE %]
Lines 17-20 Link Here
17
                <option value="ignore">
29
                <option value="ignore">
18
            [% END %]
30
            [% END %]
19
                Ignore incoming record (its items may still be processed)</option>
31
                Ignore incoming record (its items may still be processed)</option>
32
            [% IF ( overlay_action_appendmarctag ) %]
33
                <option value="appendmarctag" selected="selected">
34
            [% ELSE %]
35
                <option value="appendmarctag">
36
            [% END %]
37
                Append or update MARC21/UNIMARC tag(Enter like 100a, 700a)</option>
20
        </select>
38
        </select>
39
        <input type="textbox" id="marctag" name ="marctag" maxlength = "4" size = "4" style="display:none;visible:false"/>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (+1 lines)
Lines 214-219 $(document).ready(function(){ Link Here
214
            [% END %]
214
            [% END %]
215
        [% END %]
215
        [% END %]
216
    </li>
216
    </li>
217
    [% IF ( marctag ) %]<li><span class="label">MarcTag:</span>[% marctag %]</li>[% END %]
217
    
218
    
218
    <li>
219
    <li>
219
        [% IF ( can_commit ) %]
220
        [% IF ( can_commit ) %]
(-)a/tools/manage-marc-import.pl (-2 / +10 lines)
Lines 128-136 if ($op eq "") { Link Here
128
    my $current_matcher_id = $input->param('current_matcher_id');
128
    my $current_matcher_id = $input->param('current_matcher_id');
129
    my $overlay_action = $input->param('overlay_action');
129
    my $overlay_action = $input->param('overlay_action');
130
    my $nomatch_action = $input->param('nomatch_action');
130
    my $nomatch_action = $input->param('nomatch_action');
131
    my $marctag = $input->param('marctag');
131
    my $item_action = $input->param('item_action');
132
    my $item_action = $input->param('item_action');
132
    redo_matching($template, $import_batch_id, $new_matcher_id, $current_matcher_id, 
133
    redo_matching($template, $import_batch_id, $new_matcher_id, $current_matcher_id, 
133
                  $overlay_action, $nomatch_action, $item_action);
134
                  $overlay_action, $nomatch_action, $item_action, $marctag);
134
    import_records_list($template, $import_batch_id, $offset, $results_per_page);
135
    import_records_list($template, $import_batch_id, $offset, $results_per_page);
135
} 
136
} 
136
137
Lines 139-150 output_html_with_http_headers $input, $cookie, $template->output; Link Here
139
exit 0;
140
exit 0;
140
141
141
sub redo_matching {
142
sub redo_matching {
142
    my ($template, $import_batch_id, $new_matcher_id, $current_matcher_id, $overlay_action, $nomatch_action, $item_action) = @_;
143
    my ($template, $import_batch_id, $new_matcher_id, $current_matcher_id, $overlay_action, $nomatch_action, $item_action, $marctag) = @_;
143
    my $rematch_failed = 0;
144
    my $rematch_failed = 0;
144
    return if not defined $new_matcher_id and not defined $current_matcher_id;
145
    return if not defined $new_matcher_id and not defined $current_matcher_id;
145
    my $old_overlay_action = GetImportBatchOverlayAction($import_batch_id);
146
    my $old_overlay_action = GetImportBatchOverlayAction($import_batch_id);
146
    my $old_nomatch_action = GetImportBatchNoMatchAction($import_batch_id);
147
    my $old_nomatch_action = GetImportBatchNoMatchAction($import_batch_id);
147
    my $old_item_action = GetImportBatchItemAction($import_batch_id);
148
    my $old_item_action = GetImportBatchItemAction($import_batch_id);
149
    my $oldtag = GetImportMarcAction($import_batch_id);
150
    my $oldmarctag = $oldtag->{'marctag'};
148
    return if $new_matcher_id eq $current_matcher_id and 
151
    return if $new_matcher_id eq $current_matcher_id and 
149
              $old_overlay_action eq $overlay_action and 
152
              $old_overlay_action eq $overlay_action and 
150
              $old_nomatch_action eq $nomatch_action and 
153
              $old_nomatch_action eq $nomatch_action and 
Lines 162-167 sub redo_matching { Link Here
162
        SetImportBatchItemAction($import_batch_id, $item_action);
165
        SetImportBatchItemAction($import_batch_id, $item_action);
163
        $template->param('changed_item_action' => 1);
166
        $template->param('changed_item_action' => 1);
164
    }
167
    }
168
    if ($oldmarctag ne $marctag) {
169
       SetImportMarcAction($import_batch_id, $marctag);
170
    }
165
171
166
    my $num_with_matches = 0;
172
    my $num_with_matches = 0;
167
    if (defined $new_matcher_id and $new_matcher_id ne "") {
173
    if (defined $new_matcher_id and $new_matcher_id ne "") {
Lines 218-223 sub import_batches_list { Link Here
218
            comments => $batch->{'comments'},
224
            comments => $batch->{'comments'},
219
            can_clean => ($batch->{'import_status'} ne 'cleaned') ? 1 : 0,
225
            can_clean => ($batch->{'import_status'} ne 'cleaned') ? 1 : 0,
220
            record_type => $batch->{'record_type'},
226
            record_type => $batch->{'record_type'},
227
            marctag => $batch->{'marctag'},
221
        };
228
        };
222
    }
229
    }
223
    $template->param(batch_list => \@list); 
230
    $template->param(batch_list => \@list); 
Lines 420-425 sub batch_info { Link Here
420
    $template->param(batch_info => 1);
427
    $template->param(batch_info => 1);
421
    $template->param(file_name => $batch->{'file_name'});
428
    $template->param(file_name => $batch->{'file_name'});
422
    $template->param(comments => $batch->{'comments'});
429
    $template->param(comments => $batch->{'comments'});
430
    $template->param(marctag => $batch->{'marctag'});
423
    $template->param(import_status => $batch->{'import_status'});
431
    $template->param(import_status => $batch->{'import_status'});
424
    $template->param(upload_timestamp => $batch->{'upload_timestamp'});
432
    $template->param(upload_timestamp => $batch->{'upload_timestamp'});
425
    $template->{VARS}->{'record_type'} = $batch->{'record_type'};
433
    $template->{VARS}->{'record_type'} = $batch->{'record_type'};
(-)a/tools/stage-marc-import.pl (-2 / +2 lines)
Lines 59-64 my $comments = $input->param('comments'); Link Here
59
my $record_type = $input->param('record_type');
59
my $record_type = $input->param('record_type');
60
my $encoding = $input->param('encoding');
60
my $encoding = $input->param('encoding');
61
my $marc_modification_template = $input->param('marc_modification_template_id');
61
my $marc_modification_template = $input->param('marc_modification_template_id');
62
my $marctag = $input->param('marctag');
62
63
63
my ($template, $loggedinuser, $cookie)
64
my ($template, $loggedinuser, $cookie)
64
	= get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
65
	= get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
Lines 134-140 if ($completedJobID) { Link Here
134
    }
135
    }
135
136
136
    # FIXME branch code
137
    # FIXME branch code
137
    my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($record_type, $encoding, $marcrecord, $filename, $marc_modification_template, $comments, '', $parse_items, 0, 50, staging_progress_callback($job, $dbh));
138
    my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($record_type, $encoding, $marcrecord, $filename, $marc_modification_template, $comments, '', $parse_items, 0, $marctag, 50, staging_progress_callback($job, $dbh));
138
139
139
    $dbh->commit();
140
    $dbh->commit();
140
141
141
- 

Return to bug 10477