From 5ab876ed5ae02405a86ca783961116b3369a5223 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 25 Apr 2023 13:15:12 +0000 Subject: [PATCH] Bug 33605: WIP TO DO: - make profiles save the info - pass frameowrks to scripts - make import form fetch values from DB for new fields - handle changing values after staging (do along with redoing matching?) - tests? --- Koha/BackgroundJob/StageMARCForImport.pm | 10 ++++++-- .../data/mysql/atomicupdate/bug_33605.pl | 24 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 2 ++ .../en/modules/tools/stage-marc-import.tt | 19 +++++++++++++++ tools/stage-marc-import.pl | 4 ++++ 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_33605.pl diff --git a/Koha/BackgroundJob/StageMARCForImport.pm b/Koha/BackgroundJob/StageMARCForImport.pm index 7858eae7a0..94743cae12 100644 --- a/Koha/BackgroundJob/StageMARCForImport.pm +++ b/Koha/BackgroundJob/StageMARCForImport.pm @@ -75,7 +75,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,9 +133,12 @@ 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; + } + if ($import_frameworkcode){ + $import_batch->set({ import_frameworkcode => $import_frameworkcode })->store; } if ($matcher_id) { @@ -148,6 +153,7 @@ sub process { SetImportBatchOverlayAction( $batch_id, $overlay_action ); SetImportBatchNoMatchAction( $batch_id, $nomatch_action ); SetImportBatchItemAction( $batch_id, $item_action ); + $import_batch->set({ overlay_frameworkcode => $overlay_frameworkcode })->store if $overlay_frameworkcode; $schema->storage->txn_commit; } else { diff --git a/installer/data/mysql/atomicupdate/bug_33605.pl b/installer/data/mysql/atomicupdate/bug_33605.pl new file mode 100755 index 0000000000..c88eb3f1cf --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_33605.pl @@ -0,0 +1,24 @@ +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(4) 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(4) NOT NULL DEFAULT '' AFTER `nomatch_action` ; + }); + say $out "Added column 'import_batches.import_frameworkcode'"; + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 50796112dc..5efc9a3fb2 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3349,7 +3349,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(4) 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(4) 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/stage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt index 0fe36f2ba4..112655cd08 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 @@ -171,6 +171,15 @@ [% END %] +
  • + Add new bibliographic records into this framework: + +
  • [% IF MarcModificationTemplatesLoop %] @@ -204,6 +213,16 @@
  • [% INCLUDE 'tools-overlay-action.inc' %]
  • +
  • + When replacing records use this framework: + +
  • [% INCLUDE 'tools-nomatch-action.inc' %]
  • diff --git a/tools/stage-marc-import.pl b/tools/stage-marc-import.pl index 2fe21b1a23..48348de05c 100755 --- a/tools/stage-marc-import.pl +++ b/tools/stage-marc-import.pl @@ -48,7 +48,9 @@ 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_framework'); my $nomatch_action = $input->param('nomatch_action'); +my $import_frameworkcode = $input->param('import_framework'); my $parse_items = $input->param('parse_items'); my $item_action = $input->param('item_action'); my $comments = $input->param('comments'); @@ -91,7 +93,9 @@ 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, -- 2.30.2