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

(-)a/Koha/BackgroundJob/BatchUpdateItem.pm (-17 / +17 lines)
Lines 91-131 sub process { Link Here
91
91
92
    $self->start;
92
    $self->start;
93
93
94
    my @record_ids = @{ $args->{record_ids} };
94
    my @record_ids                        = @{ $args->{record_ids} };
95
    my $regex_mod  = $args->{regex_mod};
95
    my $regex_mod                         = $args->{regex_mod};
96
    my $new_values = $args->{new_values};
96
    my $new_values                        = $args->{new_values};
97
    my $exclude_from_local_holds_priority =
97
    my $exclude_from_local_holds_priority = $args->{exclude_from_local_holds_priority};
98
      $args->{exclude_from_local_holds_priority};
98
    my $mark_items_returned               = $args->{mark_items_returned};
99
    my $mark_items_returned =
99
    my $sort1                             = $args->{sort1};
100
      $args->{mark_items_returned};
100
    my $sort2                             = $args->{sort2};
101
101
102
    my $report = {
102
    my $report = {
103
        total_records            => scalar @record_ids,
103
        total_records   => scalar @record_ids,
104
        modified_fields          => 0,
104
        modified_fields => 0,
105
    };
105
    };
106
106
107
    try {
107
    try {
108
        my ($results) = Koha::Items->search( { itemnumber => \@record_ids } )->batch_update(
108
        my ($results) = Koha::Items->search( { itemnumber => \@record_ids } )->batch_update(
109
            {   regex_mod                         => $regex_mod,
109
            {
110
                regex_mod                         => $regex_mod,
110
                new_values                        => $new_values,
111
                new_values                        => $new_values,
111
                exclude_from_local_holds_priority => $exclude_from_local_holds_priority,
112
                exclude_from_local_holds_priority => $exclude_from_local_holds_priority,
112
                mark_items_returned               => $mark_items_returned,
113
                mark_items_returned               => $mark_items_returned,
114
                sort1                             => $sort1,
115
                sort2                             => $sort2,
113
                callback                          => sub { $self->step; },
116
                callback                          => sub { $self->step; },
114
            }
117
            }
115
        );
118
        );
116
        $report->{modified_itemnumbers} = $results->{modified_itemnumbers};
119
        $report->{modified_itemnumbers} = $results->{modified_itemnumbers};
117
        $report->{modified_fields}      = $results->{modified_fields};
120
        $report->{modified_fields}      = $results->{modified_fields};
118
    }
121
    } catch {
119
    catch {
120
        warn $_;
122
        warn $_;
121
        die "Something terrible has happened!"
123
        die "Something terrible has happened!"
122
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
124
            if ( $_ =~ /Rollback failed/ );    # Rollback failed
123
    };
125
    };
124
126
125
    my $data = $self->decoded_data;
127
    my $data = $self->decoded_data;
126
    $data->{report} = $report;
128
    $data->{report} = $report;
127
129
128
    $self->finish( $data );
130
    $self->finish($data);
129
}
131
}
130
132
131
=head3 enqueue
133
=head3 enqueue
Lines 166-174 sub additional_report { Link Here
166
    if ( scalar(@$itemnumbers) > C4::Context->preference('MaxItemsToDisplayForBatchMod') ) {
168
    if ( scalar(@$itemnumbers) > C4::Context->preference('MaxItemsToDisplayForBatchMod') ) {
167
        return { too_many_items_display => 1 };
169
        return { too_many_items_display => 1 };
168
    } else {
170
    } else {
169
        my $items_table =
171
        my $items_table = Koha::UI::Table::Builder::Items->new( { itemnumbers => $itemnumbers } )->build_table;
170
          Koha::UI::Table::Builder::Items->new( { itemnumbers => $itemnumbers } )
171
          ->build_table;
172
172
173
        return {
173
        return {
174
            items            => $items_table->{items},
174
            items            => $items_table->{items},
(-)a/Koha/Items.pm (-7 / +17 lines)
Lines 243-253 Callback function to call after an item has been modified Link Here
243
sub batch_update {
243
sub batch_update {
244
    my ( $self, $params ) = @_;
244
    my ( $self, $params ) = @_;
245
245
246
    my $regex_mod = $params->{regex_mod} || {};
246
    my $regex_mod                         = $params->{regex_mod}  || {};
247
    my $new_values = $params->{new_values} || {};
247
    my $new_values                        = $params->{new_values} || {};
248
    my $exclude_from_local_holds_priority = $params->{exclude_from_local_holds_priority};
248
    my $exclude_from_local_holds_priority = $params->{exclude_from_local_holds_priority};
249
    my $mark_items_returned = $params->{mark_items_returned};
249
    my $mark_items_returned               = $params->{mark_items_returned};
250
    my $callback = $params->{callback};
250
    my $sort1                             = $params->{sort1};
251
    my $sort2                             = $params->{sort2};
252
    my $callback                          = $params->{callback};
251
253
252
    my (@modified_itemnumbers, $modified_fields);
254
    my (@modified_itemnumbers, $modified_fields);
253
    my $i;
255
    my $i;
Lines 256-268 sub batch_update { Link Here
256
258
257
        try {$schema->txn_do(sub {
259
        try {$schema->txn_do(sub {
258
            my $modified_holds_priority = 0;
260
            my $modified_holds_priority = 0;
259
            my $item_returned = 0;
261
            my $item_returned           = 0;
262
            my $sort_fields_modified    = 0;
260
            if ( defined $exclude_from_local_holds_priority ) {
263
            if ( defined $exclude_from_local_holds_priority ) {
261
                if(!defined $item->exclude_from_local_holds_priority || $item->exclude_from_local_holds_priority != $exclude_from_local_holds_priority) {
264
                if(!defined $item->exclude_from_local_holds_priority || $item->exclude_from_local_holds_priority != $exclude_from_local_holds_priority) {
262
                    $item->exclude_from_local_holds_priority($exclude_from_local_holds_priority)->store;
265
                    $item->exclude_from_local_holds_priority($exclude_from_local_holds_priority)->store;
263
                    $modified_holds_priority = 1;
266
                    $modified_holds_priority = 1;
264
                }
267
                }
265
            }
268
            }
269
            if ( defined $sort1 || defined $sort2 ) {
270
                $item->sort1($sort1)->store if $sort1 ne "";
271
                $sort_fields_modified++     if $sort1 ne "";
272
                $item->sort2($sort2)->store if $sort2 ne "";
273
                $sort_fields_modified++     if $sort2 ne "";
274
            }
266
275
267
            my $modified = 0;
276
            my $modified = 0;
268
            my $new_values = {%$new_values};    # Don't modify the original
277
            my $new_values = {%$new_values};    # Don't modify the original
Lines 360-367 sub batch_update { Link Here
360
                }
369
                }
361
            }
370
            }
362
371
363
            push @modified_itemnumbers, $item->itemnumber if $modified || $modified_holds_priority || $item_returned;
372
            push @modified_itemnumbers, $item->itemnumber
364
            $modified_fields += $modified + $modified_holds_priority + $item_returned;
373
                if $modified || $modified_holds_priority || $item_returned || $sort_fields_modified;
374
            $modified_fields += $modified + $modified_holds_priority + $item_returned + $sort_fields_modified;
365
        })}
375
        })}
366
        catch {
376
        catch {
367
            warn $_
377
            warn $_
(-)a/catalogue/updateitem.pl (-9 / +15 lines)
Lines 29-44 my $cgi= CGI->new; Link Here
29
29
30
checkauth($cgi, 0, {circulate => 'circulate_remaining_permissions'}, 'intranet');
30
checkauth($cgi, 0, {circulate => 'circulate_remaining_permissions'}, 'intranet');
31
31
32
my $op = $cgi->param('op') || "";
32
my $op                                = $cgi->param('op') || "";
33
my $biblionumber=$cgi->param('biblionumber');
33
my $biblionumber                      = $cgi->param('biblionumber');
34
my $itemnumber=$cgi->param('itemnumber');
34
my $itemnumber                        = $cgi->param('itemnumber');
35
my $biblioitemnumber=$cgi->param('biblioitemnumber');
35
my $biblioitemnumber                  = $cgi->param('biblioitemnumber');
36
my $itemlost=$cgi->param('itemlost');
36
my $itemlost                          = $cgi->param('itemlost');
37
my $itemnotes=$cgi->param('itemnotes');
37
my $itemnotes                         = $cgi->param('itemnotes');
38
my $itemnotes_nonpublic=$cgi->param('itemnotes_nonpublic');
38
my $itemnotes_nonpublic               = $cgi->param('itemnotes_nonpublic');
39
my $withdrawn=$cgi->param('withdrawn');
39
my $withdrawn                         = $cgi->param('withdrawn');
40
my $damaged=$cgi->param('damaged');
40
my $damaged                           = $cgi->param('damaged');
41
my $exclude_from_local_holds_priority = $cgi->param('exclude_from_local_holds_priority');
41
my $exclude_from_local_holds_priority = $cgi->param('exclude_from_local_holds_priority');
42
my $sort1                             = $cgi->param('sort1');
43
my $sort2                             = $cgi->param('sort2');
42
44
43
my $confirm=$cgi->param('confirm');
45
my $confirm=$cgi->param('confirm');
44
my $dbh = C4::Context->dbh;
46
my $dbh = C4::Context->dbh;
Lines 77-82 elsif ( $op eq "set_public_note" ) { # i.e., itemnotes parameter passed from for Link Here
77
    $messages = "updated_exclude_from_local_holds_priority=$exclude_from_local_holds_priority&";
79
    $messages = "updated_exclude_from_local_holds_priority=$exclude_from_local_holds_priority&";
78
} elsif ( $op eq "set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) {
80
} elsif ( $op eq "set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) {
79
    $item->damaged($damaged);
81
    $item->damaged($damaged);
82
} elsif ( $op eq "set_sort1" && $sort1 ne $item_data_hashref->{'sort1'} ) {
83
    $item->sort1($sort1);
84
} elsif ( $op eq "set_sort2" && $sort2 ne $item_data_hashref->{'sort2'} ) {
85
    $item->sort2($sort2);
80
} else {
86
} else {
81
    #nothings changed, so do nothing.
87
    #nothings changed, so do nothing.
82
    print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber");
88
    print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber");
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt (+32 lines)
Lines 335-340 Link Here
335
                                    </div> <!-- /.rows -->
335
                                    </div> <!-- /.rows -->
336
                            </div> <!-- /.listgroup -->
336
                            </div> <!-- /.listgroup -->
337
337
338
                            <div class="listgroup">
339
                                <h4>Sort fields</h4>
340
                                <div class="rows">
341
                                    <ol class="bibliodetails">
342
                                        <li>
343
                                            <span class="label">Sort 1:</span>
344
                                            [% IF ( CAN_user_editcatalogue_edit_items ) %]
345
                                                <form class="inline" action="updateitem.pl" method="post"><input type="hidden" name="biblionumber" value="[% ITEM_DAT.biblionumber | html %]" />
346
                                                    <input type="hidden" name="biblioitemnumber" value="[% ITEM_DAT.biblioitemnumber | html %]" /><input type="hidden" name="itemnumber" value="[% ITEM_DAT.itemnumber | html %]" />
347
                                                    <input type="hidden" name="op" value="set_sort1" />
348
                                                    <textarea name="sort1" rows="2" cols="30">[% ITEM_DAT.sort1 | html %]</textarea><input type="submit" name="submit" class="btn btn-primary btn-xs" value="Update" />
349
                                                </form>
350
                                            [% ELSE %]
351
                                                [% ITEM_DAT.sort1 | html %]
352
                                            [% END %]
353
                                        </li>
354
                                        <li>
355
                                            <span class="label">Sort 2:</span>
356
                                            [% IF ( CAN_user_editcatalogue_edit_items ) %]
357
                                                <form class="inline" action="updateitem.pl" method="post"><input type="hidden" name="biblionumber" value="[% ITEM_DAT.biblionumber | html %]" />
358
                                                    <input type="hidden" name="biblioitemnumber" value="[% ITEM_DAT.biblioitemnumber | html %]" /><input type="hidden" name="itemnumber" value="[% ITEM_DAT.itemnumber | html %]" />
359
                                                    <input type="hidden" name="op" value="set_sort2" />
360
                                                    <textarea name="sort2" rows="2" cols="30">[% ITEM_DAT.sort2 | html %]</textarea><input type="submit" name="submit" class="btn btn-primary btn-xs" value="Update" />
361
                                                </form>
362
                                            [% ELSE %]
363
                                                [% ITEM_DAT.sort2 | html %]
364
                                            [% END %]
365
                                        </li>
366
                                    </ol> <!-- /.bibliodetails -->
367
                                </div> <!-- /.rows -->
368
                            </div> <!-- /.listgroup -->
369
338
                            <div class="listgroup">
370
                            <div class="listgroup">
339
                                <h4>History</h4>
371
                                <h4>History</h4>
340
                                <div class="rows">
372
                                <div class="rows">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt (+12 lines)
Lines 188-193 Link Here
188
                                        </select>
188
                                        </select>
189
                                    </div>
189
                                    </div>
190
                                </li>
190
                                </li>
191
                                <li>
192
                                    <div class="subfield_line">
193
                                        <label for="sort1">Sort 1:</label>
194
                                        <input type="text" id="sort1" name="sort1" class="input_marceditor" maxlength="50" value="" />
195
                                    </div>
196
                                </li>
197
                                <li>
198
                                    <div class="subfield_line">
199
                                        <label for="sort1">Sort 2:</label>
200
                                        <input type="text" id="sort2" name="sort2" class="input_marceditor" maxlength="50" value="" />
201
                                    </div>
202
                                </li>
191
                            </ol>
203
                            </ol>
192
                        </fieldset>
204
                        </fieldset>
193
                        <fieldset class="rows">
205
                        <fieldset class="rows">
(-)a/tools/batchMod.pl (-13 / +15 lines)
Lines 41-58 use Koha::BackgroundJob::BatchUpdateItem; Link Here
41
use Koha::UI::Form::Builder::Item;
41
use Koha::UI::Form::Builder::Item;
42
use Koha::UI::Table::Builder::Items;
42
use Koha::UI::Table::Builder::Items;
43
43
44
my $input = CGI->new;
44
my $input                             = CGI->new;
45
my $dbh = C4::Context->dbh;
45
my $dbh                               = C4::Context->dbh;
46
my $error        = $input->param('error');
46
my $error                             = $input->param('error');
47
my @itemnumbers  = $input->multi_param('itemnumber');
47
my @itemnumbers                       = $input->multi_param('itemnumber');
48
my $biblionumber = $input->param('biblionumber');
48
my $biblionumber                      = $input->param('biblionumber');
49
my $op           = $input->param('op');
49
my $op                                = $input->param('op');
50
my $del          = $input->param('del');
50
my $del                               = $input->param('del');
51
my $del_records  = $input->param('del_records');
51
my $del_records                       = $input->param('del_records');
52
my $src          = $input->param('src');
52
my $src                               = $input->param('src');
53
my $use_default_values = $input->param('use_default_values');
53
my $use_default_values                = $input->param('use_default_values');
54
my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority');
54
my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority');
55
my $mark_items_returned = $input->param('mark_items_returned');
55
my $sort1                             = $input->param('sort1');
56
my $sort2                             = $input->param('sort2');
57
my $mark_items_returned               = $input->param('mark_items_returned');
56
58
57
my $template_name;
59
my $template_name;
58
my $template_flag;
60
my $template_flag;
Lines 177-183 if ( $op eq "action" ) { Link Here
177
                  && $mark_items_returned ne ""
179
                  && $mark_items_returned ne ""
178
                )
180
                )
179
            ? $mark_items_returned : undef,
181
            ? $mark_items_returned : undef,
180
182
            sort1 => ( defined $sort1 && $sort1 ne "" ) ? $sort1 : undef,
183
            sort2 => ( defined $sort2 && $sort2 ne "" ) ? $sort2 : undef,
181
        };
184
        };
182
        try {
185
        try {
183
            my $job_id =
186
            my $job_id =
184
- 

Return to bug 19316