Bugzilla – Attachment 155320 Details for
Bug 33605
Import framework and overlay framework are not stored for imports
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33605: Add ability to set overlay and import framework when importing a staged file
Bug-33605-Add-ability-to-set-overlay-and-import-fr.patch (text/plain), 23.13 KB, created by
Sam Lau
on 2023-09-07 15:39:36 UTC
(
hide
)
Description:
Bug 33605: Add ability to set overlay and import framework when importing a staged file
Filename:
MIME Type:
Creator:
Sam Lau
Created:
2023-09-07 15:39:36 UTC
Size:
23.13 KB
patch
obsolete
>From 1ac08751a972ac9e328faa6a8652d94bb9c90901 Mon Sep 17 00:00:00 2001 >From: Sam Lau <samalau@gmail.com> >Date: Tue, 25 Apr 2023 13:15:12 +0000 >Subject: [PATCH] Bug 33605: Add ability to set overlay and import framework > when importing a staged file > >--- > Koha/BackgroundJob/MARCImportCommitBatch.pm | 4 ++ > Koha/BackgroundJob/StageMARCForImport.pm | 10 +++- > .../definitions/import_batch_profile.yaml | 10 ++++ > .../swagger/paths/import_batch_profiles.yaml | 20 ++++++++ > .../data/mysql/atomicupdate/bug_33605.pl | 38 +++++++++++++++ > installer/data/mysql/kohastructure.sql | 4 ++ > .../en/modules/tools/manage-marc-import.tt | 46 ++++++++++++++++++- > .../en/modules/tools/stage-marc-import.tt | 25 ++++++++++ > tools/manage-marc-import.pl | 3 ++ > tools/stage-marc-import.pl | 9 ++++ > 10 files changed, 165 insertions(+), 4 deletions(-) > create mode 100755 installer/data/mysql/atomicupdate/bug_33605.pl > >diff --git a/Koha/BackgroundJob/MARCImportCommitBatch.pm b/Koha/BackgroundJob/MARCImportCommitBatch.pm >index 22398aef29..0a5aec75ca 100644 >--- a/Koha/BackgroundJob/MARCImportCommitBatch.pm >+++ b/Koha/BackgroundJob/MARCImportCommitBatch.pm >@@ -25,6 +25,7 @@ use Koha::Import::Records; > use C4::ImportBatch qw( > BatchCommitRecords > ); >+use Koha::ImportBatches; > > =head1 NAME > >@@ -67,6 +68,9 @@ sub process { > my ( $num_added, $num_updated, $num_items_added, > $num_items_replaced, $num_items_errored, $num_ignored ); > try { >+ my $import_batch = Koha::ImportBatches->find($import_batch_id); >+ $import_batch->set({ import_frameworkcode => $frameworkcode })->store if $frameworkcode; >+ $import_batch->set({ overlay_frameworkcode => $overlay_frameworkcode })->store if $overlay_frameworkcode; > my $size = Koha::Import::Records->search({ import_batch_id => $import_batch_id })->count; > $self->size($size)->store; > ( $num_added, $num_updated, $num_items_added, >diff --git a/Koha/BackgroundJob/StageMARCForImport.pm b/Koha/BackgroundJob/StageMARCForImport.pm >index 7858eae7a0..a3851f7388 100644 >--- a/Koha/BackgroundJob/StageMARCForImport.pm >+++ b/Koha/BackgroundJob/StageMARCForImport.pm >@@ -33,6 +33,7 @@ use C4::ImportBatch qw( > SetImportBatchNoMatchAction > SetImportBatchItemAction > ); >+use Koha::ImportBatches; > > =head1 NAME > >@@ -75,7 +76,9 @@ sub process { > my $parse_items = $args->{parse_items}; > my $matcher_id = $args->{matcher_id}; > my $overlay_action = $args->{overlay_action}; >+ my $overlay_frameworkcode = $args->{overlay_frameworkcode}; > my $nomatch_action = $args->{nomatch_action}; >+ my $import_frameworkcode = $args->{import_frameworkcode}; > my $item_action = $args->{item_action}; > my $vendor_id = $args->{vendor_id}; > my $basket_id = $args->{basket_id}; >@@ -131,11 +134,14 @@ sub process { > $self->set({ progress => 0, status => 'failed' }); > } > >+ my $import_batch = Koha::ImportBatches->find($batch_id); > if ($profile_id) { >- my $ibatch = Koha::ImportBatches->find($batch_id); >- $ibatch->set( { profile_id => $profile_id } )->store; >+ $import_batch->set( { profile_id => $profile_id } )->store; > } > >+ $import_batch->set({ import_frameworkcode => $import_frameworkcode })->store if $import_frameworkcode; >+ $import_batch->set({ overlay_frameworkcode => $overlay_frameworkcode })->store if $overlay_frameworkcode; >+ > if ($matcher_id) { > my $matcher = C4::Matcher->fetch($matcher_id); > if ( defined $matcher ) { >diff --git a/api/v1/swagger/definitions/import_batch_profile.yaml b/api/v1/swagger/definitions/import_batch_profile.yaml >index 50aa79feb4..d625b4ef99 100644 >--- a/api/v1/swagger/definitions/import_batch_profile.yaml >+++ b/api/v1/swagger/definitions/import_batch_profile.yaml >@@ -22,11 +22,21 @@ properties: > type: > - string > - "null" >+ overlay_frameworkcode: >+ description: what framework to add to duplicate records >+ type: >+ - string >+ - "null" > nomatch_action: > description: how to handle records where no match is found > type: > - string > - "null" >+ import_frameworkcode: >+ description: what framework to add to imported records >+ type: >+ - string >+ - "null" > item_action: > description: what to do with item records > type: >diff --git a/api/v1/swagger/paths/import_batch_profiles.yaml b/api/v1/swagger/paths/import_batch_profiles.yaml >index 958b486de6..6eb16b91cd 100644 >--- a/api/v1/swagger/paths/import_batch_profiles.yaml >+++ b/api/v1/swagger/paths/import_batch_profiles.yaml >@@ -82,11 +82,21 @@ > type: > - string > - "null" >+ overlay_frameworkcode: >+ description: what framework to add to duplicate records >+ type: >+ - string >+ - "null" > nomatch_action: > description: how to handle records where no match is found > type: > - string > - "null" >+ import_frameworkcode: >+ description: what framework to add to imported records >+ type: >+ - string >+ - "null" > item_action: > description: what to do with item records > type: >@@ -191,11 +201,21 @@ > type: > - string > - "null" >+ overlay_frameworkcode: >+ description: what framework to add to duplicate records >+ type: >+ - string >+ - "null" > nomatch_action: > description: how to handle records where no match is found > type: > - string > - "null" >+ import_frameworkcode: >+ description: what framework to add to imported records >+ type: >+ - string >+ - "null" > item_action: > description: what to do with item records > type: >diff --git a/installer/data/mysql/atomicupdate/bug_33605.pl b/installer/data/mysql/atomicupdate/bug_33605.pl >new file mode 100755 >index 0000000000..a76339001f >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_33605.pl >@@ -0,0 +1,38 @@ >+use Modern::Perl; >+ >+return { >+ bug_number => "33605", >+ description => "Add import_framework and overlay_framework columns to import_batches table", >+ up => sub { >+ my ($args) = @_; >+ my ($dbh, $out) = @$args{qw(dbh out)}; >+ unless( column_exists("import_batches","overlay_frameworkcode") ){ >+ $dbh->do(q{ >+ ALTER TABLE `import_batches` >+ ADD `overlay_frameworkcode` varchar(50) NOT NULL DEFAULT '' AFTER `overlay_action` ; >+ }); >+ say $out "Added column 'import_batches.overlay_frameworkcode'"; >+ } >+ unless( column_exists("import_batches","import_frameworkcode") ){ >+ $dbh->do(q{ >+ ALTER TABLE `import_batches` >+ ADD `import_frameworkcode` varchar(50) NOT NULL DEFAULT '' AFTER `nomatch_action` ; >+ }); >+ say $out "Added column 'import_batches.import_frameworkcode'"; >+ } >+ unless( column_exists("import_batch_profiles","overlay_frameworkcode") ){ >+ $dbh->do(q{ >+ ALTER TABLE `import_batch_profiles` >+ ADD `overlay_frameworkcode` varchar(50) NOT NULL DEFAULT '' AFTER `overlay_action` ; >+ }); >+ say $out "Added column 'import_batch_profiles.overlay_frameworkcode'"; >+ } >+ unless( column_exists("import_batch_profiles","import_frameworkcode") ){ >+ $dbh->do(q{ >+ ALTER TABLE `import_batch_profiles` >+ ADD `import_frameworkcode` varchar(50) NOT NULL DEFAULT '' AFTER `nomatch_action` ; >+ }); >+ say $out "Added column 'import_batch_profiles.import_frameworkcode'"; >+ } >+ }, >+}; >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index c1f800fe7f..999b8c2275 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -3375,7 +3375,9 @@ CREATE TABLE `import_batch_profiles` ( > `matcher_id` int(11) DEFAULT NULL COMMENT 'the id of the match rule used (matchpoints.matcher_id)', > `template_id` int(11) DEFAULT NULL COMMENT 'the id of the marc modification template', > `overlay_action` varchar(50) DEFAULT NULL COMMENT 'how to handle duplicate records', >+ `overlay_frameworkcode` varchar(50) NOT NULL DEFAULT '', > `nomatch_action` varchar(50) DEFAULT NULL COMMENT 'how to handle records where no match is found', >+ `import_frameworkcode` varchar(50) NOT NULL DEFAULT '', > `item_action` varchar(50) DEFAULT NULL COMMENT 'what to do with item records', > `parse_items` tinyint(1) DEFAULT NULL COMMENT 'should items be parsed', > `record_type` varchar(50) DEFAULT NULL COMMENT 'type of record in the batch', >@@ -3403,7 +3405,9 @@ CREATE TABLE `import_batches` ( > `num_items` int(11) NOT NULL DEFAULT 0 COMMENT 'number of items in the file', > `upload_timestamp` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'date and time the file was uploaded', > `overlay_action` enum('replace','create_new','use_template','ignore') NOT NULL DEFAULT 'create_new' COMMENT 'how to handle duplicate records', >+ `overlay_frameworkcode` varchar(50) NOT NULL DEFAULT '', > `nomatch_action` enum('create_new','ignore') NOT NULL DEFAULT 'create_new' COMMENT 'how to handle records where no match is found', >+ `import_frameworkcode` varchar(50) NOT NULL DEFAULT '', > `item_action` enum('always_add','add_only_for_matches','add_only_for_new','ignore','replace') NOT NULL DEFAULT 'always_add' COMMENT 'what to do with item records', > `import_status` enum('staging','staged','importing','imported','reverting','reverted','cleaned') NOT NULL DEFAULT 'staging' COMMENT 'the status of the imported file', > `batch_type` enum('batch','z3950','webservice') NOT NULL DEFAULT 'batch' COMMENT 'where this batch has come from', >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 e11c2611a1..a122ce87b4 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 >@@ -245,6 +245,31 @@ > [% ELSE %] > <input type ="hidden" name="item_action" value="ignore"> > [% END %] >+ [% IF ( !can_commit ) %] >+ <li> >+ <span class="label">New record framework: </span> >+ [% SET framework_text = "Default" %] >+ [% FOREACH framework IN frameworks %] >+ [% IF import_frameworkcode == framework.frameworkcode %] >+ [% SET framework_text = framework.frameworktext %] >+ [% END %] >+ [% END %] >+ <span>[% framework_text | html %]</span> >+ </li> >+ <li> >+ <span class="label">Replacement record framework: </span> >+ [% SET overlay_framework_text = "Default" %] >+ [% FOREACH framework IN frameworks %] >+ [% IF overlay_frameworkcode == framework.frameworkcode %] >+ [% SET overlay_framework_text = framework.frameworktext %] >+ [% END %] >+ [% END %] >+ [% IF overlay_frameworkcode == "_USE_ORIG_" %] >+ [% SET overlay_framework_text = "Keep original framework" %] >+ [% END %] >+ <span>[% overlay_framework_text | html %]</span> >+ </li> >+ [% END %] > </ol> > [% IF ( can_commit ) %] > <fieldset class="action"><input type="submit" class="btn btn-primary" value="Apply different matching rules" /></fieldset> >@@ -265,7 +290,11 @@ > <select name="framework" id="frameworks"> > <option value="">Default</option> > [% FOREACH framework IN frameworks %] >- <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option> >+ [% IF import_frameworkcode == framework.frameworkcode %] >+ <option value="[% framework.frameworkcode | html %]" selected = "selected">[% framework.frameworktext | html %]</option> >+ [% ELSE %] >+ <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option> >+ [% END %] > [% END %] > </select> > <div class="hint">New bibliographic records will use this framework</div> >@@ -273,10 +302,23 @@ > <li> > <label for="overlay_framework">Replacement record framework:</label> > <select name="overlay_framework" id="overlay_frameworks"> >+ [% IF overlay_frameworkcode == "_USE_ORIG_" %] >+ <option value="_USE_ORIG_" selected="selected">Keep original framework</option> >+ [% ELSE %] > <option value="_USE_ORIG_">Keep original framework</option> >+ [% END %] >+ >+ [% IF overlay_frameworkcode == "" %] >+ <option value="" selected="selected">Default</option> >+ [% ELSE %] > <option value="">Default</option> >+ [% END %] > [% FOREACH framework IN frameworks %] >- <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option> >+ [% IF overlay_frameworkcode == framework.frameworkcode %] >+ <option value="[% framework.frameworkcode | html %]" selected="selected">[% framework.frameworktext | html %]</option> >+ [% ELSE %] >+ <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option> >+ [% END %] > [% END %] > </select> > <div class="hint">Replacement records will use this framework</div> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt >index 5da5e4e88a..22c425ee54 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt >@@ -160,6 +160,15 @@ > [% END %] > </select> > </li> >+ <li> >+ <label for="import_frameworkcode">Add new bibliographic records into this framework:</label> >+ <select name="import_frameworkcode" id="import_frameworkcode"> >+ <option value="">Default</option> >+ [% FOREACH framework IN frameworks %] >+ <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option> >+ [% END %] >+ </select> >+ </li> > </ol></fieldset> > > [% IF MarcModificationTemplatesLoop %] >@@ -193,6 +202,16 @@ > <li><label for="overlay_action">Action if matching record found: </label> > [% INCLUDE 'tools-overlay-action.inc' %] > </li> >+ <li> >+ <label for="overlay_frameworkcode">When replacing records use this framework:</label> >+ <select name="overlay_frameworkcode" id="overlay_frameworkcode"> >+ <option value="_USE_ORIG_">Keep original framework</option> >+ <option value="">Default</option> >+ [% FOREACH framework IN frameworks %] >+ <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option> >+ [% END %] >+ </select> >+ </li> > <li><label for="nomatch_action">Action if no match is found: </label> > [% INCLUDE 'tools-nomatch-action.inc' %] > </li> >@@ -298,7 +317,9 @@ > $("#marc_modification_template_id").val("").change(); > $("#matcher").val("").change(); > $("#overlay_action").val('replace').change(); >+ $("#overlay_frameworkcode").val('').change(); > $("#nomatch_action").val('create_new').change(); >+ $("#import_frameworkcode").val('').change(); > $("#parse_itemsyes").prop("checked", true).change(); > $("#item_action").val('always_add').change(); > $("#profile_name").val('').keyup(); >@@ -315,7 +336,9 @@ > $("#marc_modification_template_id").val(profile.template_id).change(); > $("#matcher").val(profile.matcher_id).change(); > $("#overlay_action").val(profile.overlay_action).change(); >+ $("#overlay_frameworkcode").val(profile.overlay_frameworkcode).change(); > $("#nomatch_action").val(profile.nomatch_action).change(); >+ $("#import_frameworkcode").val(profile.import_frameworkcode).change(); > $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change(); > $("#item_action").val(profile.item_action).change(); > $("#profile_name").val(profile.name).keyup(); >@@ -358,7 +381,9 @@ > template_id: $("#marc_modification_template_id").val() || null, > matcher_id: $("#matcher").val() || null, > overlay_action: $("#overlay_action").val() || null, >+ overlay_frameworkcode: $("#overlay_frameworkcode").val() || "", > nomatch_action: $("#nomatch_action").val() || null, >+ import_frameworkcode: $("#import_frameworkcode").val() || "", > parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null, > item_action: $("#item_action").val() || null, > name: name >diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl >index e74d9255ab..0a4310c2b4 100755 >--- a/tools/manage-marc-import.pl >+++ b/tools/manage-marc-import.pl >@@ -285,10 +285,13 @@ sub batch_info { > $template->param(profile => $batch->{'profile'}); > $template->param(comments => $batch->{'comments'}); > $template->param(import_status => $batch->{'import_status'}); >+ $template->param(import_frameworkcode => $batch->{'import_frameworkcode'}); >+ $template->param(overlay_frameworkcode => $batch->{'overlay_frameworkcode'}); > $template->param(upload_timestamp => $batch->{'upload_timestamp'}); > $template->{VARS}->{'record_type'} = $batch->{'record_type'}; > $template->param(num_records => $batch->{'num_records'}); > $template->param(num_items => $batch->{'num_items'}); >+ $template->param(batch => $batch); > if ($batch->{'import_status'} ne 'cleaned') { > $template->param(can_clean => 1); > } >diff --git a/tools/stage-marc-import.pl b/tools/stage-marc-import.pl >index 2fe21b1a23..2b36d2b3b4 100755 >--- a/tools/stage-marc-import.pl >+++ b/tools/stage-marc-import.pl >@@ -42,13 +42,16 @@ use C4::MarcModificationTemplates qw( GetModificationTemplates ); > use Koha::Plugins; > use Koha::ImportBatches; > use Koha::BackgroundJob::StageMARCForImport; >+use Koha::BiblioFrameworks; > > my $input = CGI->new; > > my $fileID = $input->param('uploadedfileid'); > my $matcher_id = $input->param('matcher'); > my $overlay_action = $input->param('overlay_action'); >+my $overlay_frameworkcode = $input->param('overlay_frameworkcode'); > my $nomatch_action = $input->param('nomatch_action'); >+my $import_frameworkcode = $input->param('import_frameworkcode'); > my $parse_items = $input->param('parse_items'); > my $item_action = $input->param('item_action'); > my $comments = $input->param('comments'); >@@ -70,9 +73,12 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > } > ); > >+my $frameworks = Koha::BiblioFrameworks->search({ tagfield => { 'not' => undef } }, { join => 'marc_tag_structure', distinct => 'frameworkcode', order_by => ['frameworktext'] }); >+ > $template->param( > basketno => $basketno, > booksellerid => $booksellerid, >+ frameworks => $frameworks, > ); > > if ($fileID) { >@@ -91,10 +97,13 @@ if ($fileID) { > parse_items => $parse_items, > matcher_id => $matcher_id, > overlay_action => $overlay_action, >+ overlay_frameworkcode => $overlay_frameworkcode, > nomatch_action => $nomatch_action, >+ import_frameworkcode => $import_frameworkcode, > item_action => $item_action, > basket_id => $basketno, > vendor_id => $booksellerid, >+ profile_id => $profile_id, > }; > try { > my $job_id = Koha::BackgroundJob::StageMARCForImport->new->enqueue( $params ); >-- >2.30.2
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 33605
:
150203
| 155320 |
155321