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

(-)a/C4/ImportBatch.pm (-2 / +113 lines)
Lines 76-81 BEGIN { Link Here
76
    SetImportRecordStatus
76
    SetImportRecordStatus
77
    GetImportRecordMatches
77
    GetImportRecordMatches
78
    SetImportRecordMatches
78
    SetImportRecordMatches
79
    GetImportMarcAction
80
    SetImportMarcAction
79
	);
81
	);
80
}
82
}
81
83
Lines 205-211 sub AddImportBatch { Link Here
205
    my (@fields, @vals);
207
    my (@fields, @vals);
206
    foreach (qw( matcher_id template_id branchcode
208
    foreach (qw( matcher_id template_id branchcode
207
                 overlay_action nomatch_action item_action
209
                 overlay_action nomatch_action item_action
208
                 import_status batch_type file_name comments record_type )) {
210
                 import_status batch_type file_name comments record_type marctag )) {
211
209
        if (exists $params->{$_}) {
212
        if (exists $params->{$_}) {
210
            push @fields, $_;
213
            push @fields, $_;
211
            push @vals, $params->{$_};
214
            push @vals, $params->{$_};
Lines 219-224 sub AddImportBatch { Link Here
219
    return $dbh->{'mysql_insertid'};
222
    return $dbh->{'mysql_insertid'};
220
}
223
}
221
224
225
=head2 GetImportMarcAction
226
227
  my $marctag = GetImportMarcAction($batch_id);
228
229
=cut
230
231
sub GetImportMarcAction {
232
    my ($batch_id) = @_;
233
    my $dbh = C4::Context->dbh;
234
    my $sth = $dbh->prepare("SELECT * FROM import_batches WHERE import_batch_id = ?");
235
    $sth->execute($batch_id);
236
    return $sth->fetchrow_hashref;
237
}
238
239
=head2 SetImportMarcAction
240
241
  SetImportMarcAction($batch_id, $marctag);
242
243
=cut
244
245
sub SetImportMarcAction {
246
    my ($batch_id, $marctag) = @_;
247
    my $dbh = C4::Context->dbh;
248
    my $sth = $dbh->prepare("UPDATE import_batches SET marctag = ? WHERE import_batch_id = ?");
249
    $sth->execute($marctag, $batch_id);
250
    return;
251
}
252
222
=head2 GetImportBatch 
253
=head2 GetImportBatch 
223
254
224
  my $row = GetImportBatch($batch_id);
255
  my $row = GetImportBatch($batch_id);
Lines 323-329 sub ModAuthInBatch { Link Here
323
354
324
=cut
355
=cut
325
356
326
sub  BatchStageMarcRecords {
357
sub BatchStageMarcRecords {
327
    my $record_type = shift;
358
    my $record_type = shift;
328
    my $encoding = shift;
359
    my $encoding = shift;
329
    my $marc_records = shift;
360
    my $marc_records = shift;
Lines 332-337 sub BatchStageMarcRecords { Link Here
332
    my $branch_code = shift;
363
    my $branch_code = shift;
333
    my $parse_items = shift;
364
    my $parse_items = shift;
334
    my $leave_as_staging = shift;
365
    my $leave_as_staging = shift;
366
    my $marctag = shift;
335
367
336
    # optional callback to monitor status 
368
    # optional callback to monitor status 
337
    # of job
369
    # of job
Lines 351-356 sub BatchStageMarcRecords { Link Here
351
            file_name => $file_name,
383
            file_name => $file_name,
352
            comments => $comments,
384
            comments => $comments,
353
            record_type => $record_type,
385
            record_type => $record_type,
386
            marctag => $marctag,
354
        } );
387
        } );
355
    if ($parse_items) {
388
    if ($parse_items) {
356
        SetImportBatchItemAction($batch_id, 'always_add');
389
        SetImportBatchItemAction($batch_id, 'always_add');
Lines 613-618 sub BatchCommitRecords { Link Here
613
            $sth->execute($recordid, $rowref->{'import_record_id'});
646
            $sth->execute($recordid, $rowref->{'import_record_id'});
614
            $sth->finish();
647
            $sth->finish();
615
            SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
648
            SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
649
        } elsif ($record_result eq 'appendmarctag') {
650
            $num_updated++;
651
            $recordid = $record_match;
652
            my $tag = GetImportMarcAction($batch_id);
653
            my $marctag = $tag->{'marctag'};
654
            my $mtag = substr($marctag,0,3);
655
            my $sub = substr($marctag,3);
656
            my $oldxml;
657
            if ($record_type eq 'biblio') {
658
                my ($count, $oldbiblio) = GetBiblio($recordid);
659
                $oldxml = GetXmlBiblio($recordid);
660
                my $old_marc = MARC::Record->new_from_xml(StripNonXmlChars($oldxml), 'UTF-8', $rowref->{'encoding'}, $marc_type);
661
                foreach my $item_field ($old_marc->field($item_tag)) {
662
                    $old_marc->delete_field($item_field);
663
                }
664
                $oldxml = $old_marc->as_xml($marc_type);
665
666
                my $sth=$dbh->prepare("SELECT * FROM marc_tag_structure WHERE tagfield=? AND frameworkcode=?");
667
                if ($oldbiblio->{'frameworkcode'} eq '') {
668
                    $sth->execute($mtag,'');
669
                } else {
670
                    $sth->execute($mtag,$oldbiblio->{'frameworkcode'});
671
                }
672
                my $data=$sth->fetchrow_hashref;
673
674
                if ($data->{'repeatable'} == 0) {
675
                    my $new_marc = $old_marc->field($mtag);
676
                    my $newvalue = $marc_record->field($mtag)->subfield($sub);
677
                    my $oldvalue = $old_marc->field($mtag)->subfield($sub);
678
                    ##checking value if value is not duplicate update the marc tag.
679
                    if ($oldvalue ne $newvalue) {
680
                        $new_marc->delete_subfield(code => $sub);
681
                        my $new_field = $marc_record->field($mtag);
682
                        $new_field->update( $sub => $newvalue );
683
                        $old_marc->insert_fields_ordered($new_field);
684
                    }
685
                } elsif($data->{'repeatable'} == 1 ) {
686
                   my @value;
687
                   my $i =0;
688
                   my @oldvalue;
689
                   my $j=0;
690
                   foreach my $field_marc ($marc_record->field($mtag)) {
691
                       @value[$i] = $field_marc->subfield($sub);
692
                       $i = $i + 1;
693
                   }
694
                   foreach my $oldm ($old_marc->field($mtag)) {
695
                       @oldvalue[$j] = $oldm->subfield($sub);
696
                       $j = $j + 1;
697
                   }
698
                   for my $index (0 .. $#value) {
699
                       #checking for duplicate values
700
                       if ($value[$index] ne $oldvalue[$index]) {
701
                           my $new = MARC::Field->new($mtag,'','',$sub => $value[$index]);
702
                           $old_marc->insert_fields_ordered($new);
703
                       }
704
                   }
705
                }
706
                ModBiblio($old_marc, $recordid, $oldbiblio->{'frameworkcode'});
707
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
708
709
                if ($item_result eq 'create_new') {
710
                    my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid);
711
                    $num_items_added = $bib_items_added;
712
                    $num_items_errored = $bib_items_errored;
713
                }
714
            } else {
715
                $oldxml = GetAuthorityXML($recordid);
716
                ModAuthority($recordid, $marc_record, GuessAuthTypeCode($marc_record));
717
                $query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?";
718
            }
719
            my $sth = $dbh->prepare("UPDATE import_records SET marcxml_old = ? WHERE import_record_id = ?");
720
            $sth->execute($oldxml, $rowref->{'import_record_id'});
721
            $sth = $dbh->prepare($query);
722
            $sth->execute($recordid, $rowref->{'import_record_id'});
723
            SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
724
            SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
616
        } elsif ($record_result eq 'replace') {
725
        } elsif ($record_result eq 'replace') {
617
            $num_updated++;
726
            $num_updated++;
618
            $recordid = $record_match;
727
            $recordid = $record_match;
Lines 1500-1505 sub _get_commit_action { Link Here
1500
                $bib_result  = 'create_new';
1609
                $bib_result  = 'create_new';
1501
            } elsif ($overlay_action eq 'ignore') {
1610
            } elsif ($overlay_action eq 'ignore') {
1502
                $bib_result  = 'ignore';
1611
                $bib_result  = 'ignore';
1612
            } elsif ($overlay_action eq 'appendmarctag') {
1613
                $bib_result  = 'appendmarctag';
1503
            }
1614
            }
1504
         if($item_action eq 'always_add' or $item_action eq 'add_only_for_matches'){
1615
         if($item_action eq 'always_add' or $item_action eq 'add_only_for_matches'){
1505
                $item_result = 'create_new';
1616
                $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 57-62 my $item_action = $input->param('item_action'); Link Here
57
my $comments = $input->param('comments');
57
my $comments = $input->param('comments');
58
my $record_type = $input->param('record_type');
58
my $record_type = $input->param('record_type');
59
my $encoding = $input->param('encoding');
59
my $encoding = $input->param('encoding');
60
my $marctag = $input->param('marctag');
60
my ($template, $loggedinuser, $cookie)
61
my ($template, $loggedinuser, $cookie)
61
	= get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
62
	= get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
62
					query => $input,
63
					query => $input,
Lines 131-137 if ($completedJobID) { Link Here
131
    }
132
    }
132
133
133
    # FIXME branch code
134
    # FIXME branch code
134
    my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($record_type, $encoding, $marcrecord, $filename, $comments, '', $parse_items, 0, 50, staging_progress_callback($job, $dbh));
135
    my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($record_type, $encoding, $marcrecord, $filename, $comments, '', $parse_items, 0, $marctag, 50, staging_progress_callback($job, $dbh));
135
136
136
    $dbh->commit();
137
    $dbh->commit();
137
138
138
- 

Return to bug 10477