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

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

Return to bug 31187