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

(-)a/C4/ImportBatch.pm (-15 / +37 lines)
Lines 514-520 sub BatchFindDuplicates { Link Here
514
514
515
=head2 BatchCommitRecords
515
=head2 BatchCommitRecords
516
516
517
  my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) =
517
  my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) =
518
        BatchCommitRecords($batch_id, $framework,
518
        BatchCommitRecords($batch_id, $framework,
519
        $progress_interval, $progress_callback);
519
        $progress_interval, $progress_callback);
520
520
Lines 539-544 sub BatchCommitRecords { Link Here
539
    my $num_added = 0;
539
    my $num_added = 0;
540
    my $num_updated = 0;
540
    my $num_updated = 0;
541
    my $num_items_added = 0;
541
    my $num_items_added = 0;
542
    my $num_items_replaced = 0;
542
    my $num_items_errored = 0;
543
    my $num_items_errored = 0;
543
    my $num_ignored = 0;
544
    my $num_ignored = 0;
544
    # commit (i.e., save, all records in the batch)
545
    # commit (i.e., save, all records in the batch)
Lines 598-606 sub BatchCommitRecords { Link Here
598
                my $biblioitemnumber;
599
                my $biblioitemnumber;
599
                ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework);
600
                ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework);
600
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
601
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
601
                if ($item_result eq 'create_new') {
602
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
602
                    my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid);
603
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
603
                    $num_items_added += $bib_items_added;
604
                    $num_items_added += $bib_items_added;
605
                    $num_items_replaced += $bib_items_replaced;
604
                    $num_items_errored += $bib_items_errored;
606
                    $num_items_errored += $bib_items_errored;
605
                }
607
                }
606
            } else {
608
            } else {
Lines 631-639 sub BatchCommitRecords { Link Here
631
                ModBiblio($marc_record, $recordid, $oldbiblio->{'frameworkcode'});
633
                ModBiblio($marc_record, $recordid, $oldbiblio->{'frameworkcode'});
632
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
634
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
633
635
634
                if ($item_result eq 'create_new') {
636
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
635
                    my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid);
637
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
636
                    $num_items_added += $bib_items_added;
638
                    $num_items_added += $bib_items_added;
639
                    $num_items_replaced += $bib_items_replaced;
637
                    $num_items_errored += $bib_items_errored;
640
                    $num_items_errored += $bib_items_errored;
638
                }
641
                }
639
            } else {
642
            } else {
Lines 653-660 sub BatchCommitRecords { Link Here
653
        } elsif ($record_result eq 'ignore') {
656
        } elsif ($record_result eq 'ignore') {
654
            $num_ignored++;
657
            $num_ignored++;
655
            if ($record_type eq 'biblio' and defined $recordid and $item_result eq 'create_new') {
658
            if ($record_type eq 'biblio' and defined $recordid and $item_result eq 'create_new') {
656
                my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid);
659
                my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
657
                $num_items_added += $bib_items_added;
660
                $num_items_added += $bib_items_added;
661
		$num_items_replaced += $bib_items_replaced;
658
                $num_items_errored += $bib_items_errored;
662
                $num_items_errored += $bib_items_errored;
659
                # still need to record the matched biblionumber so that the
663
                # still need to record the matched biblionumber so that the
660
                # items can be reverted
664
                # items can be reverted
Lines 667-673 sub BatchCommitRecords { Link Here
667
    }
671
    }
668
    $sth->finish();
672
    $sth->finish();
669
    SetImportBatchStatus($batch_id, 'imported');
673
    SetImportBatchStatus($batch_id, 'imported');
670
    return ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored);
674
    return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored);
