Bugzilla – Attachment 138657 Details for
Bug 27421
Porting tools/stage-marc-import.pl to BackgroundJob
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27421: Commit and revert
Bug-27421-Commit-and-revert.patch (text/plain), 34.97 KB, created by
Jonathan Druart
on 2022-08-05 07:40:27 UTC
(
hide
)
Description:
Bug 27421: Commit and revert
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-08-05 07:40:27 UTC
Size:
34.97 KB
patch
obsolete
>From d15e87e439240096e55ad6d67cfdd50888cec09e Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 13 Jun 2022 16:15:36 +0200 >Subject: [PATCH] Bug 27421: Commit and revert > >--- > Koha/BackgroundJob.pm | 2 + > Koha/BackgroundJob/MARCImportCommitBatch.pm | 110 ++++++++++ > Koha/BackgroundJob/MARCImportRevertBatch.pm | 110 ++++++++++ > .../apache-shared-intranet-plack.conf | 1 - > .../marc_import_commit_batch.inc | 42 ++++ > .../marc_import_revert_batch.inc | 38 ++++ > .../background_jobs/stage_marc_for_import.inc | 3 + > .../prog/en/modules/admin/background_jobs.tt | 4 + > .../en/modules/tools/manage-marc-import.tt | 123 ++++------- > tools/manage-marc-import.pl | 201 ++++-------------- > 10 files changed, 398 insertions(+), 236 deletions(-) > create mode 100644 Koha/BackgroundJob/MARCImportCommitBatch.pm > create mode 100644 Koha/BackgroundJob/MARCImportRevertBatch.pm > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/marc_import_commit_batch.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/marc_import_revert_batch.inc > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >index b968eb23b0a..d146c38aad3 100644 >--- a/Koha/BackgroundJob.pm >+++ b/Koha/BackgroundJob.pm >@@ -407,6 +407,8 @@ sub core_types_to_classes { > update_elastic_index => 'Koha::BackgroundJob::UpdateElasticIndex', > update_holds_queue_for_biblios => 'Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue', > stage_marc_for_import => 'Koha::BackgroundJob::StageMARCForImport', >+ marc_import_commit_batch => 'Koha::BackgroundJob::MARCImportCommitBatch', >+ marc_import_revert_batch => 'Koha::BackgroundJob::MARCImportRevertBatch', > }; > } > >diff --git a/Koha/BackgroundJob/MARCImportCommitBatch.pm b/Koha/BackgroundJob/MARCImportCommitBatch.pm >new file mode 100644 >index 00000000000..3febc91b513 >--- /dev/null >+++ b/Koha/BackgroundJob/MARCImportCommitBatch.pm >@@ -0,0 +1,110 @@ >+package Koha::BackgroundJob::MARCImportCommitBatch; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Try::Tiny; >+ >+use base 'Koha::BackgroundJob'; >+ >+use C4::ImportBatch qw( >+ BatchCommitRecords >+); >+ >+=head1 NAME >+ >+Koha::BackgroundJob::MARCImportCommitBatch - Commit records >+ >+This is a subclass of Koha::BackgroundJob. >+ >+=head1 API >+ >+=head2 Class methods >+ >+=head3 job_type >+ >+Define the job type of this job: marc_import_commit_batch >+ >+=cut >+ >+sub job_type { >+ return 'marc_import_commit_batch'; >+} >+ >+=head3 process >+ >+Commit the records >+ >+=cut >+ >+sub process { >+ my ( $self, $args ) = @_; >+ >+ $self->start; >+ >+ my $import_batch_id = $args->{import_batch_id}; >+ my $frameworkcode = $args->{frameworkcode}; >+ >+ my @messages; >+ my $job_progress = 0; >+ >+ my ( $num_added, $num_updated, $num_items_added, >+ $num_items_replaced, $num_items_errored, $num_ignored ); >+ try { >+ ( >+ $num_added, $num_updated, $num_items_added, >+ $num_items_replaced, $num_items_errored, $num_ignored >+ ) >+ = BatchCommitRecords( $import_batch_id, $frameworkcode, 50, >+ sub { my $job_progress = shift; $self->progress( $job_progress )->store } ); >+ } >+ catch { >+ warn $_; >+ die "Something terrible has happened!" >+ if ( $_ =~ /Rollback failed/ ); # Rollback failed >+ }; >+ >+ my $report = { >+ 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 >+ }; >+ my $data = $self->decoded_data; >+ $data->{messages} = \@messages; >+ $data->{report} = $report; >+ >+ $self->finish($data); >+} >+ >+=head3 enqueue >+ >+Enqueue the new job >+ >+=cut >+ >+sub enqueue { >+ my ( $self, $args) = @_; >+ >+ $self->SUPER::enqueue({ >+ job_size => 0, # unknown for now >+ job_args => $args >+ }); >+} >+ >+1; >diff --git a/Koha/BackgroundJob/MARCImportRevertBatch.pm b/Koha/BackgroundJob/MARCImportRevertBatch.pm >new file mode 100644 >index 00000000000..a1cdaeb28b5 >--- /dev/null >+++ b/Koha/BackgroundJob/MARCImportRevertBatch.pm >@@ -0,0 +1,110 @@ >+package Koha::BackgroundJob::MARCImportRevertBatch; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Try::Tiny; >+ >+use base 'Koha::BackgroundJob'; >+ >+use C4::ImportBatch qw( >+ BatchRevertRecords >+); >+ >+=head1 NAME >+ >+Koha::BackgroundJob::MARCImportRevertBatch - Revert a batch >+ >+This is a subclass of Koha::BackgroundJob. >+ >+=head1 API >+ >+=head2 Class methods >+ >+=head3 job_type >+ >+Define the job type of this job: marc_import_revert_batch >+ >+=cut >+ >+sub job_type { >+ return 'marc_import_revert_batch'; >+} >+ >+=head3 process >+ >+Revert a batch >+ >+=cut >+ >+sub process { >+ my ( $self, $args ) = @_; >+ >+ $self->start; >+ >+ my $import_batch_id = $args->{import_batch_id}; >+ >+ my @messages; >+ my $job_progress = 0; >+ my ( >+ $num_deleted, $num_errors, $num_reverted, >+ $num_items_deleted, $num_ignored >+ ); >+ >+ try { >+ ( >+ $num_deleted, $num_errors, $num_reverted, >+ $num_items_deleted, $num_ignored >+ ) = BatchRevertRecords( $import_batch_id, 50, >+ sub { my $job_progress = shift; $self->progress( $job_progress )->store } ); >+ } >+ catch { >+ warn $_; >+ die "Something terrible has happened!" >+ if ( $_ =~ /Rollback failed/ ); # Rollback failed >+ }; >+ >+ my $report = { >+ num_deleted => $num_deleted, >+ num_items_deleted => $num_items_deleted, >+ num_errors => $num_errors, >+ num_reverted => $num_reverted, >+ num_ignored => $num_ignored, >+ }; >+ >+ my $data = $self->decoded_data; >+ $data->{messages} = \@messages; >+ $data->{report} = $report; >+ >+ $self->finish($data); >+} >+ >+=head3 enqueue >+ >+Enqueue the new job >+ >+=cut >+ >+sub enqueue { >+ my ( $self, $args) = @_; >+ >+ $self->SUPER::enqueue({ >+ job_size => 0, # unknown for now >+ job_args => $args >+ }); >+} >+ >+1; >diff --git a/debian/templates/apache-shared-intranet-plack.conf b/debian/templates/apache-shared-intranet-plack.conf >index 8428e03a50e..b09b62cb6ec 100644 >--- a/debian/templates/apache-shared-intranet-plack.conf >+++ b/debian/templates/apache-shared-intranet-plack.conf >@@ -14,7 +14,6 @@ > ProxyPass "/cgi-bin/koha/offline_circ/process_koc.pl" "!" > ProxyPass "/cgi-bin/koha/tools/background-job-progress.pl" "!" > ProxyPass "/cgi-bin/koha/tools/export.pl" "!" >- ProxyPass "/cgi-bin/koha/tools/manage-marc-import.pl" "!" > ProxyPass "/cgi-bin/koha/tools/upload-cover-image.pl" "!" > ProxyPass "/cgi-bin/koha/svc/cataloguing/metasearch" "!" > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/marc_import_commit_batch.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/marc_import_commit_batch.inc >new file mode 100644 >index 00000000000..ff32dbcc567 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/marc_import_commit_batch.inc >@@ -0,0 +1,42 @@ >+[% USE Koha %] >+ >+[% BLOCK report %] >+ [% SET report = job.report %] >+ [% IF report %] >+ <div class="dialog message">Completed import of records</div> >+ <table> >+ <tr> >+ <td>Number of records added</td> >+ <td>[% report.num_added | html %]</td> >+ </tr> >+ <tr> >+ <td>Number of records updated</td> >+ <td>[% report.num_updated | html %]</td> >+ </tr> >+ <tr> >+ <td>Number of records ignored</td> >+ <td>[% report.num_ignored | html %]</td> >+ </tr> >+ [% IF ( report.record_type == 'biblio' ) %] >+ <tr> >+ <td>Number of items added</td> >+ <td>[% report.num_items_added | html %]</td> >+ </tr> >+ <tr> >+ <td>Number of items replaced</td> >+ <td>[% report.num_items_replaced | html %]</td> >+ </tr> >+ <tr> >+ <td>Number of items ignored because of duplicate barcode</td> >+ <td>[% report.num_items_errored | html %]</td> >+ </tr> >+ [% END %] >+ </table> >+ [% END %] >+[% END %] >+ >+[% BLOCK detail %] >+[% END %] >+ >+[% BLOCK js %] >+[% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/marc_import_revert_batch.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/marc_import_revert_batch.inc >new file mode 100644 >index 00000000000..2ad8117deda >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/marc_import_revert_batch.inc >@@ -0,0 +1,38 @@ >+[% USE Koha %] >+ >+[% BLOCK report %] >+ [% SET report = job.report %] >+ [% IF report %] >+ <div class="dialog message">Success: Import reversed</div> >+ <table> >+ <tr> >+ <td>Number of records deleted</td> >+ <td>[% report.num_deleted | html %]</td> >+ </tr> >+ [% IF ( report.record_type == 'biblio' ) %] >+ <tr> >+ <td>Number of items deleted</td> >+ <td>[% report.num_items_deleted | html %]</td> >+ </tr> >+ <tr> >+ <td>Number of records not deleted due to items on loan</td> >+ <td>[% report.num_errors | html %]</td> >+ </tr> >+ [% END %] >+ <tr> >+ <td>Number of records changed back</td> >+ <td>[% report.num_reverted | html %]</td> >+ </tr> >+ <tr> >+ <td>Number of records ignored</td> >+ <td>[% report.num_ignored | html %]</td> >+ </tr> >+ </table> >+ [% END %] >+[% END %] >+ >+[% BLOCK detail %] >+[% END %] >+ >+[% BLOCK js %] >+[% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/stage_marc_for_import.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/stage_marc_for_import.inc >index fdc845d5cd3..c28f7bcb4c1 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/stage_marc_for_import.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/stage_marc_for_import.inc >@@ -31,6 +31,9 @@ > <li>New label batch created: # [% report.label_batch | html %] </li> > [% END %] > </ul> >+ <p> >+ <a href="/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=[% report.import_batch_id | uri %]">View batch</a> >+ </p> > [% IF report.basketno && report.booksellerid %] > <p> > <a id="addtobasket" class="btn btn-default" href="/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=[% report.import_batch_id | html %]&basketno=[% report.basketno | html %]&booksellerid=[% report.booksellerid | html %]">Add staged files to basket</a> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >index 23b26c5be14..eb038bb041a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >@@ -43,6 +43,10 @@ > <span>Holds queue update</span> > [% CASE 'stage_marc_for_import' %] > <span>Staged MARC records for import</span> >+ [% CASE 'marc_import_commit_batch' %] >+ <span>Import MARC records</span> >+ [% CASE 'marc_import_revert_batch' %] >+ <span>Revert import MARC records</span> > [% CASE %]<span>Unknown job type '[% job_type | html %]'</span> > [% END %] > >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 7cac2154136..2efba77b096 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 >@@ -31,7 +31,7 @@ > </li> > [% IF ( import_batch_id ) %] > <li> >- <a href="[% script_name | url %]">Manage staged MARC records</a> >+ <a href="/cgi-bin/koha/tools/manage-marc-import.pl">Manage staged MARC records</a> > </li> > <li> > <a href="#" aria-current="page"> >@@ -57,8 +57,30 @@ > › Batch [% import_batch_id | html %] > [% END %] > </h1> >+ [% FOREACH message IN messages %] >+ [% IF message.type == 'success' %] >+ <div class="dialog message"> >+ [% ELSIF message.type == 'warning' %] >+ <div class="dialog alert"> >+ [% ELSIF message.type == 'error' %] >+ <div class="dialog alert" style="margin:auto;"> >+ [% END %] >+ [% IF message.code == 'cannot_enqueue_job' %] >+ <span>Cannot enqueue this job.</span> >+ [% END %] >+ [% IF message.error %] >+ <span>(The error was: [% message.error | html %], see the Koha log file for more information).</span> >+ [% END %] >+ </div> >+ [% END %] >+ >+ [% IF job_enqueued %] >+ <div class="dialog message"> >+ <p>The job has been enqueued! It will be processed as soon as possible.</p> >+ <p><a href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job_id | uri %]" title="View detail of the enqueued job">View detail of the enqueued job</a> >+ </div> > >- [% IF ( label_batch_msg ) %] >+ [% ELSIF ( label_batch_msg ) %] > [% IF ( alert ) %] > <div class="alert"> > [% ELSE %] >@@ -82,18 +104,16 @@ > <div class="dialog message">Import batch deleted successfully</div> > [% END %] > >- [% UNLESS ( batch_list ) %] >- [% UNLESS ( batch_info ) %] >- <div class="dialog message"> >- <p>No records have been staged.</p> >- <p><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>.</p> >- </div> >- [% END %] >+ [% UNLESS batch_list || batch_info || job_enqueued %] >+ <div class="dialog message"> >+ <p>No records have been staged.</p> >+ <p><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>.</p> >+ </div> > [% END %] > > [% IF ( batch_info ) %] > [% IF ( can_commit ) %] >- <form action="[% script_name | html %]" method="post"> >+ <form method="post"> > <input type="hidden" name="op" value="redo-matching" /> > <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" /> > <input type="hidden" name="current_matcher_id" value="[% current_matcher_id | html %]" /> >@@ -121,6 +141,7 @@ > <div class="dialog message">Changed item processing option</div> > [% END %] > >+ [% UNLESS job_enqueued %] > <fieldset class="rows" id="staged-record-matching-rules"> > <ol> > <li><span class="label">File name:</span> [% file_name | html %]</li> >@@ -236,7 +257,7 @@ > > <div> > [% IF ( can_commit ) %] >- <form action="[% script_name | html %]" method="post" id="import_batch_form"> >+ <form method="post" id="import_batch_form"> > <input type="hidden" name="op" value="commit-batch" /> > <input type="hidden" name="runinbackground" value="" /> > <input type="hidden" name="completedJobID" value="" /> >@@ -261,7 +282,7 @@ > </div> > [% END # /IF can_commit %] > [% IF ( can_revert ) %] >- <form action="[% script_name | html %]" method="post" id="revert_batch_form"> >+ <form method="post" id="revert_batch_form"> > <input type="hidden" name="op" value="revert-batch" /> > <input type="hidden" name="runinbackground" value="" /> > <input type="hidden" name="completedJobID" value="" /> >@@ -274,66 +295,7 @@ > </div> > [% END # /IF can_revert %] > </div> >- >- [% IF ( did_commit ) %] >- <div class="dialog message">Completed import of records</div> >- <table> >- <tr> >- <td>Number of records added</td> >- <td>[% num_added | html %]</td> >- </tr> >- <tr> >- <td>Number of records updated</td> >- <td>[% num_updated | html %]</td> >- </tr> >- <tr> >- <td>Number of records ignored</td> >- <td>[% num_ignored | html %]</td> >- </tr> >- [% IF ( record_type == 'biblio' ) %] >- <tr> >- <td>Number of items added</td> >- <td>[% num_items_added | html %]</td> >- </tr> >- <tr> >- <td>Number of items replaced</td> >- <td>[% num_items_replaced | html %]</td> >- </tr> >- <tr> >- <td>Number of items ignored because of duplicate barcode</td> >- <td>[% num_items_errored | html %]</td> >- </tr> >- [% END %] >- </table> >- [% END #/ IF did_commit %] >- >- [% IF ( did_revert ) %] >- <div class="dialog message">Success: Import reversed</div> >- <table> >- <tr> >- <td>Number of records deleted</td> >- <td>[% num_deleted | html %]</td> >- </tr> >- [% IF ( record_type == 'biblio' ) %] >- <tr> >- <td>Number of items deleted</td> >- <td>[% num_items_deleted | html %]</td> >- </tr> >- <tr> >- <td>Number of records not deleted due to items on loan</td> >- <td>[% num_errors | html %]</td> >- </tr> >- [% END %] >- <tr> >- <td>Number of records changed back</td> >- <td>[% num_reverted | html %]</td> >- </tr> >- <tr> >- <td>Number of records ignored</td> >- <td>[% num_ignored | html %]</td> >- </tr> >- </table> >- [% END # /IF did_revert%] >+ [% END %] > > [% END # /IF batch_info %] > >@@ -360,7 +322,7 @@ > [% FOREACH batch_lis IN batch_list %] > <tr> > <td>[% batch_lis.import_batch_id | html %]</td> >- <td><a href="[% batch_lis.script_name | url %]?import_batch_id=[% batch_lis.import_batch_id | uri %]">[% batch_lis.file_name | html %]</a></td> >+ <td><a href="?import_batch_id=[% batch_lis.import_batch_id | uri %]">[% batch_lis.file_name | html %]</a></td> > <td>[% batch_lis.profile | html %]</td> > <td>[% batch_lis.comments | html %]</td> > <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td> >@@ -385,12 +347,12 @@ > <td>[% batch_lis.num_records | html %]</td> > <td>[% batch_lis.num_items | html %] > [% IF ( batch_lis.num_items && batch_lis.import_status == 'imported' ) %] >- (<a href="[% batch_lis.script_name | url %]?import_batch_id=[% batch_lis.import_batch_id | uri %]&op=create_labels">Create label batch</a>) >+ (<a href="?import_batch_id=[% batch_lis.import_batch_id | uri %]&op=create_labels">Create label batch</a>) > [% END %] > </td> > <td class="actions"> > [% IF ( batch_lis.can_clean ) %] >- <form method="post" action="[% batch_lis.script_name | html %]" name="clean_batch_[% batch_lis.import_batch_id | html %]" id="clean_batch_[% batch_lis.import_batch_id | html %]" class="batch_form batch_clean"> >+ <form method="post" name="clean_batch_[% batch_lis.import_batch_id | html %]" id="clean_batch_[% batch_lis.import_batch_id | html %]" class="batch_form batch_clean"> > <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id | html %]" /> > <input type="hidden" name="op" value="clean-batch" /> > <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-eraser"></i> Clean</button> >@@ -457,7 +419,6 @@ > [% MACRO jsinclude BLOCK %] > [% Asset.js("js/tools-menu.js") | $raw %] > [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] >- [% Asset.js("js/background-job-progressbar.js") | $raw %] > [% INCLUDE 'datatables.inc' %] > <script> > $(document).ready(function() { >@@ -657,8 +618,8 @@ > <ul class="pagination"> > [% FOREACH page IN pages %] > [% IF ( page.current_page && page.page_number > 1 ) %] >- <li><a href="[% page.script_name | url %]?offset=0" class="nav"><i class="fa fa-fw fa-angle-double-left"></i> First</a></li> >- <li><a href="[% page.script_name | url %]?offset=[% offset - results_per_page | uri %]"><i class="fa fa-fw fa-angle-left"></i> Previous</a></li> >+ <li><a href="?offset=0" class="nav"><i class="fa fa-fw fa-angle-double-left"></i> First</a></li> >+ <li><a href="?offset=[% offset - results_per_page | uri %]"><i class="fa fa-fw fa-angle-left"></i> Previous</a></li> > [% END %] > [% END %] > [% FOREACH page IN pages %] >@@ -666,15 +627,15 @@ > [% SET current_page = page.page_number %] > <li class="active"><span class="current">[% page.page_number | html %]</span></li> > [% ELSE %] >- <li><a class="nav" href="[% page.script_name | url %]?offset=[% page.offset | uri %]">[% page.page_number | html %]</a></li> >+ <li><a class="nav" href="?offset=[% page.offset | uri %]">[% page.page_number | html %]</a></li> > [% END %] > [% END %] > [% IF ( current_page < pages.size() ) %] > <li> >- <a href="[% page.script_name | url %]?offset=[% offset + results_per_page | uri %]" class="nav">Next <i class="fa fa-fw fa-angle-right"></i></a> >+ <a href="?offset=[% offset + results_per_page | uri %]" class="nav">Next <i class="fa fa-fw fa-angle-right"></i></a> > </li> > <li> >- <a href="[% page.script_name | url %]?offset=[% ( results_per_page * ( pages.size - 1 ) ) | uri %]" class="nav">Last <i class="fa fa-fw fa-angle-double-right"></i></a> >+ <a href="?offset=[% ( results_per_page * ( pages.size - 1 ) ) | uri %]" class="nav">Last <i class="fa fa-fw fa-angle-double-right"></i></a> > </li> > [% END %] > </ul> >diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl >index 9ee6917be48..9c25ec08f24 100755 >--- a/tools/manage-marc-import.pl >+++ b/tools/manage-marc-import.pl >@@ -23,6 +23,7 @@ use Modern::Perl; > use CGI qw ( -utf8 ); > use CGI::Cookie; > use MARC::File::USMARC; >+use Try::Tiny; > > # Koha modules used > use C4::Context; >@@ -31,19 +32,18 @@ use C4::Auth qw( get_template_and_user ); > use C4::Output qw( output_html_with_http_headers ); > use C4::ImportBatch qw( CleanBatch DeleteBatch GetImportBatch GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction SetImportBatchOverlayAction SetImportBatchNoMatchAction SetImportBatchItemAction BatchFindDuplicates SetImportBatchMatcher GetItemNumbersFromImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches BatchCommitRecords BatchRevertRecords ); > use C4::Matcher; >-use C4::BackgroundJob; > use C4::Labels::Batch; > use Koha::BiblioFrameworks; >+use Koha::BackgroundJob::MARCImportCommitBatch; >+use Koha::BackgroundJob::MARCImportRevertBatch; > > use Koha::Logger; > >-my $script_name = "/cgi-bin/koha/tools/manage-marc-import.pl"; > > my $input = CGI->new; > my $op = $input->param('op') || ''; >-my $completedJobID = $input->param('completedJobID'); >-our $runinbackground = $input->param('runinbackground'); > my $import_batch_id = $input->param('import_batch_id') || ''; >+my @messages; > > # record list displays > my $offset = $input->param('offset') || 0; >@@ -56,10 +56,6 @@ my ($template, $loggedinuser, $cookie) > flagsrequired => {tools => 'manage_staged_marc'}, > }); > >-my %cookies = CGI::Cookie->fetch(); >-our $sessionID = $cookies{'CGISESSID'}->value; >-our $dbh = C4::Context->dbh; >- > my $frameworks = Koha::BiblioFrameworks->search({ tagfield => { 'not' => undef } }, { join => 'marc_tag_structure', distinct => 'frameworkcode', order_by => ['frameworktext'] }); > $template->param( frameworks => $frameworks ); > >@@ -79,10 +75,9 @@ if ($op eq "create_labels") { > $op=''; > $import_batch_id=''; > } >+ > if ($op) { >- $template->param(script_name => $script_name, $op => 1); >-} else { >- $template->param(script_name => $script_name); >+ $template->param($op => 1); > } > > if ($op eq "") { >@@ -93,20 +88,50 @@ if ($op eq "") { > import_records_list($template, $import_batch_id, $offset, $results_per_page); > } > } elsif ($op eq "commit-batch") { >- if ($completedJobID) { >- add_saved_job_results_to_template($template, $completedJobID); >- } else { >- my $framework = $input->param('framework'); >- commit_batch($template, $import_batch_id, $framework); >+ my $frameworkcode = $input->param('framework'); >+ try { >+ my $job_id = Koha::BackgroundJob::MARCImportCommitBatch->new->enqueue( >+ { >+ import_batch_id => $import_batch_id, >+ frameworkcode => $frameworkcode >+ } >+ ); >+ if ($job_id) { >+ $template->param( >+ job_enqueued => 1, >+ job_id => $job_id, >+ ); >+ } > } >- import_records_list($template, $import_batch_id, $offset, $results_per_page); >+ catch { >+ warn $_; >+ push @messages, >+ { >+ type => 'error', >+ code => 'cannot_enqueue_job', >+ error => $_, >+ }; >+ }; > } elsif ($op eq "revert-batch") { >- if ($completedJobID) { >- add_saved_job_results_to_template($template, $completedJobID); >- } else { >- revert_batch($template, $import_batch_id); >+ try { >+ my $job_id = Koha::BackgroundJob::MARCImportRevertBatch->new->enqueue( >+ { import_batch_id => $import_batch_id } ); >+ if ($job_id) { >+ $template->param( >+ job_enqueued => 1, >+ job_id => $job_id, >+ ); >+ } > } >- import_records_list($template, $import_batch_id, $offset, $results_per_page); >+ catch { >+ warn $_; >+ push @messages, >+ { >+ type => 'error', >+ code => 'cannot_enqueue_job', >+ error => $_, >+ }; >+ }; > } elsif ($op eq "clean-batch") { > CleanBatch($import_batch_id); > import_batches_list($template, $offset, $results_per_page); >@@ -228,138 +253,6 @@ sub import_batches_list { > > } > >-sub commit_batch { >- my ($template, $import_batch_id, $framework) = @_; >- >- my $job = undef; >- my ( $num_added, $num_updated, $num_items_added, >- $num_items_replaced, $num_items_errored, $num_ignored ); >- my $callback = sub { }; >- if ($runinbackground) { >- $job = put_in_background($import_batch_id); >- $callback = progress_callback( $job ); >- } >- ( >- $num_added, $num_updated, $num_items_added, >- $num_items_replaced, $num_items_errored, $num_ignored >- ) >- = BatchCommitRecords( $import_batch_id, $framework, 50, >- $callback ); >- >- my $results = { >- did_commit => 1, >- 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 >- }; >- if ($runinbackground) { >- $job->finish($results); >- } else { >- add_results_to_template($template, $results); >- } >-} >- >-sub revert_batch { >- my ($template, $import_batch_id) = @_; >- >- my $job = undef; >- my ( >- $num_deleted, $num_errors, $num_reverted, >- $num_items_deleted, $num_ignored >- ); >- my $schema = Koha::Database->new->schema; >- $schema->txn_do( >- sub { >- if ($runinbackground) { >- $job = put_in_background($import_batch_id); >- } >- ( >- $num_deleted, $num_errors, $num_reverted, >- $num_items_deleted, $num_ignored >- ) = BatchRevertRecords( $import_batch_id ); >- } >- ); >- >- my $results = { >- did_revert => 1, >- num_deleted => $num_deleted, >- num_items_deleted => $num_items_deleted, >- num_errors => $num_errors, >- num_reverted => $num_reverted, >- num_ignored => $num_ignored, >- }; >- if ($runinbackground) { >- $job->finish($results); >- } else { >- add_results_to_template($template, $results); >- } >-} >- >-sub put_in_background { >- my $import_batch_id = shift; >- >- my $batch = GetImportBatch($import_batch_id); >- my $job = C4::BackgroundJob->new($sessionID, $batch->{'file_name'}, '/cgi-bin/koha/tools/manage-marc-import.pl', $batch->{'num_records'}); >- my $jobID = $job->id(); >- >- # fork off >- if (my $pid = fork) { >- # parent >- # return job ID as JSON >- >- # prevent parent exiting from >- # destroying the kid's database handle >- # FIXME: according to DBI doc, this may not work for Oracle >- $dbh->{InactiveDestroy} = 1; >- >- my $reply = CGI->new(""); >- print $reply->header(-type => 'text/html'); >- print '{"jobID":"' . $jobID . '"}'; >- exit 0; >- } elsif (defined $pid) { >- # child >- # close STDOUT to signal to Apache that >- # we're now running in the background >- close STDOUT; >- close STDERR; >- $SIG{__WARN__} = sub { >- my ($msg) = @_; >- my $logger = Koha::Logger->get; >- $logger->warn($msg); >- } >- } else { >- # fork failed, so exit immediately >- warn "fork failed while attempting to run tools/manage-marc-import.pl as a background job"; >- exit 0; >- } >- return $job; >-} >- >-sub progress_callback { >- my $job = shift; >- return sub { >- my $progress = shift; >- $job->progress($progress); >- } >-} >- >-sub add_results_to_template { >- my $template = shift; >- my $results = shift; >- $template->param(map { $_ => $results->{$_} } keys %{ $results }); >-} >- >-sub add_saved_job_results_to_template { >- my $template = shift; >- my $completedJobID = shift; >- my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID); >- my $results = $job->results(); >- add_results_to_template($template, $results); >-} >- > sub import_records_list { > my ($template, $import_batch_id, $offset, $results_per_page) = @_; > >-- >2.25.1
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 27421
:
136127
|
136128
|
136129
|
136216
|
136217
|
136338
|
136339
|
138642
|
138643
|
138656
|
138657
|
138660
|
138881
|
139384
|
139385
|
139386
|
139387
|
139388
|
139448
|
139449
|
139450
|
139797
|
140205
|
140206
|
140207
|
140208
|
140223
|
140224
|
140225
|
140226
|
140227
|
140228
|
140229
|
140230
|
140231
|
140232
|
140233
|
140234
|
140759