From 1ac08751a972ac9e328faa6a8652d94bb9c90901 Mon Sep 17 00:00:00 2001 From: Sam Lau 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 %] [% END %] + [% IF ( !can_commit ) %] +
  • + New record framework: + [% SET framework_text = "Default" %] + [% FOREACH framework IN frameworks %] + [% IF import_frameworkcode == framework.frameworkcode %] + [% SET framework_text = framework.frameworktext %] + [% END %] + [% END %] + [% framework_text | html %] +
  • +
  • + Replacement record framework: + [% 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 %] + [% overlay_framework_text | html %] +
  • + [% END %] [% IF ( can_commit ) %]
    @@ -265,7 +290,11 @@
    New bibliographic records will use this framework
    @@ -273,10 +302,23 @@
  • Replacement records will use this framework
    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 %]
  • +
  • + + +
  • [% IF MarcModificationTemplatesLoop %] @@ -193,6 +202,16 @@
  • [% INCLUDE 'tools-overlay-action.inc' %]
  • +
  • + + +
  • [% INCLUDE 'tools-nomatch-action.inc' %]
  • @@ -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