671
}
675
}
672
676
673
=head2 BatchCommitItems
677
=head2 BatchCommitItems
Lines 678-689 sub BatchCommitRecords { Link Here
678
=cut
682
=cut
679
683
680
sub BatchCommitItems {
684
sub BatchCommitItems {
681
    my ($import_record_id, $biblionumber) = @_;
685
    my ($import_record_id, $biblionumber, $action) = @_;
682
686
683
    my $dbh = C4::Context->dbh;
687
    my $dbh = C4::Context->dbh;
684
688
685
    my $num_items_added = 0;
689
    my ($num_items_added, $num_items_errored, $num_items_replaced) = 0;
686
    my $num_items_errored = 0;
687
    my $sth = $dbh->prepare("SELECT import_items_id, import_items.marcxml, encoding
690
    my $sth = $dbh->prepare("SELECT import_items_id, import_items.marcxml, encoding
688
                             FROM import_items
691
                             FROM import_items
689
                             JOIN import_records USING (import_record_id)
692
                             JOIN import_records USING (import_record_id)
Lines 693-703 sub BatchCommitItems { Link Here
693
    $sth->execute();
696
    $sth->execute();
694
    while (my $row = $sth->fetchrow_hashref()) {
697
    while (my $row = $sth->fetchrow_hashref()) {
695
        my $item_marc = MARC::Record->new_from_xml(StripNonXmlChars($row->{'marcxml'}), 'UTF-8', $row->{'encoding'});
698
        my $item_marc = MARC::Record->new_from_xml(StripNonXmlChars($row->{'marcxml'}), 'UTF-8', $row->{'encoding'});
699
	#delete date_due subfield as to not accidentally delete item checkout due dates
700
	$item_marc->field('952')->delete_subfield(code => 'q');
696
        # FIXME - duplicate barcode check needs to become part of AddItemFromMarc()
701
        # FIXME - duplicate barcode check needs to become part of AddItemFromMarc()
697
        my $item = TransformMarcToKoha($dbh, $item_marc);
702
        my $item = TransformMarcToKoha($dbh, $item_marc);
698
        my $duplicate_barcode = exists($item->{'barcode'}) && GetItemnumberFromBarcode($item->{'barcode'});
703
        my $duplicate_barcode = exists($item->{'barcode'}) && GetItemnumberFromBarcode($item->{'barcode'});
699
        if ($duplicate_barcode) {
704
        my $duplicate_itemnumber = exists($item->{'itemnumber'});
700
            my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, import_error = ? WHERE import_items_id = ?");
705
	my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
706
	if($action eq "replace" && $duplicate_itemnumber){
707
	    ModItemFromMarc($item_marc, $biblionumber, $item->{itemnumber});
708
            $updsth->bind_param(1, 'imported');
709
            $updsth->bind_param(2, $item->{itemnumber});
710
            $updsth->bind_param(3, $row->{'import_items_id'});
711
            $updsth->execute();
712
            $updsth->finish();
713
	    $num_items_replaced++;
714
	}
715
        elsif ($duplicate_barcode) {
701
            $updsth->bind_param(1, 'error');
716
            $updsth->bind_param(1, 'error');
702
            $updsth->bind_param(2, 'duplicate item barcode');
717
            $updsth->bind_param(2, 'duplicate item barcode');
703
            $updsth->bind_param(3, $row->{'import_items_id'});
718
            $updsth->bind_param(3, $row->{'import_items_id'});
Lines 705-711 sub BatchCommitItems { Link Here
705
            $num_items_errored++;
720
            $num_items_errored++;
706
        } else {
721
        } else {
707
            my ($item_biblionumber, $biblioitemnumber, $itemnumber) = AddItemFromMarc($item_marc, $biblionumber);
722
            my ($item_biblionumber, $biblioitemnumber, $itemnumber) = AddItemFromMarc($item_marc, $biblionumber);
708
            my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
709
            $updsth->bind_param(1, 'imported');
723
            $updsth->bind_param(1, 'imported');
710
            $updsth->bind_param(2, $itemnumber);
724
            $updsth->bind_param(2, $itemnumber);
711
            $updsth->bind_param(3, $row->{'import_items_id'});
725
            $updsth->bind_param(3, $row->{'import_items_id'});
Lines 715-721 sub BatchCommitItems { Link Here
715
        }
729
        }
716
    }
730
    }
717
    $sth->finish();
731
    $sth->finish();
718
    return ($num_items_added, $num_items_errored);
732
    return ($num_items_added, $num_items_replaced, $num_items_errored);
719
}
733
}
720
734
721
=head2 BatchRevertRecords
735
=head2 BatchRevertRecords
Lines 1461-1467 sub _get_commit_action { Link Here
1461
            } elsif ($overlay_action eq 'ignore') {
1475
            } elsif ($overlay_action eq 'ignore') {
1462
                $bib_result  = 'ignore';
1476
                $bib_result  = 'ignore';
1463
            }
1477
            }
1464
            $item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_matches') ? 'create_new' : 'ignore';
1478
         if($item_action eq 'always_add' or $item_action eq 'add_only_for_matches'){
1479
                $item_result = 'create_new';
1480
       }
1481
      elsif($item_action eq 'replace'){
1482
          $item_result = 'replace';
1483
          }
1484
      else {
1485
             $item_result = 'ignore';
1486
           }
1465
        } else {
1487
        } else {
1466
            $bib_result = $nomatch_action;
1488
            $bib_result = $nomatch_action;
1467
            $item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_new')     ? 'create_new' : 'ignore';
1489
            $item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_new')     ? 'create_new' : 'ignore';
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 861-867 CREATE TABLE `import_batches` ( -- information about batches of marc records tha Link Here
861
  `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- date and time the file was uploaded
861
  `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- date and time the file was uploaded
862
  `overlay_action` enum('replace', 'create_new', 'use_template', 'ignore') NOT NULL default 'create_new', -- how to handle duplicate records
862
  `overlay_action` enum('replace', 'create_new', 'use_template', 'ignore') NOT NULL default 'create_new', -- how to handle duplicate records
863
  `nomatch_action` enum('create_new', 'ignore') NOT NULL default 'create_new', -- how to handle records where no match is found
863
  `nomatch_action` enum('create_new', 'ignore') NOT NULL default 'create_new', -- how to handle records where no match is found
864
  `item_action` enum('always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore') NOT NULL default 'always_add', -- what to do with item records
864
  `item_action` enum('always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore', 'replace') NOT NULL default 'always_add', -- what to do with item records
865
  `import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging', -- the status of the imported file
865
  `import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging', -- the status of the imported file
866
  `batch_type` enum('batch', 'z3950', 'webservice') NOT NULL default 'batch', -- where this batch has come from
866
  `batch_type` enum('batch', 'z3950', 'webservice') NOT NULL default 'batch', -- where this batch has come from
867
  `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio', -- type of record in the batch
867
  `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio', -- type of record in the batch
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-item-action.inc (+6 lines)
Lines 17-22 Link Here
17
                <option value="add_only_for_new">
17
                <option value="add_only_for_new">
18
            [% END %]
18
            [% END %]
19
                Add items only if no matching bib was found</option>
19
                Add items only if no matching bib was found</option>
20
            [% IF ( item_action_replace ) %]
21
                <option value="replace" selected="selected">
22
            [% ELSE %]
23
                <option value="replace">
24
            [% END %]
25
                Replace items if matching bib was found (only for existing items)</option>
20
            [% IF ( item_action_ignore ) %]
26
            [% IF ( item_action_ignore ) %]
21
                <option value="ignore" selected="selected">
27
                <option value="ignore" selected="selected">
22
            [% ELSE %]
28
            [% ELSE %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (+1 lines)
Lines 222-227 $(document).ready(function(){ Link Here
222
  <tr><td>Number of records updated</td><td>[% num_updated %]</td></tr>
222
  <tr><td>Number of records updated</td><td>[% num_updated %]</td></tr>
223
  <tr><td>Number of records ignored</td><td>[% num_ignored %]</td></tr>
223
  <tr><td>Number of records ignored</td><td>[% num_ignored %]</td></tr>
224
  <tr><td>Number of items added</td><td>[% num_items_added %]</td></tr>
224
  <tr><td>Number of items added</td><td>[% num_items_added %]</td></tr>
225
  <tr><td>Number of items replaced</td><td>[% num_items_replaced %]</td></tr>
225
  <tr><td>Number of items ignored because of duplicate barcode</td><td>[% num_items_errored %]</td></tr>
226
  <tr><td>Number of items ignored because of duplicate barcode</td><td>[% num_items_errored %]</td></tr>
226
  </table>
227
  </table>
227
  [% END %]
228
  [% END %]
(-)a/tools/manage-marc-import.pl (-2 / +4 lines)
Lines 146-151 sub redo_matching { Link Here
146
    my $old_overlay_action = GetImportBatchOverlayAction($import_batch_id);
146
    my $old_overlay_action = GetImportBatchOverlayAction($import_batch_id);
147
    my $old_nomatch_action = GetImportBatchNoMatchAction($import_batch_id);
147
    my $old_nomatch_action = GetImportBatchNoMatchAction($import_batch_id);
148
    my $old_item_action = GetImportBatchItemAction($import_batch_id);
148
    my $old_item_action = GetImportBatchItemAction($import_batch_id);
149
    print STDERR "IN REDO MATCHING: $old_item_action - $item_action\n\n";
149
    return if $new_matcher_id eq $current_matcher_id and 
150
    return if $new_matcher_id eq $current_matcher_id and 
150
              $old_overlay_action eq $overlay_action and 
151
              $old_overlay_action eq $overlay_action and 
151
              $old_nomatch_action eq $nomatch_action and 
152
              $old_nomatch_action eq $nomatch_action and 
Lines 160-165 sub redo_matching { Link Here
160
        $template->param('changed_nomatch_action' => 1);
161
        $template->param('changed_nomatch_action' => 1);
161
    }
162
    }
162
    if ($old_item_action ne $item_action) {
163
    if ($old_item_action ne $item_action) {
164
	print STDERR "IN IF";
163
        SetImportBatchItemAction($import_batch_id, $item_action);
165
        SetImportBatchItemAction($import_batch_id, $item_action);
164
        $template->param('changed_item_action' => 1);
166
        $template->param('changed_item_action' => 1);
165
    }
167
    }
Lines 241-247 sub commit_batch { Link Here
241
        $job = put_in_background($import_batch_id);
243
        $job = put_in_background($import_batch_id);
242
        $callback = progress_callback($job, $dbh);
244
        $callback = progress_callback($job, $dbh);
243
    }
245
    }
244
    my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) = 
246
    my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) =
245
        BatchCommitRecords($import_batch_id, $framework, 50, $callback);
247
        BatchCommitRecords($import_batch_id, $framework, 50, $callback);
246
    $dbh->commit();
248
    $dbh->commit();
247
249
Lines 250-255 sub commit_batch { Link Here
250
        num_added => $num_added,
252
        num_added => $num_added,
251
        num_updated => $num_updated,
253
        num_updated => $num_updated,
252
        num_items_added => $num_items_added,
254
        num_items_added => $num_items_added,
255
        num_items_replaced => $num_items_replaced,
253
        num_items_errored => $num_items_errored,
256
        num_items_errored => $num_items_errored,
254
        num_ignored => $num_ignored
257
        num_ignored => $num_ignored
255
    };
258
    };
256
- 

Return to bug 7131