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

(-)a/Koha/BackgroundJob/BatchUpdateItem.pm (-17 / +17 lines)
Lines 92-132 sub process { Link Here
92
92
93
    $self->start;
93
    $self->start;
94
94
95
    my @record_ids = @{ $args->{record_ids} };
95
    my @record_ids                        = @{ $args->{record_ids} };
96
    my $regex_mod  = $args->{regex_mod};
96
    my $regex_mod                         = $args->{regex_mod};
97
    my $new_values = $args->{new_values};
97
    my $new_values                        = $args->{new_values};
98
    my $exclude_from_local_holds_priority =
98
    my $exclude_from_local_holds_priority = $args->{exclude_from_local_holds_priority};
99
      $args->{exclude_from_local_holds_priority};
99
    my $mark_items_returned               = $args->{mark_items_returned};
100
    my $mark_items_returned =
100
    my $sort1                             = $args->{sort1};
101
      $args->{mark_items_returned};
101
    my $sort2                             = $args->{sort2};
102
102
103
    my $report = {
103
    my $report = {
104
        total_records            => scalar @record_ids,
104
        total_records   => scalar @record_ids,
105
        modified_fields          => 0,
105
        modified_fields => 0,
106
    };
106
    };
107
107
108
    try {
108
    try {
109
        my ($results) = Koha::Items->search( { itemnumber => \@record_ids } )->batch_update(
109
        my ($results) = Koha::Items->search( { itemnumber => \@record_ids } )->batch_update(
110
            {   regex_mod                         => $regex_mod,
110
            {
111
                regex_mod                         => $regex_mod,
111
                new_values                        => $new_values,
112
                new_values                        => $new_values,
112
                exclude_from_local_holds_priority => $exclude_from_local_holds_priority,
113
                exclude_from_local_holds_priority => $exclude_from_local_holds_priority,
113
                mark_items_returned               => $mark_items_returned,
114
                mark_items_returned               => $mark_items_returned,
115
                sort1                             => $sort1,
116
                sort2                             => $sort2,
114
                callback                          => sub { $self->step; },
117
                callback                          => sub { $self->step; },
115
            }
118
            }
116
        );
119
        );
117
        $report->{modified_itemnumbers} = $results->{modified_itemnumbers};
120
        $report->{modified_itemnumbers} = $results->{modified_itemnumbers};
118
        $report->{modified_fields}      = $results->{modified_fields};
121
        $report->{modified_fields}      = $results->{modified_fields};
119
    }
122
    } catch {
120
    catch {
121
        warn $_;
123
        warn $_;
122
        die "Something terrible has happened!"
124
        die "Something terrible has happened!"
123
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
125
            if ( $_ =~ /Rollback failed/ );    # Rollback failed
124
    };
126
    };
125
127
126
    my $data = $self->decoded_data;
128
    my $data = $self->decoded_data;
127
    $data->{report} = $report;
129
    $data->{report} = $report;
128
130
129
    $self->finish( $data );
131
    $self->finish($data);
130
}
132
}
131
133
132
=head3 enqueue
134
=head3 enqueue
Lines 167-175 sub additional_report { Link Here
167
    if ( scalar(@$itemnumbers) > C4::Context->preference('MaxItemsToDisplayForBatchMod') ) {
169
    if ( scalar(@$itemnumbers) > C4::Context->preference('MaxItemsToDisplayForBatchMod') ) {
168
        return { too_many_items_display => 1 };
170
        return { too_many_items_display => 1 };
169
    } else {
171
    } else {
170
        my $items_table =
172
        my $items_table = Koha::UI::Table::Builder::Items->new( { itemnumbers => $itemnumbers } )->build_table;
171
          Koha::UI::Table::Builder::Items->new( { itemnumbers => $itemnumbers } )
172
          ->build_table;
173
173
174
        return {
174
        return {
175
            items            => $items_table->{items},
175
            items            => $items_table->{items},
(-)a/Koha/Items.pm (-8 / +18 lines)
Lines 198-204 sub move_to_biblio { Link Here
198
198
199
=head3 batch_update
199
=head3 batch_update
200
200
201
    Koha::Items->search->batch_update
201
    Koha::Items->search->batch_update(
202
        {
202
        {
203
            new_values => {
203
            new_values => {
204
                itemnotes => $new_item_notes,
204
                itemnotes => $new_item_notes,
Lines 258-268 Callback function to call after an item has been modified Link Here
258
sub batch_update {
258
sub batch_update {
259
    my ( $self, $params ) = @_;
259
    my ( $self, $params ) = @_;
260
260
261
    my $regex_mod = $params->{regex_mod} || {};
261
    my $regex_mod                         = $params->{regex_mod}  || {};
262
    my $new_values = $params->{new_values} || {};
262
    my $new_values                        = $params->{new_values} || {};
263
    my $exclude_from_local_holds_priority = $params->{exclude_from_local_holds_priority};
263
    my $exclude_from_local_holds_priority = $params->{exclude_from_local_holds_priority};
264
    my $mark_items_returned = $params->{mark_items_returned};
264
    my $mark_items_returned               = $params->{mark_items_returned};
265
    my $callback = $params->{callback};
265
    my $sort1                             = $params->{sort1};
266
    my $sort2                             = $params->{sort2};
267
    my $callback                          = $params->{callback};
266
268
267
    my (@modified_itemnumbers, $modified_fields);
269
    my (@modified_itemnumbers, $modified_fields);
268
    my $i;
270
    my $i;
Lines 271-283 sub batch_update { Link Here
271
273
272
        try {$schema->txn_do(sub {
274
        try {$schema->txn_do(sub {
273
            my $modified_holds_priority = 0;
275
            my $modified_holds_priority = 0;
274
            my $item_returned = 0;
276
            my $item_returned           = 0;
277
            my $sort_fields_modified    = 0;
275
            if ( defined $exclude_from_local_holds_priority ) {
278
            if ( defined $exclude_from_local_holds_priority ) {
276
                if(!defined $item->exclude_from_local_holds_priority || $item->exclude_from_local_holds_priority != $exclude_from_local_holds_priority) {
279
                if(!defined $item->exclude_from_local_holds_priority || $item->exclude_from_local_holds_priority != $exclude_from_local_holds_priority) {
277
                    $item->exclude_from_local_holds_priority($exclude_from_local_holds_priority)->store;
280
                    $item->exclude_from_local_holds_priority($exclude_from_local_holds_priority)->store;
278
                    $modified_holds_priority = 1;
281
                    $modified_holds_priority = 1;
279
                }
282
                }
280
            }
283
            }
284
            if ( defined $sort1 || defined $sort2 ) {
285
                $item->sort1($sort1)->store if $sort1 ne "";
286
                $sort_fields_modified++     if $sort1 ne "";
287
                $item->sort2($sort2)->store if $sort2 ne "";
288
                $sort_fields_modified++     if $sort2 ne "";
289
            }
281
290
282
            my $modified = 0;
291
            my $modified = 0;
283
            my $new_values = {%$new_values};    # Don't modify the original
292
            my $new_values = {%$new_values};    # Don't modify the original
Lines 375-382 sub batch_update { Link Here
375
                }
384
                }
376
            }
385
            }
377
386
378
            push @modified_itemnumbers, $item->itemnumber if $modified || $modified_holds_priority || $item_returned;
387
            push @modified_itemnumbers, $item->itemnumber
379
            $modified_fields += $modified + $modified_holds_priority + $item_returned;
388
                if $modified || $modified_holds_priority || $item_returned || $sort_fields_modified;
389
            $modified_fields += $modified + $modified_holds_priority + $item_returned + $sort_fields_modified;
380
        })}
390
        })}
381
        catch {
391
        catch {
382
            warn $_
392
            warn $_
(-)a/catalogue/updateitem.pl (-10 / +16 lines)
Lines 29-45 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 $bookable = $cgi->param('bookable');
42
my $bookable                          = $cgi->param('bookable');
43
my $sort1                             = $cgi->param('sort1');
44
my $sort2                             = $cgi->param('sort2');
43
45
44
my $confirm=$cgi->param('confirm');
46
my $confirm=$cgi->param('confirm');
45
my $dbh = C4::Context->dbh;
47
my $dbh = C4::Context->dbh;
Lines 80-85 elsif ( $op eq "cud-set_public_note" ) { # i.e., itemnotes parameter passed from Link Here
80
    $item->bookable($bookable);
82
    $item->bookable($bookable);
81
} elsif ( $op eq "cud-set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) {
83
} elsif ( $op eq "cud-set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) {
82
    $item->damaged($damaged);
84
    $item->damaged($damaged);
85
} elsif ( $op eq "set_sort1" && $sort1 ne $item_data_hashref->{'sort1'} ) {
86
    $item->sort1($sort1);
87
} elsif ( $op eq "set_sort2" && $sort2 ne $item_data_hashref->{'sort2'} ) {
88
    $item->sort2($sort2);
83
} else {
89
} else {
84
    #nothings changed, so do nothing.
90
    #nothings changed, so do nothing.
85
    print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber");
91
    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 379-384 Link Here
379
                                    </div> <!-- /.rows -->
379
                                    </div> <!-- /.rows -->
380
                            </div> <!-- /.listgroup -->
380
                            </div> <!-- /.listgroup -->
381
381
382
                            <div class="listgroup">
383
                                <h4>Sort fields</h4>
384
                                <div class="rows">
385
                                    <ol class="bibliodetails">
386
                                        <li>
387
                                            <span class="label">Sort 1:</span>
388
                                            [% IF ( CAN_user_editcatalogue_edit_items ) %]
389
                                                <form class="inline" action="updateitem.pl" method="post"><input type="hidden" name="biblionumber" value="[% ITEM_DAT.biblionumber | html %]" />
390
                                                    <input type="hidden" name="biblioitemnumber" value="[% ITEM_DAT.biblioitemnumber | html %]" /><input type="hidden" name="itemnumber" value="[% ITEM_DAT.itemnumber | html %]" />
391
                                                    <input type="hidden" name="op" value="set_sort1" />
392
                                                    <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" />
393
                                                </form>
394
                                            [% ELSE %]
395
                                                [% ITEM_DAT.sort1 | html %]
396
                                            [% END %]
397
                                        </li>
398
                                        <li>
399
                                            <span class="label">Sort 2:</span>
400
                                            [% IF ( CAN_user_editcatalogue_edit_items ) %]
401
                                                <form class="inline" action="updateitem.pl" method="post"><input type="hidden" name="biblionumber" value="[% ITEM_DAT.biblionumber | html %]" />
402
                                                    <input type="hidden" name="biblioitemnumber" value="[% ITEM_DAT.biblioitemnumber | html %]" /><input type="hidden" name="itemnumber" value="[% ITEM_DAT.itemnumber | html %]" />
403
                                                    <input type="hidden" name="op" value="set_sort2" />
404
                                                    <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" />
405
                                                </form>
406
                                            [% ELSE %]
407
                                                [% ITEM_DAT.sort2 | html %]
408
                                            [% END %]
409
                                        </li>
410
                                    </ol> <!-- /.bibliodetails -->
411
                                </div> <!-- /.rows -->
412
                            </div> <!-- /.listgroup -->
413
382
                            <div class="listgroup">
414
                            <div class="listgroup">
383
                                <h4>History</h4>
415
                                <h4>History</h4>
384
                                <div class="rows">
416
                                <div class="rows">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt (+12 lines)
Lines 218-223 Link Here
218
                                        </select>
218
                                        </select>
219
                                    </div>
219
                                    </div>
220
                                </li>
220
                                </li>
221
                                <li>
222
                                    <div class="subfield_line">
223
                                        <label for="sort1">Sort 1:</label>
224
                                        <input type="text" id="sort1" name="sort1" class="input_marceditor" maxlength="50" value="" />
225
                                    </div>
226
                                </li>
227
                                <li>
228
                                    <div class="subfield_line">
229
                                        <label for="sort1">Sort 2:</label>
230
                                        <input type="text" id="sort2" name="sort2" class="input_marceditor" maxlength="50" value="" />
231
                                    </div>
232
                                </li>
221
                            </ol>
233
                            </ol>
222
                        </fieldset>
234
                        </fieldset>
223
                        <fieldset class="rows">
235
                        <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 "cud-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