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

(-)a/Koha/Item.pm (-57 / +46 lines)
Lines 2783-2788 FIXME: It should return I<$self>. See bug 35270. Link Here
2783
sub location_update_trigger {
2783
sub location_update_trigger {
2784
    my ( $self, $action ) = @_;
2784
    my ( $self, $action ) = @_;
2785
2785
2786
    if (my $new_location = $self->_check_location_update_rules($action)) {
2787
        my $messages = {
2788
            'ItemLocationUpdated' => {
2789
                from => $self->location,
2790
                to   => $new_location,
2791
            }
2792
        };
2793
        $self->location($new_location)->store(
2794
            {
2795
                log_action        => 0,
2796
                skip_record_index => 1,
2797
                skip_holds_queue  => 1
2798
            }
2799
        );
2800
        return $messages;
2801
    }
2802
    return undef;
2803
}
2804
2805
sub _check_location_update_rules {
2806
    my ($self, $action) = @_;
2786
    my ( $update_loc_rules, $messages );
2807
    my ( $update_loc_rules, $messages );
2787
    if ( $action eq 'checkin' ) {
2808
    if ( $action eq 'checkin' ) {
2788
        $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckin');
2809
        $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckin');
Lines 2791-2854 sub location_update_trigger { Link Here
2791
    }
2812
    }
2792
2813
2793
    if ($update_loc_rules) {
2814
    if ($update_loc_rules) {
2794
        if ( defined $update_loc_rules->{_ALL_} ) {
2815
        if (defined($update_loc_rules->{'_ALL_'})) {
2795
            if ( $update_loc_rules->{_ALL_} eq '_PERM_' ) {
2816
            return $self->_check_location_update_rule($update_loc_rules->{'_ALL_'});
2796
                $update_loc_rules->{_ALL_} = $self->permanent_location;
2817
        }
2797
            }
2818
        elsif (defined($update_loc_rules->{$self->location//''})) {
2798
            if ( $update_loc_rules->{_ALL_} eq '_BLANK_' ) {
2819
            return $self->_check_location_update_rule($update_loc_rules->{$self->location});
2799
                $update_loc_rules->{_ALL_} = '';
2800
            }
2801
            if (
2802
                ( defined $self->location && $self->location ne $update_loc_rules->{_ALL_} )
2803
                || ( !defined $self->location
2804
                    && $update_loc_rules->{_ALL_} ne "" )
2805
                )
2806
            {
2807
                $messages->{'ItemLocationUpdated'} =
2808
                    { from => $self->location, to => $update_loc_rules->{_ALL_} };
2809
                $self->location( $update_loc_rules->{_ALL_} )->store(
2810
                    {
2811
                        log_action        => 0,
2812
                        skip_record_index => 1,
2813
                        skip_holds_queue  => 1
2814
                    }
2815
                );
2816
            }
2817
        } else {
2818
            foreach my $key ( keys %$update_loc_rules ) {
2819
                if ( $update_loc_rules->{$key} eq '_PERM_' ) {
2820
                    $update_loc_rules->{$key} = $self->permanent_location;
2821
                } elsif ( $update_loc_rules->{$key} eq '_BLANK_' ) {
2822
                    $update_loc_rules->{$key} = '';
2823
                }
2824
                if (
2825
                    (
2826
                           defined $self->location
2827
                        && $self->location eq $key
2828
                        && $self->location ne $update_loc_rules->{$key}
2829
                    )
2830
                    || (   $key eq '_BLANK_'
2831
                        && ( !defined $self->location || $self->location eq '' )
2832
                        && $update_loc_rules->{$key} ne '' )
2833
                    )
2834
                {
2835
                    $messages->{'ItemLocationUpdated'} = {
2836
                        from => $self->location,
2837
                        to   => $update_loc_rules->{$key}
2838
                    };
2839
                    $self->location( $update_loc_rules->{$key} )->store(
2840
                        {
2841
                            log_action        => 0,
2842
                            skip_record_index => 1,
2843
                            skip_holds_queue  => 1
2844
                        }
2845
                    );
2846
                    last;
2847
                }
2848
            }
2849
        }
2820
        }
2821
        elsif (defined($update_loc_rules->{'_DEFAULT_'})) {
2822
            return $self->_check_location_update_rule($update_loc_rules->{'_DEFAULT_'});
2823
        }
2824
    }
2825
}
2826
2827
2828
sub _check_location_update_rule {
2829
    my ($self, $update_loc_rule) = @_;
2830
2831
    if ($update_loc_rule eq '_PERM_') {
2832
        $update_loc_rule = $self->permanent_location;
2833
    }
2834
    if ($update_loc_rule eq '_BLANK_') {
2835
        $update_loc_rule = '';
2836
    }
2837
    if ((defined($self->location) && $self->location ne $update_loc_rule) ||
2838
        (not(defined($self->location)) && $update_loc_rule ne "" )) {
2839
        return $update_loc_rule;
2850
    }
2840
    }
2851
    return $messages;
2841
    return undef;
2852
}
2842
}
2853
2843
2854
=head3 z3950_status
2844
=head3 z3950_status
2855
- 

Return to bug 29326