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

(-)a/Koha/Items.pm (+9 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
		    # In the case where permanent_location is exposed we need
300
		    # to preserve the original value when none is passed
301
		    # the script will send a blank value to indicate that it was
302
		    # included in the form
303
		    $modified++;
304
		    $new_values->{permanent_location} = $old;
305
		    $item->make_column_dirty('permanent_location');
306
	        }
298
                $modified++
307
                $modified++
299
                  if ( defined $old xor defined $new )
308
                  if ( defined $old xor defined $new )
300
                  || ( defined $old && defined $new && $new ne $old );
309
                  || ( defined $old && defined $new && $new ne $old );
(-)a/t/db_dependent/Koha/Items/BatchUpdate.t (-1 / +33 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
            new_values => {
169
	        'permanent_location' => 'perm',
170
		'location' => 'loc'
171
	    }
172
        });
173
    $items->reset;
174
175
    $item = $item->get_from_storage;
176
    is( $item->permanent_location, 'perm', 'Updated as expected when value passed');
177
178
    $items->batch_update({
179
            new_values => {
180
	        'permanent_location' => '',
181
		'location' => 'new_loc'
182
	    }
183
        });
184
    $items->reset;
185
186
    $item = $item->get_from_storage;
187
    is( $item->permanent_location, 'perm', 'Permanent location not updated when mapped, so key present, but no value passed ');
188
189
};
190
159
subtest 'regex' => sub {
191
subtest 'regex' => sub {
160
    plan tests => 12;
192
    plan tests => 12;
161
193
(-)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