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

(-)a/C4/Circulation.pm (-39 / +21 lines)
Lines 21-27 package C4::Circulation; Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
use DateTime;
22
use DateTime;
23
use POSIX qw( floor );
23
use POSIX qw( floor );
24
use YAML::XS;
25
use Encode;
24
use Encode;
26
25
27
use C4::Context;
26
use C4::Context;
Lines 1798-1818 sub AddIssue { Link Here
1798
                }
1797
                }
1799
            }
1798
            }
1800
1799
1801
            my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckout');
1800
            my $rules = C4::Context->yaml_preference('UpdateNotForLoanStatusOnCheckout');
1802
            if ($yaml) {
1801
            if ($rules) {
1803
                $yaml = "$yaml\n\n";
1802
                foreach my $key ( keys %$rules ) {
1804
1803
                    if ( $item_object->notforloan eq $key ) {
1805
                my $rules;
1804
                        $item_object->notforloan($rules->{$key})->store({ log_action => 0, skip_record_index => 1 });
1806
                eval { $rules = YAML::XS::Load(Encode::encode_utf8($yaml)); };
1805
                        last;
1807
                if ($@) {
1808
                    warn "Unable to parse UpdateNotForLoanStatusOnCheckout syspref : $@";
1809
                }
1810
                else {
1811
                    foreach my $key ( keys %$rules ) {
1812
                        if ( $item_object->notforloan eq $key ) {
1813
                            $item_object->notforloan($rules->{$key})->store({ log_action => 0, skip_record_index => 1 });
1814
                            last;
1815
                        }
1816
                    }
1806
                    }
1817
                }
1807
                }
1818
            }
1808
            }
Lines 2215-2244 sub AddReturn { Link Here
2215
        $messages->{ $loc_msg_key } = $loc_messages->{ $loc_msg_key };
2205
        $messages->{ $loc_msg_key } = $loc_messages->{ $loc_msg_key };
2216
    }
2206
    }
2217
2207
2218
    my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin');
2208
    my $rules = C4::Context->yaml_preference('UpdateNotForLoanStatusOnCheckin');
2219
    if ($yaml) {
2209
    if ($rules) {
2220
        $yaml = "$yaml\n\n";  # YAML is anal on ending \n. Surplus does not hurt
2210
        if ( defined $rules->{$item->itype} ) {
2221
        my $rules;
2211
            foreach my $notloan_rule_key (keys %{ $rules->{$item->itype}} ) {
2222
        eval { $rules = YAML::XS::Load(Encode::encode_utf8($yaml)); };
2212
                if ( $item->notforloan eq $notloan_rule_key ) {
2223
        if ($@) {
2213
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$item->itype}->{$notloan_rule_key} };
2224
            warn "Unable to parse UpdateNotForLoanStatusOnCheckin syspref : $@";
2214
                    $item->notforloan($rules->{$item->itype}->{$notloan_rule_key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1 });
2225
        }
2215
                    last;
2226
        else {
2227
            if ( defined $rules->{$item->itype} ) {
2228
                foreach my $notloan_rule_key (keys %{ $rules->{$item->itype}} ) {
2229
                    if ( $item->notforloan eq $notloan_rule_key ) {
2230
                        $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$item->itype}->{$notloan_rule_key} };
2231
                        $item->notforloan($rules->{$item->itype}->{$notloan_rule_key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1 });
2232
                        last;
2233
                    }
2234
                }
2216
                }
2235
            } elsif ( defined $rules->{'_ALL_'} ) {
2217
            }
2236
                foreach my $notloan_rule_key (keys %{ $rules->{'_ALL_'}} ) {
2218
        } elsif ( defined $rules->{'_ALL_'} ) {
2237
                    if ( $item->notforloan eq $notloan_rule_key ) {
2219
            foreach my $notloan_rule_key (keys %{ $rules->{'_ALL_'}} ) {
2238
                        $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{'_ALL_'}->{$notloan_rule_key} };
2220
                if ( $item->notforloan eq $notloan_rule_key ) {
2239
                        $item->notforloan($rules->{'_ALL_'}->{$notloan_rule_key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1 });
2221
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{'_ALL_'}->{$notloan_rule_key} };
2240
                        last;
2222
                    $item->notforloan($rules->{'_ALL_'}->{$notloan_rule_key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1 });
2241
                    }
2223
                    last;
2242
                }
2224
                }
2243
            }
2225
            }
2244
        }
2226
        }
(-)a/C4/Context.pm (-2 / +1 lines)
Lines 342-348 the value cannot be properly decoded as YAML. Link Here
342
sub yaml_preference {
342
sub yaml_preference {
343
    my ( $self, $preference ) = @_;
343
    my ( $self, $preference ) = @_;
344
344
345
    my $yaml = eval { YAML::XS::Load( Encode::encode_utf8( $self->preference( $preference ) ) ); };
345
    my $yaml = eval { YAML::XS::Load( Encode::encode_utf8( $self->preference( $preference ) // '' ) ); };
346
    if ($@) {
346
    if ($@) {
347
        warn "Unable to parse $preference syspref : $@";
347
        warn "Unable to parse $preference syspref : $@";
348
        return;
348
        return;
349
- 

Return to bug 33431