Bugzilla – Attachment 14344 Details for
Bug 7131
way to overlay items in in marc import
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch adds the ability to overlay items when Staging
Patch-adds-the-ability-to-overlay-items-when-Stagi.patch (text/plain), 12.22 KB, created by
Elliott Davis
on 2012-12-31 21:01:35 UTC
(
hide
)
Description:
Patch adds the ability to overlay items when Staging
Filename:
MIME Type:
Creator:
Elliott Davis
Created:
2012-12-31 21:01:35 UTC
Size:
12.22 KB
patch
obsolete
>From 17fb1319268de7f9a0ce2cf67e8892ff4aab4cd3 Mon Sep 17 00:00:00 2001 >From: Elliott Davis <elliott@bywatersolutions.com> >Date: Wed, 10 Oct 2012 14:21:22 -0500 >Subject: [PATCH] Patch adds the ability to overlay items when Staging > >When staging biblios with items attached you previously had only 2 options (add/don't add). >This patch adds a third option to replace an item record if a match is found else it adds the item. > >To test: > >Stage a file of biblios with items attached. >Import the batch into the catalog. >Run the indexer so the matcher will match >Modify the item data for at least one bib in the file >Re-stage the file with the item matching option set to "Replace items if matching bib was found" >Let the indexer run again >You should see updated item information afte the overlay > >http://bugs.koha-community.org/show_bug.cgi?id=7131 >--- > C4/ImportBatch.pm | 48 ++++++++++++++----- > installer/data/mysql/kohastructure.sql | 2 +- > .../prog/en/includes/tools-item-action.inc | 6 +++ > .../prog/en/modules/tools/manage-marc-import.tt | 1 + > tools/manage-marc-import.pl | 5 ++- > 5 files changed, 47 insertions(+), 15 deletions(-) > >diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm >index 5f46613..4c5450c 100644 >--- a/C4/ImportBatch.pm >+++ b/C4/ImportBatch.pm >@@ -514,7 +514,7 @@ sub BatchFindDuplicates { > > =head2 BatchCommitRecords > >- my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) = >+ my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) = > BatchCommitRecords($batch_id, $framework, > $progress_interval, $progress_callback); > >@@ -539,6 +539,7 @@ sub BatchCommitRecords { > my $num_added = 0; > my $num_updated = 0; > my $num_items_added = 0; >+ my $num_items_replaced = 0; > my $num_items_errored = 0; > my $num_ignored = 0; > # commit (i.e., save, all records in the batch) >@@ -598,9 +599,10 @@ sub BatchCommitRecords { > my $biblioitemnumber; > ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework); > $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; >- if ($item_result eq 'create_new') { >- my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid); >+ if ($item_result eq 'create_new' || $item_result eq 'replace') { >+ my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result); > $num_items_added += $bib_items_added; >+ $num_items_replaced += $bib_items_replaced; > $num_items_errored += $bib_items_errored; > } > } else { >@@ -631,9 +633,10 @@ sub BatchCommitRecords { > ModBiblio($marc_record, $recordid, $oldbiblio->{'frameworkcode'}); > $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; > >- if ($item_result eq 'create_new') { >- my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid); >+ if ($item_result eq 'create_new' || $item_result eq 'replace') { >+ my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result); > $num_items_added += $bib_items_added; >+ $num_items_replaced += $bib_items_replaced; > $num_items_errored += $bib_items_errored; > } > } else { >@@ -653,8 +656,9 @@ sub BatchCommitRecords { > } elsif ($record_result eq 'ignore') { > $num_ignored++; > if ($record_type eq 'biblio' and defined $recordid and $item_result eq 'create_new') { >- my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid); >+ my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result); > $num_items_added += $bib_items_added; >+ $num_items_replaced += $bib_items_replaced; > $num_items_errored += $bib_items_errored; > # still need to record the matched biblionumber so that the > # items can be reverted >@@ -667,7 +671,7 @@ sub BatchCommitRecords { > } > $sth->finish(); > SetImportBatchStatus($batch_id, 'imported'); >- return ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored); >+ return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored); > } > > =head2 BatchCommitItems >@@ -678,12 +682,11 @@ sub BatchCommitRecords { > =cut > > sub BatchCommitItems { >- my ($import_record_id, $biblionumber) = @_; >+ my ($import_record_id, $biblionumber, $action) = @_; > > my $dbh = C4::Context->dbh; > >- my $num_items_added = 0; >- my $num_items_errored = 0; >+ my ($num_items_added, $num_items_errored, $num_items_replaced) = 0; > my $sth = $dbh->prepare("SELECT import_items_id, import_items.marcxml, encoding > FROM import_items > JOIN import_records USING (import_record_id) >@@ -696,7 +699,18 @@ sub BatchCommitItems { > # FIXME - duplicate barcode check needs to become part of AddItemFromMarc() > my $item = TransformMarcToKoha($dbh, $item_marc); > my $duplicate_barcode = exists($item->{'barcode'}) && GetItemnumberFromBarcode($item->{'barcode'}); >- if ($duplicate_barcode) { >+ my $duplicate_itemnumber = exists($item->{'itemnumber'}); >+ if($action eq "replace"){ >+ ModItemFromMarc($item_marc, $biblionumber, $item->{itemnumber}); >+ my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?"); >+ $updsth->bind_param(1, 'imported'); >+ $updsth->bind_param(2, $item->{itemnumber}); >+ $updsth->bind_param(3, $row->{'import_items_id'}); >+ $updsth->execute(); >+ $updsth->finish(); >+ $num_items_replaced++; >+ } >+ elsif ($duplicate_barcode) { > my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, import_error = ? WHERE import_items_id = ?"); > $updsth->bind_param(1, 'error'); > $updsth->bind_param(2, 'duplicate item barcode'); >@@ -715,7 +729,7 @@ sub BatchCommitItems { > } > } > $sth->finish(); >- return ($num_items_added, $num_items_errored); >+ return ($num_items_added, $num_items_replaced, $num_items_errored); > } > > =head2 BatchRevertRecords >@@ -1461,7 +1475,15 @@ sub _get_commit_action { > } elsif ($overlay_action eq 'ignore') { > $bib_result = 'ignore'; > } >- $item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_matches') ? 'create_new' : 'ignore'; >+ if($item_action eq 'always_add' or $item_action eq 'add_only_for_matches'){ >+ $item_result = 'create_new'; >+ } >+ elsif($item_action eq 'replace'){ >+ $item_result = 'replace'; >+ } >+ else { >+ $item_result = 'ignore'; >+ } > } else { > $bib_result = $nomatch_action; > $item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_new') ? 'create_new' : 'ignore'; >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index ed673da..07c5316 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -861,7 +861,7 @@ CREATE TABLE `import_batches` ( -- information about batches of marc records tha > `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- date and time the file was uploaded > `overlay_action` enum('replace', 'create_new', 'use_template', 'ignore') NOT NULL default 'create_new', -- how to handle duplicate records > `nomatch_action` enum('create_new', 'ignore') NOT NULL default 'create_new', -- how to handle records where no match is found >- `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 >+ `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 > `import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging', -- the status of the imported file > `batch_type` enum('batch', 'z3950', 'webservice') NOT NULL default 'batch', -- where this batch has come from > `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio', -- type of record in the batch >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-item-action.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-item-action.inc >index 0c8d37b..4aac672 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-item-action.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-item-action.inc >@@ -17,6 +17,12 @@ > <option value="add_only_for_new"> > [% END %] > Add items only if no matching bib was found</option> >+ [% IF ( item_action_replace ) %] >+ <option value="replace" selected="selected"> >+ [% ELSE %] >+ <option value="replace"> >+ [% END %] >+ Replace items if matching bib was found</option> > [% IF ( item_action_ignore ) %] > <option value="ignore" selected="selected"> > [% ELSE %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt >index 8265b50..9ee2ccf 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt >@@ -204,6 +204,7 @@ $(document).ready(function(){ > <tr><td>Number of records updated</td><td>[% num_updated %]</td></tr> > <tr><td>Number of records ignored</td><td>[% num_ignored %]</td></tr> > <tr><td>Number of items added</td><td>[% num_items_added %]</td></tr> >+ <tr><td>Number of items replaced</td><td>[% num_items_replaced %]</td></tr> > <tr><td>Number of items ignored because of duplicate barcode</td><td>[% num_items_errored %]</td></tr> > </table> > [% END %] >diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl >index 32d3645..37a054d 100755 >--- a/tools/manage-marc-import.pl >+++ b/tools/manage-marc-import.pl >@@ -146,6 +146,7 @@ sub redo_matching { > my $old_overlay_action = GetImportBatchOverlayAction($import_batch_id); > my $old_nomatch_action = GetImportBatchNoMatchAction($import_batch_id); > my $old_item_action = GetImportBatchItemAction($import_batch_id); >+ print STDERR "IN REDO MATCHING: $old_item_action - $item_action\n\n"; > return if $new_matcher_id eq $current_matcher_id and > $old_overlay_action eq $overlay_action and > $old_nomatch_action eq $nomatch_action and >@@ -160,6 +161,7 @@ sub redo_matching { > $template->param('changed_nomatch_action' => 1); > } > if ($old_item_action ne $item_action) { >+ print STDERR "IN IF"; > SetImportBatchItemAction($import_batch_id, $item_action); > $template->param('changed_item_action' => 1); > } >@@ -241,7 +243,7 @@ sub commit_batch { > $job = put_in_background($import_batch_id); > $callback = progress_callback($job, $dbh); > } >- my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) = >+ my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) = > BatchCommitRecords($import_batch_id, $framework, 50, $callback); > $dbh->commit(); > >@@ -250,6 +252,7 @@ sub commit_batch { > num_added => $num_added, > num_updated => $num_updated, > num_items_added => $num_items_added, >+ num_items_replaced => $num_items_replaced, > num_items_errored => $num_items_errored, > num_ignored => $num_ignored > }; >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7131
:
14344
|
14475
|
15954
|
15957
|
16887
|
16889
|
17208
|
17209
|
17210
|
17211
|
17212
|
18708
|
18709
|
18710
|
18711
|
18967
|
18968
|
18969
|
20455
|
21797