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