View | Details | Raw Unified | Return to bug 22417
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt (+15 lines)
Lines 76-81 Link Here
76
                                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.
76
                                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.
77
                            [% CASE 'biblio_modified' %]
77
                            [% CASE 'biblio_modified' %]
78
                                Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblionumber | uri %]">[% m.biblionumber | html %]</a> has successfully been modified.
78
                                Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblionumber | uri %]">[% m.biblionumber | html %]</a> has successfully been modified.
79
                                <h3>Next steps</h3>
80
                                <ul>
81
                                    <li><a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>
82
                                    [% IF lists.count %]
83
                                    <li>
84
                                        <label for="add_bibs_to_list">Add modified records to the following list: </label>
85
                                        <select name="add_bibs_to_list" id="add_bibs_to_list">
86
                                            <option value="">Select a list</option>
87
                                            [% FOREACH list IN lists %]
88
                                                <option class="shelf" value="[% list.shelfnumber | html %]">[% list.shelfname | html %]</option>
89
                                            [% END %]
90
                                        </select>
91
                                    </li>
92
                                    [% END %]
93
                                </ul>
79
                            [% END %]
94
                            [% END %]
80
                        </div>
95
                        </div>
81
                    [% END %]
96
                    [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt (-43 / +9 lines)
Lines 42-53 Link Here
42
                                    Bibliographic record [% message.biblionumber | html %] does not exist in the database.
42
                                    Bibliographic record [% message.biblionumber | html %] does not exist in the database.
43
                                [% ELSIF message.code == 'authority_not_exists' %]
43
                                [% ELSIF message.code == 'authority_not_exists' %]
44
                                    Authority record [% message.authid | html %] does not exist in the database.
44
                                    Authority record [% message.authid | html %] does not exist in the database.
45
                                [% ELSIF message.code == 'biblio_not_modified' %]
46
                                    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.
47
                                [% ELSIF message.code == 'authority_not_modified' %]
45
                                [% ELSIF message.code == 'authority_not_modified' %]
48
                                    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.
46
                                    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.
49
                                [% ELSIF message.code == 'biblio_modified' %]
50
                                    Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% message.biblionumber | uri %]">[% message.biblionumber | html %]</a> has successfully been modified.
51
                                [% ELSIF message.code == 'authority_modified' %]
47
                                [% ELSIF message.code == 'authority_modified' %]
52
                                    Bibliographic record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% message.authid | uri %]">[% message.authid | html %]</a> has successfully been modified.
48
                                    Bibliographic record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% message.authid | uri %]">[% message.authid | html %]</a> has successfully been modified.
53
                                [% END %]
49
                                [% END %]
Lines 147-153 Link Here
147
                        </form> <!-- /#record_ids_selection -->
143
                        </form> <!-- /#record_ids_selection -->
148
                    [% ELSIF view == 'list' %]
144
                    [% ELSIF view == 'list' %]
149
                        [% IF records %]
145
                        [% IF records %]
150
                            <form action="/cgi-bin/koha/tools/batch_record_modification.pl" method="post" id="process">
146
                            <form action="/cgi-bin/koha/tools/batch_record_modification.pl" method="post">
151
                                <label for="marc_modification_template_id" class="required">Modify record using the following template: </label>
147
                                <label for="marc_modification_template_id" class="required">Modify record using the following template: </label>
152
                                <select name="marc_modification_template_id" id="marc_modification_template_id" required="required">
148
                                <select name="marc_modification_template_id" id="marc_modification_template_id" required="required">
153
                                    <option value="">Select a template</option>
149
                                    <option value="">Select a template</option>
Lines 233-281 Link Here
233
                                <fieldset class="action">
229
                                <fieldset class="action">
234
                                    <input type="hidden" name="op" value="modify" />
230
                                    <input type="hidden" name="op" value="modify" />
235
                                    <input type="hidden" name="recordtype" value="[% recordtype | html %]" />
231
                                    <input type="hidden" name="recordtype" value="[% recordtype | html %]" />
236
                                    <input type="button" id="mainformsubmit" value="Modify selected records" class="button" />
232
                                    <input type="submit" id="mainformsubmit" value="Modify selected records" class="button" />
237
                                    <input type="hidden" name="runinbackground" id="runinbackground" value="" />
238
                                    <input type="hidden" name="completedJobID" id="completedJobID" value="" />
239
                                    <a class="cancel" href="/cgi-bin/koha/tools/batch_record_modification.pl">Cancel</a>
240
                                </fieldset>
233
                                </fieldset>
241
                                <div id="jobpanel">
242
                                    <div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
243
                                    <div id="jobfailed"></div>
244
                                </div>
245
                            </form> <!-- /#process -->
234
                            </form> <!-- /#process -->
246
                        [% ELSE %]
235
                        [% ELSE %]
247
                            <div class="dialog message">
