Bugzilla – Attachment 19213 Details for
Bug 10477
Allow to select MARC fields to merge on staged MARC import
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Increased flexibility for upload of Staged
0001-Bug-10477-Increased-flexibility-for-upload-of-Staged.patch (text/plain), 15.51 KB, created by
Amit Gupta
on 2013-06-24 12:17:56 UTC
(
hide
)
Description:
Increased flexibility for upload of Staged
Filename:
MIME Type:
Creator:
Amit Gupta
Created:
2013-06-24 12:17:56 UTC
Size:
15.51 KB
patch
obsolete
>From df1a4605d5392bff6ff0fab91fe181b19e014f4b Mon Sep 17 00:00:00 2001 >From: Amit Gupta <amitddng135@gmail.com> >Date: Sat, 22 Jun 2013 23:30:19 +0530 >Subject: [PATCH 1/2] Bug-10477 Increased flexibility for upload of Staged > >When uploading bulk MARC records against existing records need further >option to allow the process to just add/merge extra MARC tags rather >than having to completely overwrite an existing record or just leave >the existing record unchanged. > >Test Plan: >1. Click on Tools->Stage MARC records for import. >2. Upload the MARC file for ex: first.mrc >3. Click on upload button. >4. Choose Record matching rule: 020$a ISBN. >5. Choose Action if matching record found: Append or update MARC21/UNIMARC >tag a text box will appear after choosing enter MARC tag for ex: 700a which >you want to merge. >6. Click on Stage for import button. >7. On the next screen click on Manage staged records. >8. You can also edit the record matching rule in manage record screen. >9. Click on Import this batch on catalog button. >10. Next screen will give no of record updated. >11. It will check duplicate field record for ex: 700$aamit is already in record >it will skip the tag and move to next. > >Sponsored-by: Staffordshire University/Halton Borough Council/PTFS Europe >--- > C4/ImportBatch.pm | 115 +++++++++++++++++++- > .../prog/en/includes/tools-overlay-action.inc | 21 +++- > .../prog/en/modules/tools/manage-marc-import.tt | 2 + > tools/manage-marc-import.pl | 12 +- > tools/stage-marc-import.pl | 3 +- > 5 files changed, 147 insertions(+), 6 deletions(-) > >diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm >index 3ce5c67..35a2d38 100644 >--- a/C4/ImportBatch.pm >+++ b/C4/ImportBatch.pm >@@ -76,6 +76,8 @@ BEGIN { > SetImportRecordStatus > GetImportRecordMatches > SetImportRecordMatches >+ GetImportMarcAction >+ SetImportMarcAction > ); > } > >@@ -205,7 +207,8 @@ sub AddImportBatch { > my (@fields, @vals); > foreach (qw( matcher_id template_id branchcode > overlay_action nomatch_action item_action >- import_status batch_type file_name comments record_type )) { >+ import_status batch_type file_name comments record_type marctag )) { >+ > if (exists $params->{$_}) { > push @fields, $_; > push @vals, $params->{$_}; >@@ -219,6 +222,34 @@ sub AddImportBatch { > return $dbh->{'mysql_insertid'}; > } > >+=head2 GetImportMarcAction >+ >+ my $marctag = GetImportMarcAction($batch_id); >+ >+=cut >+ >+sub GetImportMarcAction { >+ my ($batch_id) = @_; >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare("SELECT * FROM import_batches WHERE import_batch_id = ?"); >+ $sth->execute($batch_id); >+ return $sth->fetchrow_hashref; >+} >+ >+=head2 SetImportMarcAction >+ >+ SetImportMarcAction($batch_id, $marctag); >+ >+=cut >+ >+sub SetImportMarcAction { >+ my ($batch_id, $marctag) = @_; >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare("UPDATE import_batches SET marctag = ? WHERE import_batch_id = ?"); >+ $sth->execute($marctag, $batch_id); >+ return; >+} >+ > =head2 GetImportBatch > > my $row = GetImportBatch($batch_id); >@@ -323,7 +354,7 @@ sub ModAuthInBatch { > > =cut > >-sub BatchStageMarcRecords { >+sub BatchStageMarcRecords { > my $record_type = shift; > my $encoding = shift; > my $marc_records = shift; >@@ -332,6 +363,7 @@ sub BatchStageMarcRecords { > my $branch_code = shift; > my $parse_items = shift; > my $leave_as_staging = shift; >+ my $marctag = shift; > > # optional callback to monitor status > # of job >@@ -351,6 +383,7 @@ sub BatchStageMarcRecords { > file_name => $file_name, > comments => $comments, > record_type => $record_type, >+ marctag => $marctag, > } ); > if ($parse_items) { > SetImportBatchItemAction($batch_id, 'always_add'); >@@ -611,6 +644,82 @@ sub BatchCommitRecords { > $sth->execute($recordid, $rowref->{'import_record_id'}); > $sth->finish(); > SetImportRecordStatus($rowref->{'import_record_id'}, 'imported'); >+ } elsif ($record_result eq 'appendmarctag') { >+ $num_updated++; >+ $recordid = $record_match; >+ my $tag = GetImportMarcAction($batch_id); >+ my $marctag = $tag->{'marctag'}; >+ my $mtag = substr($marctag,0,3); >+ my $sub = substr($marctag,3); >+ my $oldxml; >+ if ($record_type eq 'biblio') { >+ my ($count, $oldbiblio) = GetBiblio($recordid); >+ $oldxml = GetXmlBiblio($recordid); >+ my $old_marc = MARC::Record->new_from_xml(StripNonXmlChars($oldxml), 'UTF-8', $rowref->{'encoding'}, $marc_type); >+ foreach my $item_field ($old_marc->field($item_tag)) { >+ $old_marc->delete_field($item_field); >+ } >+ $oldxml = $old_marc->as_xml($marc_type); >+ >+ my $sth=$dbh->prepare("SELECT * FROM marc_tag_structure WHERE tagfield=? AND frameworkcode=?"); >+ if ($oldbiblio->{'frameworkcode'} eq '') { >+ $sth->execute($mtag,''); >+ } else { >+ $sth->execute($mtag,$oldbiblio->{'frameworkcode'}); >+ } >+ my $data=$sth->fetchrow_hashref; >+ >+ if ($data->{'repeatable'} == 0) { >+ my $new_marc = $old_marc->field($mtag); >+ my $newvalue = $marc_record->field($mtag)->subfield($sub); >+ my $oldvalue = $old_marc->field($mtag)->subfield($sub); >+ ##checking value if value is not duplicate update the marc tag. >+ if ($oldvalue ne $newvalue) { >+ $new_marc->delete_subfield(code => $sub); >+ my $new_field = $marc_record->field($mtag); >+ $new_field->update( $sub => $newvalue ); >+ $old_marc->insert_fields_ordered($new_field); >+ } >+ } elsif($data->{'repeatable'} == 1 ) { >+ my @value; >+ my $i =0; >+ my @oldvalue; >+ my $j=0; >+ foreach my $field_marc ($marc_record->field($mtag)) { >+ @value[$i] = $field_marc->subfield($sub); >+ $i = $i + 1; >+ } >+ foreach my $oldm ($old_marc->field($mtag)) { >+ @oldvalue[$j] = $oldm->subfield($sub); >+ $j = $j + 1; >+ } >+ for my $index (0 .. $#value) { >+ #checking for duplicate values >+ if ($value[$index] ne $oldvalue[$index]) { >+ my $new = MARC::Field->new($mtag,'','',$sub => $value[$index]); >+ $old_marc->insert_fields_ordered($new); >+ } >+ } >+ } >+ ModBiblio($old_marc, $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); >+ $num_items_added = $bib_items_added; >+ $num_items_errored = $bib_items_errored; >+ } >+ } else { >+ $oldxml = GetAuthorityXML($recordid); >+ ModAuthority($recordid, $marc_record, GuessAuthTypeCode($marc_record)); >+ $query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?"; >+ } >+ my $sth = $dbh->prepare("UPDATE import_records SET marcxml_old = ? WHERE import_record_id = ?"); >+ $sth->execute($oldxml, $rowref->{'import_record_id'}); >+ $sth = $dbh->prepare($query); >+ $sth->execute($recordid, $rowref->{'import_record_id'}); >+ SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied'); >+ SetImportRecordStatus($rowref->{'import_record_id'}, 'imported'); > } elsif ($record_result eq 'replace') { > $num_updated++; > $recordid = $record_match; >@@ -1466,6 +1575,8 @@ sub _get_commit_action { > $bib_result = 'create_new'; > } elsif ($overlay_action eq 'ignore') { > $bib_result = 'ignore'; >+ } elsif ($overlay_action eq 'appendmarctag') { >+ $bib_result = 'appendmarctag'; > } > $item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_matches') ? 'create_new' : 'ignore'; > } else { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-overlay-action.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-overlay-action.inc >index 9318814..8a2f93d 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-overlay-action.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-overlay-action.inc >@@ -1,4 +1,16 @@ >- <select name="overlay_action" id="overlay_action"> >+<script type="text/javascript"> >+ function toggle() { >+ var a = document.getElementById('overlay_action').value; >+ if (a == 'appendmarctag') { >+ document.getElementById('marctag').style.visibility = 'visible'; >+ document.getElementById('marctag').style.display = 'block'; >+ } else { >+ document.getElementById('marctag').style.visibility = 'hidden'; >+ document.getElementById('marctag').style.display = 'none'; >+ } >+ } >+</script> >+ <select name="overlay_action" id="overlay_action" onchange="toggle()"> > [% IF ( overlay_action_replace ) %] > <option value="replace" selected="selected"> > [% ELSE %] >@@ -17,4 +29,11 @@ > <option value="ignore"> > [% END %] > Ignore incoming record (its items may still be processed)</option> >+ [% IF ( overlay_action_appendmarctag ) %] >+ <option value="appendmarctag" selected="selected"> >+ [% ELSE %] >+ <option value="appendmarctag"> >+ [% END %] >+ Append or update MARC21/UNIMARC tag(Enter like 100a, 700a)</option> > </select> >+ <input type="textbox" id="marctag" name ="marctag" maxlength = "4" size = "4" style="display:none;visible:false"/> >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 5b0e3a2..063fa62 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 >@@ -170,6 +170,8 @@ $(document).ready(function(){ > </li> > <li>[% IF ( can_commit ) %] <label for="overlay_action">Action if matching record found:</label> > [% INCLUDE 'tools-overlay-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_overlay_action">Reset</a></span>[% ELSE %]<span class="label">Action if matching record found:</span>[% overlay_action %][% END %]</li> >+ >+ [% IF ( marctag ) %]<li><span class="label">MarcTag:</span>[% marctag %]</li>[% END %] > > <li>[% IF ( can_commit ) %]<label for="nomatch_action">Action if no match found:</label> > [% INCLUDE 'tools-nomatch-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_nomatch_action">Reset</a></span>[% ELSE %]<span class="label">Action if no match found:</span>[% nomatch_action %][% END %]</li> >diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl >index 25f7769..dfc3541 100755 >--- a/tools/manage-marc-import.pl >+++ b/tools/manage-marc-import.pl >@@ -129,9 +129,10 @@ if ($op eq "") { > my $current_matcher_id = $input->param('current_matcher_id'); > my $overlay_action = $input->param('overlay_action'); > my $nomatch_action = $input->param('nomatch_action'); >+ my $marctag = $input->param('marctag'); > my $item_action = $input->param('item_action'); > redo_matching($template, $import_batch_id, $new_matcher_id, $current_matcher_id, >- $overlay_action, $nomatch_action, $item_action); >+ $overlay_action, $nomatch_action, $item_action, $marctag); > import_records_list($template, $import_batch_id, $offset, $results_per_page); > } > >@@ -140,12 +141,14 @@ output_html_with_http_headers $input, $cookie, $template->output; > exit 0; > > sub redo_matching { >- my ($template, $import_batch_id, $new_matcher_id, $current_matcher_id, $overlay_action, $nomatch_action, $item_action) = @_; >+ my ($template, $import_batch_id, $new_matcher_id, $current_matcher_id, $overlay_action, $nomatch_action, $item_action, $marctag) = @_; > my $rematch_failed = 0; > return if not defined $new_matcher_id and not defined $current_matcher_id; > my $old_overlay_action = GetImportBatchOverlayAction($import_batch_id); > my $old_nomatch_action = GetImportBatchNoMatchAction($import_batch_id); > my $old_item_action = GetImportBatchItemAction($import_batch_id); >+ my $oldtag = GetImportMarcAction($import_batch_id); >+ my $oldmarctag = $oldtag->{'marctag'}; > return if $new_matcher_id eq $current_matcher_id and > $old_overlay_action eq $overlay_action and > $old_nomatch_action eq $nomatch_action and >@@ -163,6 +166,9 @@ sub redo_matching { > SetImportBatchItemAction($import_batch_id, $item_action); > $template->param('changed_item_action' => 1); > } >+ if ($oldmarctag ne $marctag) { >+ SetImportMarcAction($import_batch_id, $marctag); >+ } > > my $num_with_matches = 0; > if (defined $new_matcher_id and $new_matcher_id ne "") { >@@ -219,6 +225,7 @@ sub import_batches_list { > comments => $batch->{'comments'}, > can_clean => ($batch->{'import_status'} ne 'cleaned') ? 1 : 0, > record_type => $batch->{'record_type'}, >+ marctag => $batch->{'marctag'}, > }; > } > $template->param(batch_list => \@list); >@@ -420,6 +427,7 @@ sub batch_info { > $template->param(batch_info => 1); > $template->param(file_name => $batch->{'file_name'}); > $template->param(comments => $batch->{'comments'}); >+ $template->param(marctag => $batch->{'marctag'}); > $template->param(import_status => $batch->{'import_status'}); > $template->param(upload_timestamp => $batch->{'upload_timestamp'}); > $template->{VARS}->{'record_type'} = $batch->{'record_type'}; >diff --git a/tools/stage-marc-import.pl b/tools/stage-marc-import.pl >index fbb5365..d6762f2 100755 >--- a/tools/stage-marc-import.pl >+++ b/tools/stage-marc-import.pl >@@ -57,6 +57,7 @@ my $item_action = $input->param('item_action'); > my $comments = $input->param('comments'); > my $record_type = $input->param('record_type'); > my $encoding = $input->param('encoding'); >+my $marctag = $input->param('marctag'); > my ($template, $loggedinuser, $cookie) > = get_template_and_user({template_name => "tools/stage-marc-import.tmpl", > query => $input, >@@ -131,7 +132,7 @@ if ($completedJobID) { > } > > # FIXME branch code >- 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)); >+ 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)); > > $dbh->commit(); > >-- >1.7.9.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 10477
:
19213
|
19214
|
22034
|
22035
|
22536
|
22537
|
24066
|
24067
|
24159
|
24160