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

(-)a/Koha/Items.pm (+10 lines)
Lines 295-300 sub batch_update { Link Here
295
295
296
                my $old = $old_values->{$attribute};
296
                my $old = $old_values->{$attribute};
297
                my $new = $new_values->{$attribute};
297
                my $new = $new_values->{$attribute};
298
                if ( $attribute eq 'permanent_location' && $new eq '' ) {
299
300
                    # In the case where permanent_location is exposed we need
301
                    # to preserve the original value when none is passed
302
                    # the script will send a blank value to indicate that it was
303
                    # included in the form
304
                    $new_values->{permanent_location} = $old;
305
                    $item->make_column_dirty('permanent_location');
306
                    next; # We aren't modifying, we are preserving, so skip the increment
307
                }
298
                $modified++
308
                $modified++
299
                  if ( defined $old xor defined $new )
309
                  if ( defined $old xor defined $new )
300
                  || ( defined $old && defined $new && $new ne $old );
310
                  || ( defined $old && defined $new && $new ne $old );
(-)a/t/db_dependent/Koha/Items/BatchUpdate.t (-1 / +35 lines)
Lines 16-22 Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use Test::More tests=> 8;
19
use Test::More tests=> 9;
20
use Test::Warn;
20
use Test::Warn;
21
use utf8;
21
use utf8;
22
22
Lines 156-161 subtest 'blank' => sub { Link Here
156
156
157
};
157
};
158
158
159
subtest 'permanent_location' => sub {
160
161
    # This is a special case as some libraries add this field in the frameworks
162
    # to allow explicitly setting a temporary location.
163
    # When mapped an empty value is submitted in the form with the key of permanent_location
164
165
    plan tests => 2;
166
167
    $items->batch_update(
168
        {
169
            new_values => {
170
                'permanent_location' => 'perm',
171
                'location'           => 'loc'
172
            }
173
        }
174
    )->reset;
175
176
    $item = $item->get_from_storage;
177
    is( $item->permanent_location, 'perm', 'Updated as expected when value passed');
178
179
    $items->batch_update(
180
        {
181
            new_values => {
182
                'permanent_location' => '',
183
                'location'           => 'new_loc'
184
            }
185
        }
186
    )->reset;
187
188
    $item = $item->get_from_storage;
189
    is( $item->permanent_location, 'perm', 'Permanent location not updated when mapped, so key present, but no value passed ');
190
191
};
192
159
subtest 'regex' => sub {
193
subtest 'regex' => sub {
160
    plan tests => 12;
194
    plan tests => 12;
161
195
(-)a/tools/batchMod.pl (-2 / +5 lines)
Lines 155-161 if ( $op eq "action" ) { Link Here
155
                    my @v =
155
                    my @v =
156
                      grep { $_ ne "" } uniq $input->multi_param($cgi_var_name);
156
                      grep { $_ ne "" } uniq $input->multi_param($cgi_var_name);
157
157
158
                    next unless @v;
158
                    next unless @v || $attr eq 'permanent_location';
159
                    # If permanent_location is present in the form we need to pass it forward
160
                    # to indicate that the user may modify this field directly and so
161
                    # it needs to be marked as 'dirty' on any update. Otherwise the object always
162
                    # sets location to the permanent_location as well
159
163
160
                    $new_item_data->{$attr} = join '|', @v;
164
                    $new_item_data->{$attr} = join '|', @v;
161
                }
165
                }
162
- 

Return to bug 31187