236
                            <div class="dialog message">
248
                                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 %]
237
                                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 %]
249
                            </div>
238
                            </div>
250
                        [% END %]
239
                        [% END %]
251
                    [% ELSIF view == 'report' %]
252
                        [% IF report.total_records == report.total_success %]
253
                            <div class="dialog message">
254
                                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 %]
255
                            </div>
256
                        [% ELSE %]
257
                            <div class="dialog message">
258
                                [% 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>
259
                            </div>
260
                        [% END %]
261
262
                        [% IF recordtype == 'biblio' %]
263
                            <h3>Next steps</h3>
264
                            <ul>
265
                                <li><a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>
266
                                [% IF lists.count %]
267
                                <li>
268
                                    <label for="add_bibs_to_list">Add modified records to the following list: </label>
269
                                    <select name="add_bibs_to_list" id="add_bibs_to_list">
270
                                        <option value="">Select a list</option>
271
                                        [% FOREACH list IN lists %]
272
                                            <option class="shelf" value="[% list.shelfnumber | html %]">[% list.shelfname | html %]</option>
273
                                        [% END %]
274
                                    </select>
275
                                </li>
276
                                [% END %]
277
                            </ul>
278
                        [% END %]
279
                    [% ELSIF view == 'errors' %]
240
                    [% ELSIF view == 'errors' %]
280
                        [% FOR error IN errors %]
241
                        [% FOR error IN errors %]
281
                            [% IF error == 'no_template_defined' %]
242
                            [% IF error == 'no_template_defined' %]
Lines 284-289 Link Here
284
                                </div>
245
                                </div>
285
                            [% END %]
246
                            [% END %]
286
                        [% END %]
247
                        [% END %]
248
                     [% ELSIF view == 'enqueued' %]
249
                        <div class="dialog message">
250
                            The job has been enqueued! It will be processed as soon as possible (FIXME - well, it could depend on a config?)
251
                            <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>
252
                            | <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>
253
                        </div>
287
                    [% ELSE %]
254
                    [% ELSE %]
288
                        <div class="dialog alert">
255
                        <div class="dialog alert">
289
                            No action defined for the template.
256
                            No action defined for the template.
Lines 291-297 Link Here
291
                    [% END %]
258
                    [% END %]
292
                </main>
259
                </main>
293
            </div> <!-- /.col-sm-10.col-sm-push-2 -->
260
            </div> <!-- /.col-sm-10.col-sm-push-2 -->
294
295
            <div class="col-sm-2 col-sm-pull-10">
261
            <div class="col-sm-2 col-sm-pull-10">
296
                <aside>
262
                <aside>
297
                    [% INCLUDE 'tools-menu.inc' %]
263
                    [% INCLUDE 'tools-menu.inc' %]
Lines 362-368 Link Here
362
                    alert(_("Please select a modification template."));
328
                    alert(_("Please select a modification template."));
363
                    return false;
329
                    return false;
364
                }
330
                }
365
                return submitBackgroundJob(document.getElementById("process"));
331
                return true;
366
            });
332
            });
