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 53-75 $template->param( lists => scalar Koha::Virtualshelves->search([{ category => 1, Link Here
53
55
54
my $sessionID = $input->cookie("CGISESSID");
56
my $sessionID = $input->cookie("CGISESSID");
55
57
56
my $runinbackground = $input->param('runinbackground');
57
my $completedJobID = $input->param('completedJobID');
58
if ( $completedJobID ) {
59
    my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID);
60
    my $report = $job->get('report');
61
    my $messages = $job->get('messages');
62
    $template->param(
63
        report => $report,
64
        messages => $messages,
65
        view => 'report',
66
        recordtype => $recordtype,
67
    );
68
    output_html_with_http_headers $input, $cookie, $template->output;
69
    $job->clear();
70
    exit;
71
}
72
73
my @templates = GetModificationTemplates( $mmtid );
58
my @templates = GetModificationTemplates( $mmtid );
74
unless ( @templates ) {
59
unless ( @templates ) {
75
    $op = 'error';
60
    $op = 'error';
Lines 165-269 if ( $op eq 'form' ) { Link Here
165
    # We want to modify selected records!
150
    # We want to modify selected records!
166
    my @record_ids = $input->multi_param('record_id');
151
    my @record_ids = $input->multi_param('record_id');
167
152
168
    my ( $job );
153
    my $job_id = Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue(
169
    if ( $runinbackground ) {
154
        {
170
        my $job_size = scalar( @record_ids );
155
            mmtid       => $mmtid,
171
        $job = C4::BackgroundJob->new( $sessionID, "FIXME", '/cgi-bin/koha/tools/batch_record_modification.pl', $job_size );
156
            record_type => $recordtype,
172
        my $job_id = $job->id;
157
            record_ids  => \@record_ids,
173
        if (my $pid = fork) {
174
            $dbh->{InactiveDestroy}  = 1;
175
176
            my $reply = CGI->new("");
177
            print $reply->header(-type => 'text/html');
178
            print '{"jobID":"' . $job_id . '"}';
179
            exit 0;
180
        } elsif (defined $pid) {
181
            close STDOUT;
182
        } else {
183
            warn "fork failed while attempting to run tools/batch_record_modification.pl as a background job";
184
            exit 0;
185
        }
158
        }
186
    }
159
    );
187
160
    $template->param(
188
    my $report = {
161
        view => 'enqueued',
189
        total_records => 0,
162
        job_id => $job_id,
190
        total_success => 0,
163
    );
191
    };
192
    my $progress = 0;
193
    $dbh->{RaiseError} = 1;
194
    RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) {
195
        $report->{total_records}++;
196
        next unless $record_id;
197
198
        if ( $recordtype eq 'biblio' ) {
199
            # Biblios
200
            my $biblionumber = $record_id;
201
202
            # Finally, modify the biblio
203
            my $error = eval {
204
                my $record = GetMarcBiblio({ biblionumber => $biblionumber });
205
                ModifyRecordWithTemplate( $mmtid, $record );
206
                my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber );
207
                ModBiblio( $record, $biblionumber, $frameworkcode );
208
            };
209
            if ( $error and $error != 1 or $@ ) { # ModBiblio returns 1 if everything as gone well
210
                push @messages, {
211
                    type => 'error',
212
                    code => 'biblio_not_modified',
213
                    biblionumber => $biblionumber,
214
                    error => ($@ ? $@ : $error),
215
                };
216
            } else {
217
                push @messages, {
218
                    type => 'success',
219
                    code => 'biblio_modified',
220
                    biblionumber => $biblionumber,
221
                };
222
                $report->{total_success}++;
223
            }
224
        } else {
225
            # Authorities
226
            my $authid = $record_id;
227
            my $error = eval {
228
                my $authority = Koha::MetadataRecord::Authority->get_from_authid( $authid );
229
                my $record = $authority->record;
230
                ModifyRecordWithTemplate( $mmtid, $record );
231
                ModAuthority( $authid, $record, $authority->authtypecode );
232
            };
233
            if ( $error and $error != $authid or $@ ) {
234
                push @messages, {
235
                    type => 'error',
236
                    code => 'authority_not_modified',
237
                    authid => $authid,
238
                    error => ($@ ? $@ : 0),
239
                };
240
            } else {
241
                push @messages, {
242
                    type => 'success',
243
                    code => 'authority_modified',
244
                    authid => $authid,
245
                };
246
                $report->{total_success}++;
247
            }
248
        }
249
250
        $job->set({
251
            view => 'report',
252
            report => $report,
253
            messages => \@messages,
254
        });
255
        $job->progress( ++$progress ) if $runinbackground;
256
    }
257
258
    if ($runinbackground) {
259
        $job->finish if defined $job;
260
    } else {
261
        $template->param(
262
            view => 'report',
263
            report => $report,
264
            messages => \@messages,
265
        );
266
    }
267
}
164
}
268
165
269
$template->param(
166
$template->param(
270
- 

Return to bug 22417