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

(-)a/Koha/Patron.pm (-11 / +7 lines)
Lines 21-27 package Koha::Patron; Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
22
23
use List::MoreUtils    qw( any none uniq notall zip6);
23
use List::MoreUtils    qw( any none uniq notall zip6);
24
use JSON               qw( to_json );
25
use Scalar::Util       qw( blessed looks_like_number );
24
use Scalar::Util       qw( blessed looks_like_number );
26
use Unicode::Normalize qw( NFKD );
25
use Unicode::Normalize qw( NFKD );
27
use Try::Tiny;
26
use Try::Tiny;
Lines 2553-2562 sub add_extended_attribute { Link Here
2553
    if ( C4::Context->preference("BorrowersLog") ) {
2552
    if ( C4::Context->preference("BorrowersLog") ) {
2554
        my $code = $attribute->{code};
2553
        my $code = $attribute->{code};
2555
        logaction(
2554
        logaction(
2556
            "MEMBERS",
2555
            "MEMBERS", "MODIFY", $self->borrowernumber,
2557
            "MODIFY",
2556
            { "attribute.$code" => $change->{after} },
2558
            $self->borrowernumber,
2557
            undef,
2559
            to_json( { "attribute.$code" => $change }, { pretty => 1, canonical => 1 } )
2558
            { "attribute.$code" => $change->{before} }
2560
        );
2559
        );
2561
    }
2560
    }
2562
2561
Lines 2680-2691 sub extended_attributes { Link Here
2680
                }
2679
                }
2681
2680
2682
                if ( %{$all_changes} ) {
2681
                if ( %{$all_changes} ) {
2683
                    logaction(
2682
                    my %log_from = map { $_ => $all_changes->{$_}->{before} } keys %{$all_changes};
2684
                        "MEMBERS",
2683
                    my %log_to   = map { $_ => $all_changes->{$_}->{after} } keys %{$all_changes};
2685
                        "MODIFY",
2684
                    logaction( "MEMBERS", "MODIFY", $self->borrowernumber, \%log_to, undef, \%log_from );
2686
                        $self->borrowernumber,
2687
                        to_json( $all_changes, { pretty => 1, canonical => 1 } )
2688
                    );
2689
                }
2685
                }
2690
            }
2686
            }
2691
        );
2687
        );
(-)a/t/db_dependent/Koha/Patron/Attribute.t (-17 / +4 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <https://www.gnu.org/licenses>.
18
# along with Koha; if not, see <https://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use JSON qw( to_json );
21
use JSON qw( encode_json from_json );
22
22
23
use Test::NoWarnings;
23
use Test::NoWarnings;
24
use Test::More tests => 5;
24
use Test::More tests => 5;
Lines 531-550 subtest 'action log tests' => sub { Link Here
531
531
532
    my $get_info = sub {
532
    my $get_info = sub {
533
        my ( $before, $after, $code, $repeatable ) = @_;
533
        my ( $before, $after, $code, $repeatable ) = @_;
534
        my $change = {
535
            before => $before,
536
            after  => $after
537
        };
538
        if ($repeatable) {
534
        if ($repeatable) {
539
            while ( my ( $k, $v ) = each %{$change} ) {
535
            $after = ref $after eq 'ARRAY' ? [ sort @{$after} ] : ( $after ? [$after] : [] );
540
                if ( ref $v eq 'ARRAY' ) {
541
                    $change->{$k} = [ sort @{$v} ];
542
                } else {
543
                    $change->{$k} = $v ? [$v] : [];
544
                }
545
            }
546
        }
536
        }
547
        return to_json( { "attribute.$code" => $change }, { pretty => 1, canonical => 1 } );
537
        return encode_json( { "attribute.$code" => $after } );
548
    };
538
    };
549
539
550
    my $patron         = $builder->build_object( { class => 'Koha::Patrons' } );
540
    my $patron         = $builder->build_object( { class => 'Koha::Patrons' } );
Lines 689-697 subtest 'action log tests' => sub { Link Here
689
    ];
679
    ];
690
    $patron->extended_attributes($attributes);
680
    $patron->extended_attributes($attributes);
691
681
692
    $info = $get_info->( [], [ 'Foo', 'Bar' ], $attribute_type->code, 1 );
682
    $info        = $get_info->( [], [ 'Foo', 'Bar' ], $attribute_type->code, 1 );
693
    use Data::Dumper;
694
    print Dumper($info);
695
    $action_logs = Koha::ActionLogs->search(
683
    $action_logs = Koha::ActionLogs->search(
696
        {
684
        {
697
            module => "MEMBERS",
685
            module => "MEMBERS",
698
- 

Return to bug 40136