367
333
368
            $("#record_ids_selection").on("submit", function(e) {
334
            $("#record_ids_selection").on("submit", function(e) {
(-)a/tools/batch_record_modification.pl (-118 / +14 lines)
Lines 22-36 use Modern::Perl; Link Here
22
22
23
use CGI;
23
use CGI;
24
use List::MoreUtils qw( uniq );
24
use List::MoreUtils qw( uniq );
25
use JSON qw( encode_json );
26
use Net::RabbitFoot;
25
27
26
use C4::Auth qw( get_template_and_user );
28
use C4::Auth qw( get_template_and_user );
27
use C4::Output qw( output_html_with_http_headers );
29
use C4::Output qw( output_html_with_http_headers );
28
use C4::AuthoritiesMarc qw( BuildSummary ModAuthority );
30
use C4::AuthoritiesMarc qw( BuildSummary ModAuthority );
29
use C4::BackgroundJob;
30
use C4::Biblio qw( GetMarcBiblio ModBiblio );
31
use C4::Biblio qw( GetMarcBiblio ModBiblio );
31
use C4::MarcModificationTemplates qw( GetModificationTemplateActions GetModificationTemplates ModifyRecordWithTemplate );
32
use C4::MarcModificationTemplates qw( GetModificationTemplateActions GetModificationTemplates );
32
33
33
use Koha::Biblios;
34
use Koha::Biblios;
35
use Koha::BackgroundJob::BatchUpdateBiblio;
34
use Koha::MetadataRecord::Authority;
36
use Koha::MetadataRecord::Authority;
35
use Koha::Virtualshelves;
37
use Koha::Virtualshelves;
36
38
Lines 54-76 $template->param( lists => scalar Koha::Virtualshelves->search([{ category => 1, Link Here
54
56
55
my $sessionID = $input->cookie("CGISESSID");
57
my $sessionID = $input->cookie("CGISESSID");
56
58
57
my $runinbackground = $input->param('runinbackground');
58
my $completedJobID = $input->param('completedJobID');
59
if ( $completedJobID ) {
60
    my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID);
61
    my $report = $job->get('report');
62
    my $messages = $job->get('messages');
63
    $template->param(
64
        report => $report,
65
        messages => $messages,
66
        view => 'report',
67
        recordtype => $recordtype,
68
    );
69
    output_html_with_http_headers $input, $cookie, $template->output;
70
    $job->clear();
71
    exit;
72
}
73
74
my @templates = GetModificationTemplates( $mmtid );
59
my @templates = GetModificationTemplates( $mmtid );
75
unless ( @templates ) {
60
unless ( @templates ) {
76
    $op = 'error';
61
    $op = 'error';
Lines 166-270 if ( $op eq 'form' ) { Link Here
166
    # We want to modify selected records!
151
    # We want to modify selected records!
167
    my @record_ids = $input->multi_param('record_id');
152
    my @record_ids = $input->multi_param('record_id');
168
153
169
    my ( $job );
154
    my $job_id = Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue(
170
    if ( $runinbackground ) {
155
        {
171
        my $job_size = scalar( @record_ids );
156
            mmtid       => $mmtid,
172
        $job = C4::BackgroundJob->new( $sessionID, "FIXME", '/cgi-bin/koha/tools/batch_record_modification.pl', $job_size );
157
            record_type => $recordtype,
173
        my $job_id = $job->id;
158
            record_ids  => \@record_ids,
174
        if (my $pid = fork) {
175
            $dbh->{InactiveDestroy}  = 1;
176
177
            my $reply = CGI->new("");
178
            print $reply->header(-type => 'text/html');
179
            print '{"jobID":"' . $job_id . '"}';
180
            exit 0;
181
        } elsif (defined $pid) {
182
            close STDOUT;
183
        } else {
184
            warn "fork failed while attempting to run tools/batch_record_modification.pl as a background job";
185
            exit 0;
186
        }
159
        }
187
    }
160
    );
188
161
    $template->param(
189
    my $report = {
162
        view => 'enqueued',
190
        total_records => 0,
163
        job_id => $job_id,
191
        total_success => 0,
164
    );
192
    };
193
    my $progress = 0;
194
    $dbh->{RaiseError} = 1;
195
    RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) {
196
        $report->{total_records}++;
197
        next unless $record_id;
198
199
        if ( $recordtype eq 'biblio' ) {
200
            # Biblios
201
            my $biblionumber = $record_id;
202
203
            # Finally, modify the biblio
204
            my $error = eval {
205
                my $record = GetMarcBiblio({ biblionumber => $biblionumber });
206
                ModifyRecordWithTemplate( $mmtid, $record );
207
                my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber );
208
                ModBiblio( $record, $biblionumber, $frameworkcode );
209
            };
210
            if ( $error and $error != 1 or $@ ) { # ModBiblio returns 1 if everything as gone well
211
                push @messages, {
212
                    type => 'error',
213
                    code => 'biblio_not_modified',
214
                    biblionumber => $biblionumber,
215
                    error => ($@ ? $@ : $error),
216
                };
217
            } else {
218
                push @messages, {
219
                    type => 'success',
220
                    code => 'biblio_modified',
221
                    biblionumber => $biblionumber,
222
                };
223
                $report->{total_success}++;
224
            }
225
        } else {
226
            # Authorities
227
            my $authid = $record_id;
228
            my $error = eval {
229
                my $authority = Koha::MetadataRecord::Authority->get_from_authid( $authid );
230
                my $record = $authority->record;
231
                ModifyRecordWithTemplate( $mmtid, $record );
232
                ModAuthority( $authid, $record, $authority->authtypecode );
233
            };
234
            if ( $error and $error != $authid or $@ ) {
235
                push @messages, {
236
                    type => 'error',
237
                    code => 'authority_not_modified',
238
                    authid => $authid,
239
                    error => ($@ ? $@ : 0),
240
                };
241
            } else {
242
                push @messages, {
243
                    type => 'success',
244
                    code => 'authority_modified',
245
                    authid => $authid,
246
                };
247
                $report->{total_success}++;
248
            }
249
        }
250
251
        $job->set({
252
            view => 'report',
253
            report => $report,
254
            messages => \@messages,
255
        });
256
        $job->progress( ++$progress ) if $runinbackground;
257
    }
258
259
    if ($runinbackground) {
260
        $job->finish if defined $job;
261
    } else {
262
        $template->param(
263
            view => 'report',
264
            report => $report,
265
            messages => \@messages,
266
        );
267
    }
268
}
165
}
269
166
270
$template->param(
167
$template->param(
271
- 

Return to bug 22417