Lines 414-457
If log_action is true or undefined, the action will be logged.
Link Here
|
414 |
sub ModItem { |
414 |
sub ModItem { |
415 |
my ( $item, $biblionumber, $itemnumber, $additional_params ) = @_; |
415 |
my ( $item, $biblionumber, $itemnumber, $additional_params ) = @_; |
416 |
my $log_action = $additional_params->{log_action} // 1; |
416 |
my $log_action = $additional_params->{log_action} // 1; |
417 |
my $unlinked_item_subfields = $additional_params->{unlinked_item_subfields}; |
|
|
418 |
|
419 |
return unless %$item; |
420 |
$item->{'itemnumber'} = $itemnumber or return; |
421 |
|
422 |
# if $biblionumber is undefined, get it from the current item |
423 |
unless (defined $biblionumber) { |
424 |
$biblionumber = _get_single_item_column('biblionumber', $itemnumber); |
425 |
} |
426 |
|
427 |
if ($unlinked_item_subfields) { |
428 |
$item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields); |
429 |
}; |
430 |
|
431 |
my @fields = qw( itemlost withdrawn damaged ); |
432 |
|
433 |
# Only retrieve the item if we need to set an "on" date field |
434 |
if ( $item->{itemlost} || $item->{withdrawn} || $item->{damaged} ) { |
435 |
my $pre_mod_item = Koha::Items->find( $item->{'itemnumber'} ); |
436 |
for my $field (@fields) { |
437 |
if ( defined( $item->{$field} ) |
438 |
and not $pre_mod_item->$field |
439 |
and $item->{$field} ) |
440 |
{ |
441 |
$item->{ $field . '_on' } = |
442 |
DateTime::Format::MySQL->format_datetime( dt_from_string() ); |
443 |
} |
444 |
} |
445 |
} |
446 |
|
447 |
# If the field is defined but empty, we are removing and, |
448 |
# and thus need to clear out the 'on' field as well |
449 |
for my $field (@fields) { |
450 |
if ( defined( $item->{$field} ) && !$item->{$field} ) { |
451 |
$item->{ $field . '_on' } = undef; |
452 |
} |
453 |
} |
454 |
|
455 |
|
417 |
|
456 |
_set_derived_columns_for_mod($item); |
418 |
_set_derived_columns_for_mod($item); |
457 |
_do_column_fixes_for_mod($item); |
419 |
_do_column_fixes_for_mod($item); |
Lines 1308-1360
sub _set_derived_columns_for_add {
Link Here
|
1308 |
} |
1270 |
} |
1309 |
} |
1271 |
} |
1310 |
|
1272 |
|
1311 |
=head2 _set_derived_columns_for_mod |
|
|
1312 |
|
1313 |
_set_derived_column_for_mod($item); |
1314 |
|
1315 |
Given an item hash representing a new item to be modified. |
1316 |
calculate any derived columns. Currently the only |
1317 |
such column is C<items.cn_sort>. |
1318 |
|
1319 |
This routine differs from C<_set_derived_columns_for_add> |
1320 |
in that it needs to handle partial item records. In other |
1321 |
words, the caller of C<ModItem> may have supplied only one |
1322 |
or two columns to be changed, so this function needs to |
1323 |
determine whether any of the columns to be changed affect |
1324 |
any of the derived columns. Also, if a derived column |
1325 |
depends on more than one column, but the caller is not |
1326 |
changing all of then, this routine retrieves the unchanged |
1327 |
values from the database in order to ensure a correct |
1328 |
calculation. |
1329 |
|
1330 |
=cut |
1331 |
|
1332 |
sub _set_derived_columns_for_mod { |
1333 |
my $item = shift; |
1334 |
|
1335 |
foreach my $column (keys %derived_columns) { |
1336 |
my $builder = $derived_columns{$column}->{'BUILDER'}; |
1337 |
my $source_values = {}; |
1338 |
my %missing_sources = (); |
1339 |
my $must_recalc = 0; |
1340 |
foreach my $source_column (keys %{ $derived_columns{$column} }) { |
1341 |
next if $source_column eq 'BUILDER'; |
1342 |
if (exists $item->{$source_column}) { |
1343 |
$must_recalc = 1; |
1344 |
$source_values->{$source_column} = $item->{$source_column}; |
1345 |
} else { |
1346 |
$missing_sources{$source_column} = 1; |
1347 |
} |
1348 |
} |
1349 |
if ($must_recalc) { |
1350 |
foreach my $source_column (keys %missing_sources) { |
1351 |
$source_values->{$source_column} = _get_single_item_column($source_column, $item->{'itemnumber'}); |
1352 |
} |
1353 |
$builder->($item, $source_values); |
1354 |
} |
1355 |
} |
1356 |
} |
1357 |
|
1358 |
=head2 _do_column_fixes_for_mod |
1273 |
=head2 _do_column_fixes_for_mod |
1359 |
|
1274 |
|
1360 |
_do_column_fixes_for_mod($item); |
1275 |
_do_column_fixes_for_mod($item); |
1361 |
- |
|
|