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

(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (-4 / +8 lines)
Lines 18-23 package Koha::BackgroundJob::BatchUpdateBiblio; Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Biblios;
20
use Koha::Biblios;
21
use Koha::Exceptions::BackgroundJob::BatchUpdateBiblio;
21
use Koha::Virtualshelves;
22
use Koha::Virtualshelves;
22
use Koha::SearchEngine;
23
use Koha::SearchEngine;
23
use Koha::SearchEngine::Indexer;
24
use Koha::SearchEngine::Indexer;
Lines 67-74 sub process { Link Here
67
68
68
    $self->start;
69
    $self->start;
69
70
70
    my $mmtid      = $args->{mmtid};
71
    my $mmtid                = $args->{mmtid};
71
    my @record_ids = @{ $args->{record_ids} };
72
    my $update_frameworkcode = $args->{frameworkcode};
73
    my @record_ids           = @{ $args->{record_ids} };
72
74
73
    my $report = {
75
    my $report = {
74
        total_records => scalar @record_ids,
76
        total_records => scalar @record_ids,
Lines 86-92 RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) { Link Here
86
            my $biblio = Koha::Biblios->find($biblionumber);
88
            my $biblio = Koha::Biblios->find($biblionumber);
87
            my $record = $biblio->metadata->record;
89
            my $record = $biblio->metadata->record;
88
            C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record );
90
            C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record );
89
            my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber);
91
            my $frameworkcode = $update_frameworkcode // C4::Biblio::GetFrameworkCode($biblionumber);
90
92
91
            if ( marc_record_contains_item_data($record) ) {
93
            if ( marc_record_contains_item_data($record) ) {
92
                my ( $can_add_item, $add_item_error_message ) = can_add_item_from_marc_record($record);
94
                my ( $can_add_item, $add_item_error_message ) = can_add_item_from_marc_record($record);
Lines 145-151 sub enqueue { Link Here
145
    my ( $self, $args ) = @_;
147
    my ( $self, $args ) = @_;
146
148
147
    # TODO Raise exception instead
149
    # TODO Raise exception instead
148
    return unless exists $args->{mmtid};
150
    Koha::Exceptions::BackgroundJob::BatchUpdateBiblio::NoAction->throw()
151
        unless ( exists $args->{mmtid} && $args->{mmtid} > 0
152
        || exists $args->{frameworkcode} && $args->{frameworkcode} != '_USE_ORIG' );
149
    return unless exists $args->{record_ids};
153
    return unless exists $args->{record_ids};
150
154
151
    $self->SUPER::enqueue(
155
    $self->SUPER::enqueue(
(-)a/Koha/Exceptions/BackgroundJob/BatchUpdateBiblio.pm (+57 lines)
Line 0 Link Here
1
package Koha::Exceptions::BackgroundJob::BatchUpdateBiblio;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Exception;
21
22
use Exception::Class (
23
24
    'Koha::Exceptions::BackgroundJob::BatchUpdateBiblio' => {
25
        isa => 'Koha::Exception',
26
    },
27
    'Koha::Exceptions::BackgroundJob::BatchUpdateBiblio::NoAction' => {
28
        isa         => 'Koha::Exceptions::BackgroundJob::BatchUpdateBiblio',
29
        description => 'Batch update requested but no modifications selected',
30
    },
31
    'Koha::Exceptions::BackgroundJob::BatchUpdateBiblio::NoRecords' => {
32
        isa         => 'Koha::Exceptions::BackgroundJob::BatchUpdateBiblio',
33
        description => 'Batch update requested but no records selected'
34
    },
35
);
36
37
=head1 NAME
38
39
Koha::Exceptions::BackgroundJob::BatchUpdateBiblio - Base class for BatchUpdateBiblio BackgroundJob exceptions
40
41
=head1 Exceptions
42
43
=head2 Koha::Exceptions::BackgroundJob::BatchUpdateBiblio
44
45
Generic BatchUpdateBiblio BackgroundJob exception
46
47
=head2 Koha::Exceptions::BackgroundJob::BatchUpdateBiblio::NoAction
48
49
Exception to be used when a BatchUpdateBiblio BackgroundJob has no actions specified.
50
51
=head2 Koha::Exceptions::BackgroundJob::BatchUpdateBiblio::NoRecords
52
53
Exception to be used when no records are sent to batch modification.
54
55
=cut
56
57
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt (-16 / +33 lines)
Lines 153-160 Link Here
153
                <legend>MARC modification template</legend>
153
                <legend>MARC modification template</legend>
154
                <ol>
154
                <ol>
155
                    <li>
155
                    <li>
156
                        <label for="marc_modification_template_id" class="required">Template: </label>
156
                        <label for="marc_modification_template_id">Template: </label>
157
                        <select name="marc_modification_template_id" id="marc_modification_template_id" required="required">
157
                        <select name="marc_modification_template_id" id="marc_modification_template_id">
158
                            <option value="">Select a template</option>
158
                            <option value="">Select a template</option>
159
                            [% FOREACH mmt IN MarcModificationTemplatesLoop %]
159
                            [% FOREACH mmt IN MarcModificationTemplatesLoop %]
160
                                <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
160
                                <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
Lines 163-168 Link Here
163
                    </li>
163
                    </li>
164
                </ol>
164
                </ol>
165
            </fieldset>
165
            </fieldset>
166
            <fieldset class="rows frameworkcode">
167
                <legend>Update framework</legend>
168
                <ol>
169
                    <li>
170
                        <label for="overlay_framework">Update framework: </label>
171
                        <select name="overlay_framework" id="overlay_framework">
172
                            <option value="_USE_ORIG_">Keep original framework</option>
173
                            <option value="">Default</option>
174
                            [% FOREACH framework IN frameworks %]
175
                                <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
176
                            [% END %]
177
                        </select>
178
                    </li>
179
                </ol>
180
            </fieldset>
166
            <fieldset class="action">
181
            <fieldset class="action">
167
                <input type="hidden" name="op" value="cud-list" />
182
                <input type="hidden" name="op" value="cud-list" />
168
                <input type="submit" class="btn btn-primary" value="Continue" />
183
                <input type="submit" class="btn btn-primary" value="Continue" />
Lines 174-181 Link Here
174
        [% IF records %]
189
        [% IF records %]
175
            <form action="/cgi-bin/koha/tools/batch_record_modification.pl" method="post">
190
            <form action="/cgi-bin/koha/tools/batch_record_modification.pl" method="post">
176
                [% INCLUDE 'csrf-token.inc' %]
191
                [% INCLUDE 'csrf-token.inc' %]
177
                <label for="marc_modification_template_id" class="required">Modify record using the following template: </label>
192
                <label for="marc_modification_template_id">Modify record using the following template: </label>
178
                <select name="marc_modification_template_id" id="marc_modification_template_id" required="required">
193
                <select name="marc_modification_template_id" id="marc_modification_template_id">
179
                    <option value="">Select a template</option>
194
                    <option value="">Select a template</option>
180
                    [% FOREACH mmt IN MarcModificationTemplatesLoop %]
195
                    [% FOREACH mmt IN MarcModificationTemplatesLoop %]
181
                        [% IF mmt.selected %]
196
                        [% IF mmt.selected %]
Lines 202-207 Link Here
202
                    </div>
217
                    </div>
203
                </div>
218
                </div>
204
                [% IF recordtype == 'biblio' %]
219
                [% IF recordtype == 'biblio' %]
220
                    <label for="update_framework">Update framework: </label>
221
                    <select name="overlay_framework" id="overlay_framework">
222
                        <option value="_USE_ORIG_" [% IF frameworkcode == "_USE_ORIG" %]selected="selected"[% END %]>Keep original framework</option>
223
                        <option value="" [% IF frameworkcode == "" %]selected="selected"[% END %]>Default</option>
224
                        [%- FOREACH framework IN frameworks -%]
225
                            [%- IF framework.frameworkcode == frameworkcode -%]
226
                                <option value="[% framework.frameworkcode | html %]" selected="selected">[% framework.frameworktext | html %]</option>
227
                            [%- ELSE -%]
228
                                <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
229
                            [%- END -%]
230
                        [%- END -%]
231
                    </select>
205
                    <div class="btn-toolbar selections-toolbar">
232
                    <div class="btn-toolbar selections-toolbar">
206
                        <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a>
233
                        <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a>
207
                        | <a id="clearall" href="#"><i class="fa fa-times"></i> Clear all</a>
234
                        | <a id="clearall" href="#"><i class="fa fa-times"></i> Clear all</a>
Lines 325-333 Link Here
325
            if (selected_type == 'authority') {
352
            if (selected_type == 'authority') {
326
                $("a[href='#shelves_tab_panel']").parent().hide();
353
                $("a[href='#shelves_tab_panel']").parent().hide();
327
                $("a[href='#uploadfile_tab_panel']").tab("show");
354
                $("a[href='#uploadfile_tab_panel']").tab("show");
355
                $("fieldset.frameworkcode").hide();
328
            } else if (selected_type == 'biblio') {
356
            } else if (selected_type == 'biblio') {
329
                $("a[href='#shelves_tab_panel']").parent().show();
357
                $("a[href='#shelves_tab_panel']").parent().show();
330
                $("a[href='#uploadfile_tab_panel']").tab("show");
358
                $("a[href='#uploadfile_tab_panel']").tab("show");
359
                $("fieldset.frameworkcode").show();
331
            }
360
            }
332
        }
361
        }
333
        $(document).ready(function() {
362
        $(document).ready(function() {
Lines 373-390 Link Here
373
                paginate: false,
402
                paginate: false,
374
            });
403
            });
375
404
376
            $("#mainformsubmit").click(function() {
377
                if ($("input[type=checkbox][name='record_id']:checked").length == 0) {
378
                    alert(_("Please select at least one record to process"));
379
                    return false;
380
                }
381
                if ($("#marc_modification_template_id").val() <= 0) {
382
                    alert(_("Please select a modification template."));
383
                    return false;
384
                }
385
                return true;
386
            });
387
388
            $("#record_ids_selection").on("submit", function(e) {
405
            $("#record_ids_selection").on("submit", function(e) {
389
                var tab = $(this).find('#batch_mod_form li a.active:first').attr('href');
406
                var tab = $(this).find('#batch_mod_form li a.active:first').attr('href');
390
                if (tab == '#uploadfile_tab_panel') {
407
                if (tab == '#uploadfile_tab_panel') {
(-)a/tools/batch_record_modification.pl (-6 / +24 lines)
Lines 35-40 use C4::MarcModificationTemplates qw( Link Here
35
use Koha::Biblios;
35
use Koha::Biblios;
36
use Koha::BackgroundJob::BatchUpdateBiblio;
36
use Koha::BackgroundJob::BatchUpdateBiblio;
37
use Koha::BackgroundJob::BatchUpdateAuthority;
37
use Koha::BackgroundJob::BatchUpdateAuthority;
38
use Koha::BiblioFrameworks;
38
use Koha::MetadataRecord::Authority;
39
use Koha::MetadataRecord::Authority;
39
use Koha::Virtualshelves;
40
use Koha::Virtualshelves;
40
41
Lines 82-87 if ($mmtid) { Link Here
82
83
83
if ( $op eq 'form' ) {
84
if ( $op eq 'form' ) {
84
85
86
    my $frameworks = Koha::BiblioFrameworks->search(
87
        { tagfield => { 'not' => undef } },
88
        { join     => 'marc_tag_structure', distinct => 'frameworkcode', order_by => ['frameworktext'] }
89
    );
90
85
    # Display the form
91
    # Display the form
86
    $template->param(
92
    $template->param(
87
        view  => 'form',
93
        view  => 'form',
Lines 90-97 if ( $op eq 'form' ) { Link Here
90
                { public => 0, owner => $loggedinuser },
96
                { public => 0, owner => $loggedinuser },
91
                { public => 1 }
97
                { public => 1 }
92
            ]
98
            ]
93
        )
99
        ),
100
        frameworks => $frameworks
94
    );
101
    );
102
95
} elsif ( $op eq 'cud-list' ) {
103
} elsif ( $op eq 'cud-list' ) {
96
104
97
    # List all records to process
105
    # List all records to process
Lines 122-128 if ( $op eq 'form' ) { Link Here
122
        # The user enters manually the list of id
130
        # The user enters manually the list of id
123
        push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') );
131
        push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') );
124
    }
132
    }
133
    my $frameworkcode = $input->param('overlay_framework');
125
134
135
    my $frameworks;
136
    $frameworks = Koha::BiblioFrameworks->search(
137
        { tagfield => { 'not' => undef } },
138
        { join     => 'marc_tag_structure', distinct => 'frameworkcode', order_by => ['frameworktext'] }
139
    );
126
    for my $record_id ( uniq @record_ids ) {
140
    for my $record_id ( uniq @record_ids ) {
127
        if ( $recordtype eq 'biblio' ) {
141
        if ( $recordtype eq 'biblio' ) {
128
142
Lines 157-174 if ( $op eq 'form' ) { Link Here
157
        }
171
        }
158
    }
172
    }
159
    $template->param(
173
    $template->param(
160
        records => \@records,
174
        records       => \@records,
161
        mmtid   => $mmtid,
175
        mmtid         => $mmtid,
162
        view    => 'list',
176
        view          => 'list',
177
        frameworks    => $frameworks,
178
        frameworkcode => $frameworkcode,
163
    );
179
    );
164
} elsif ( $op eq 'cud-modify' ) {
180
} elsif ( $op eq 'cud-modify' ) {
165
181
166
    # We want to modify selected records!
182
    # We want to modify selected records!
167
    my @record_ids = $input->multi_param('record_id');
183
    my @record_ids    = $input->multi_param('record_id');
184
    my $frameworkcode = $input->param('overlay_framework');
185
    $frameworkcode = undef if $frameworkcode eq '_USE_ORIG_';
168
186
169
    try {
187
    try {
170
        my $patron = Koha::Patrons->find($loggedinuser);
188
        my $patron = Koha::Patrons->find($loggedinuser);
171
        my $params = {
189
        my $params = {
190
            frameworkcode   => $frameworkcode,
172
            mmtid           => $mmtid,
191
            mmtid           => $mmtid,
173
            record_ids      => \@record_ids,
192
            record_ids      => \@record_ids,
174
            overlay_context => {
193
            overlay_context => {
175
- 

Return to bug 24843