Bugzilla – Attachment 108030 Details for
Bug 22417
Add a task queue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22417: Adapt the batch_record_modification tool
Bug-22417-Adapt-the-batchrecordmodification-tool.patch (text/plain), 16.24 KB, created by
David Cook
on 2020-08-11 08:17:47 UTC
(
hide
)
Description:
Bug 22417: Adapt the batch_record_modification tool
Filename:
MIME Type:
Creator:
David Cook
Created:
2020-08-11 08:17:47 UTC
Size:
16.24 KB
patch
obsolete
>From e89d8b056853806f5e48ea8764f29237b687bdba Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 25 Feb 2019 21:46:01 -0300 >Subject: [PATCH] Bug 22417: Adapt the batch_record_modification tool > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: David Cook <dcook@prosentient.com.au> >--- > .../prog/en/modules/admin/background_jobs.tt | 15 +++ > .../en/modules/tools/batch_record_modification.tt | 52 ++------ > tools/batch_record_modification.pl | 131 +++------------------ > 3 files changed, 38 insertions(+), 160 deletions(-) > >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 5d42f4ad08..098b7a3239 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 >@@ -76,6 +76,21 @@ > Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblionumber | uri %]">[% m.biblionumber | html %]</a> has not been modified. An error occurred on modifying it. > [% CASE 'biblio_modified' %] > Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblionumber | uri %]">[% m.biblionumber | html %]</a> has successfully been modified. >+ <h3>Next steps</h3> >+ <ul> >+ <li><a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a> >+ [% IF lists.count %] >+ <li> >+ <label for="add_bibs_to_list">Add modified records to the following list: </label> >+ <select name="add_bibs_to_list" id="add_bibs_to_list"> >+ <option value="">Select a list</option> >+ [% FOREACH list IN lists %] >+ <option class="shelf" value="[% list.shelfnumber | html %]">[% list.shelfname | html %]</option> >+ [% END %] >+ </select> >+ </li> >+ [% END %] >+ </ul> > [% END %] > </div> > [% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt >index 66de6f4b1c..dfa649eaa6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt >@@ -42,12 +42,8 @@ > Bibliographic record [% message.biblionumber | html %] does not exist in the database. > [% ELSIF message.code == 'authority_not_exists' %] > Authority record [% message.authid | html %] does not exist in the database. >- [% ELSIF message.code == 'biblio_not_modified' %] >- Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% message.biblionumber | uri %]">[% message.biblionumber | html %]</a> has not been modified. An error occurred on modifying it. > [% ELSIF message.code == 'authority_not_modified' %] > Authority record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% message.authid | uri %]">[% message.authid | html %]</a> has not been modified. An error occurred on modifying it. >- [% ELSIF message.code == 'biblio_modified' %] >- Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% message.biblionumber | uri %]">[% message.biblionumber | html %]</a> has successfully been modified. > [% ELSIF message.code == 'authority_modified' %] > Bibliographic record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% message.authid | uri %]">[% message.authid | html %]</a> has successfully been modified. > [% END %] >@@ -147,7 +143,7 @@ > </form> <!-- /#record_ids_selection --> > [% ELSIF view == 'list' %] > [% IF records %] >- <form action="/cgi-bin/koha/tools/batch_record_modification.pl" method="post" id="process"> >+ <form action="/cgi-bin/koha/tools/batch_record_modification.pl" method="post"> > <label for="marc_modification_template_id" class="required">Modify record using the following template: </label> > <select name="marc_modification_template_id" id="marc_modification_template_id" required="required"> > <option value="">Select a template</option> >@@ -233,49 +229,14 @@ > <fieldset class="action"> > <input type="hidden" name="op" value="modify" /> > <input type="hidden" name="recordtype" value="[% recordtype | html %]" /> >- <input type="button" id="mainformsubmit" value="Modify selected records" class="button" /> >- <input type="hidden" name="runinbackground" id="runinbackground" value="" /> >- <input type="hidden" name="completedJobID" id="completedJobID" value="" /> >- <a class="cancel" href="/cgi-bin/koha/tools/batch_record_modification.pl">Cancel</a> >+ <input type="submit" id="mainformsubmit" value="Modify selected records" class="button" /> > </fieldset> >- <div id="jobpanel"> >- <div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div> >- <div id="jobfailed"></div> >- </div> > </form> <!-- /#process --> > [% ELSE %] > <div class="dialog message"> > No records were modified. [% IF recordtype != 'biblio' %]<a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>[% END %] > </div> > [% END %] >- [% ELSIF view == 'report' %] >- [% IF report.total_records == report.total_success %] >- <div class="dialog message"> >- All records have successfully been modified! [% IF recordtype != 'biblio' %]<a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>[% END %] >- </div> >- [% ELSE %] >- <div class="dialog message"> >- [% report.total_success | html %] / [% report.total_records | html %] records have successfully been modified. Some errors occurred. <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a> >- </div> >- [% END %] >- >- [% IF recordtype == 'biblio' %] >- <h3>Next steps</h3> >- <ul> >- <li><a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a> >- [% IF lists.count %] >- <li> >- <label for="add_bibs_to_list">Add modified records to the following list: </label> >- <select name="add_bibs_to_list" id="add_bibs_to_list"> >- <option value="">Select a list</option> >- [% FOREACH list IN lists %] >- <option class="shelf" value="[% list.shelfnumber | html %]">[% list.shelfname | html %]</option> >- [% END %] >- </select> >- </li> >- [% END %] >- </ul> >- [% END %] > [% ELSIF view == 'errors' %] > [% FOR error IN errors %] > [% IF error == 'no_template_defined' %] >@@ -284,6 +245,12 @@ > </div> > [% END %] > [% END %] >+ [% ELSIF view == 'enqueued' %] >+ <div class="dialog message"> >+ The job has been enqueued! It will be processed as soon as possible (FIXME - well, it could depend on a config?) >+ <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> >+ | <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a> >+ </div> > [% ELSE %] > <div class="dialog alert"> > No action defined for the template. >@@ -291,7 +258,6 @@ > [% END %] > </main> > </div> <!-- /.col-sm-10.col-sm-push-2 --> >- > <div class="col-sm-2 col-sm-pull-10"> > <aside> > [% INCLUDE 'tools-menu.inc' %] >@@ -356,7 +322,7 @@ > alert(_("Please select a modification template.")); > return false; > } >- return submitBackgroundJob(document.getElementById("process")); >+ return true; > }); > > $("#record_ids_selection").on("submit", function(e) { >diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl >index 0203b0bb69..d0f017674b 100755 >--- a/tools/batch_record_modification.pl >+++ b/tools/batch_record_modification.pl >@@ -22,15 +22,17 @@ use Modern::Perl; > > use CGI; > use List::MoreUtils qw( uniq ); >+use JSON qw( encode_json ); >+use Net::RabbitFoot; > > use C4::Auth qw( get_template_and_user ); > use C4::Output qw( output_html_with_http_headers ); > use C4::AuthoritiesMarc qw( BuildSummary ModAuthority ); >-use C4::BackgroundJob; > use C4::Biblio qw( GetMarcBiblio ModBiblio ); >-use C4::MarcModificationTemplates qw( GetModificationTemplateActions GetModificationTemplates ModifyRecordWithTemplate ); >+use C4::MarcModificationTemplates qw( GetModificationTemplateActions GetModificationTemplates ); > > use Koha::Biblios; >+use Koha::BackgroundJob::BatchUpdateBiblio; > use Koha::MetadataRecord::Authority; > use Koha::Virtualshelves; > >@@ -54,23 +56,6 @@ $template->param( lists => scalar Koha::Virtualshelves->search([{ category => 1, > > my $sessionID = $input->cookie("CGISESSID"); > >-my $runinbackground = $input->param('runinbackground'); >-my $completedJobID = $input->param('completedJobID'); >-if ( $completedJobID ) { >- my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID); >- my $report = $job->get('report'); >- my $messages = $job->get('messages'); >- $template->param( >- report => $report, >- messages => $messages, >- view => 'report', >- recordtype => $recordtype, >- ); >- output_html_with_http_headers $input, $cookie, $template->output; >- $job->clear(); >- exit; >-} >- > my @templates = GetModificationTemplates( $mmtid ); > unless ( @templates ) { > $op = 'error'; >@@ -166,105 +151,17 @@ if ( $op eq 'form' ) { > # We want to modify selected records! > my @record_ids = $input->multi_param('record_id'); > >- my ( $job ); >- if ( $runinbackground ) { >- my $job_size = scalar( @record_ids ); >- $job = C4::BackgroundJob->new( $sessionID, "FIXME", '/cgi-bin/koha/tools/batch_record_modification.pl', $job_size ); >- my $job_id = $job->id; >- if (my $pid = fork) { >- $dbh->{InactiveDestroy} = 1; >- >- my $reply = CGI->new(""); >- print $reply->header(-type => 'text/html'); >- print '{"jobID":"' . $job_id . '"}'; >- exit 0; >- } elsif (defined $pid) { >- close STDOUT; >- } else { >- warn "fork failed while attempting to run tools/batch_record_modification.pl as a background job"; >- exit 0; >+ my $job_id = Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue( >+ { >+ mmtid => $mmtid, >+ record_type => $recordtype, >+ record_ids => \@record_ids, > } >- } >- >- my $report = { >- total_records => 0, >- total_success => 0, >- }; >- my $progress = 0; >- $dbh->{RaiseError} = 1; >- RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { >- $report->{total_records}++; >- next unless $record_id; >- >- if ( $recordtype eq 'biblio' ) { >- # Biblios >- my $biblionumber = $record_id; >- >- # Finally, modify the biblio >- my $error = eval { >- my $record = GetMarcBiblio({ biblionumber => $biblionumber }); >- ModifyRecordWithTemplate( $mmtid, $record ); >- my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber ); >- ModBiblio( $record, $biblionumber, $frameworkcode ); >- }; >- if ( $error and $error != 1 or $@ ) { # ModBiblio returns 1 if everything as gone well >- push @messages, { >- type => 'error', >- code => 'biblio_not_modified', >- biblionumber => $biblionumber, >- error => ($@ ? $@ : $error), >- }; >- } else { >- push @messages, { >- type => 'success', >- code => 'biblio_modified', >- biblionumber => $biblionumber, >- }; >- $report->{total_success}++; >- } >- } else { >- # Authorities >- my $authid = $record_id; >- my $error = eval { >- my $authority = Koha::MetadataRecord::Authority->get_from_authid( $authid ); >- my $record = $authority->record; >- ModifyRecordWithTemplate( $mmtid, $record ); >- ModAuthority( $authid, $record, $authority->authtypecode ); >- }; >- if ( $error and $error != $authid or $@ ) { >- push @messages, { >- type => 'error', >- code => 'authority_not_modified', >- authid => $authid, >- error => ($@ ? $@ : 0), >- }; >- } else { >- push @messages, { >- type => 'success', >- code => 'authority_modified', >- authid => $authid, >- }; >- $report->{total_success}++; >- } >- } >- >- $job->set({ >- view => 'report', >- report => $report, >- messages => \@messages, >- }); >- $job->progress( ++$progress ) if $runinbackground; >- } >- >- if ($runinbackground) { >- $job->finish if defined $job; >- } else { >- $template->param( >- view => 'report', >- report => $report, >- messages => \@messages, >- ); >- } >+ ); >+ $template->param( >+ view => 'enqueued', >+ job_id => $job_id, >+ ); > } > > $template->param( >-- >2.11.0
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 22417
:
105542
|
105543
|
107385
|
107386
|
107387
|
107388
|
107389
|
107390
|
107391
|
107392
|
107393
|
107394
|
107395
|
107396
|
107397
|
107398
|
107399
|
107400
|
107401
|
107402
|
107403
|
107404
|
107405
|
107406
|
107481
|
107482
|
107682
|
108023
|
108024
|
108025
|
108026
|
108027
|
108028
|
108029
|
108030
|
108031
|
108032
|
108033
|
108034
|
108035
|
108036
|
108037
|
108038
|
108039
|
108040
|
108041
|
108042
|
108043
|
108044
|
108045
|
108046
|
108047
|
109270
|
109271
|
109319
|
109320
|
109321
|
109322
|
109323
|
109324
|
109325
|
109326
|
109327
|
109328
|
109329
|
109330
|
109331
|
109332
|
109333
|
109334
|
109335
|
109336
|
109337
|
109338
|
109339
|
109340
|
109341
|
109342
|
109343
|
109344
|
109345
|
109350
|
109351
|
109355
|
109390
|
109391
|
109392
|
109393
|
109394
|
109395
|
109396
|
109397
|
109398
|
109399
|
109400
|
109401
|
109402
|
109403
|
109404
|
109405
|
109406
|
109407
|
109408
|
109409
|
109410
|
109411
|
109412
|
109413
|
109414
|
109415
|
109416
|
109417
|
109418
|
109474
|
109475
|
109476
|
109477
|
110150
|
111091
|
111092
|
111093
|
111094
|
111095
|
111096
|
111097
|
111098
|
111099
|
111100
|
111101
|
111102
|
111103
|
111104
|
111105
|
111106
|
111107
|
111108
|
111109
|
111110
|
111111
|
111112
|
111113
|
111114
|
111115
|
111116
|
111117
|
111118
|
111119
|
111120
|
111121
|
111238
|
111239
|
111245