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

(-)a/Koha/Patron.pm (-2 / +23 lines)
Lines 2237-2249 sub _generate_userid_internal { # as we always did Link Here
2237
sub add_extended_attribute {
2237
sub add_extended_attribute {
2238
    my ( $self, $attribute ) = @_;
2238
    my ( $self, $attribute ) = @_;
2239
2239
2240
    return Koha::Patron::Attribute->new(
2240
    my $change;
2241
    if (C4::Context->preference("BorrowersLog")) {
2242
        my @attribute_values_before = map { $_->attribute }
2243
            $self->extended_attributes->search({ 'me.code' => $attribute->{code} })->as_list;
2244
        my @attribute_values_after = sort ($attribute->{attribute}, @attribute_values_before);
2245
        $change = {
2246
            before => \@attribute_values_before,
2247
            after => \@attribute_values_after
2248
        }
2249
    }
2250
2251
    my $added_attribute =  Koha::Patron::Attribute->new(
2241
        {
2252
        {
2242
            %$attribute,
2253
            %{$attribute},
2243
            ( borrowernumber => $self->borrowernumber ),
2254
            ( borrowernumber => $self->borrowernumber ),
2244
        }
2255
        }
2245
    )->store;
2256
    )->store;
2246
2257
2258
    if (C4::Context->preference("BorrowersLog")) {
2259
        logaction(
2260
            "MEMBERS",
2261
            "MODIFY",
2262
            $self->borrowernumber,
2263
            "Patron attribute " . $attribute->{code} . ": " . to_json($change, { pretty => 1, canonical => 1 })
2264
        );
2265
    }
2266
2267
    return $added_attribute;
2247
}
2268
}
2248
2269
2249
=head3 extended_attributes
2270
=head3 extended_attributes
(-)a/t/db_dependent/Koha/Patron/Attribute.t (-1 / +27 lines)
Lines 524-530 subtest 'merge_and_replace_with' => sub { Link Here
524
};
524
};
525
525
526
subtest 'action log tests' => sub {
526
subtest 'action log tests' => sub {
527
    plan tests => 11;
527
    plan tests => 12;
528
    my $schema = Koha::Database->new->schema;
528
    my $schema = Koha::Database->new->schema;
529
    $schema->storage->txn_begin;
529
    $schema->storage->txn_begin;
530
530
Lines 741-745 subtest 'action log tests' => sub { Link Here
741
        "New action log entry has been created when updating repeatable patron attribute with existing multiple values with multiple values"
741
        "New action log entry has been created when updating repeatable patron attribute with existing multiple values with multiple values"
742
    );
742
    );
743
743
744
    my $attribute = {
745
        attribute => 'Qux',
746
        code => $attribute_type->code,
747
    };
748
    $patron->add_extended_attribute($attribute);
749
750
    $info = $get_info->(
751
        ['Foo', 'Bar', 'Baz'],
752
        ['Foo', 'Bar', 'Baz', 'Qux'],
753
        $attribute_type->code,
754
        1
755
    );
756
    $action_logs = Koha::ActionLogs->search(
757
        {
758
            module => "MEMBERS",
759
            action => "MODIFY",
760
            object => $patron->borrowernumber,
761
            info => $info
762
        }
763
    );
764
    is(
765
        $action_logs->count,
766
        1,
767
        "New action log entry has been created when updating patron attributes using add_extended_attribute"
768
    );
769
744
    $schema->storage->txn_rollback;
770
    $schema->storage->txn_rollback;
745
};
771
};
(-)a/tools/modborrowers.pl (-16 / +18 lines)
Lines 40-45 use Koha::Patron::Debarments qw( AddDebarment DelDebarment ); Link Here
40
use Koha::Patrons;
40
use Koha::Patrons;
41
use List::MoreUtils qw(uniq);
41
use List::MoreUtils qw(uniq);
42
use Koha::Patron::Messages;
42
use Koha::Patron::Messages;
43
use Try::Tiny;
43
44
44
my $input = CGI->new;
45
my $input = CGI->new;
45
my $op    = $input->param('op') || 'show_form';
46
my $op    = $input->param('op') || 'show_form';
Lines 428-433 if ( $op eq 'cud-do' ) { Link Here
428
            $attributes->{$code}->{disabled} = grep { $_ eq sprintf( "attr%s_value", $i++ ) } @disabled;
429
            $attributes->{$code}->{disabled} = grep { $_ eq sprintf( "attr%s_value", $i++ ) } @disabled;
429
        }
430
        }
430
431
432
        my @extended_attributes = map { { code => $_->code, attribute => $_->attribute } }
433
            $patron->extended_attributes->filter_by_branch_limitations->as_list;
434
431
        for my $code ( keys %$attributes ) {
435
        for my $code ( keys %$attributes ) {
432
            my $attr_type = Koha::Patron::Attribute::Types->find($code);
436
            my $attr_type = Koha::Patron::Attribute::Types->find($code);
433
437
Lines 436-460 if ( $op eq 'cud-do' ) { Link Here
436
            # If this borrower is not in the category of this attribute, we don't want to modify this attribute
440
            # If this borrower is not in the category of this attribute, we don't want to modify this attribute
437
            next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode;
441
            next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode;
438
442
439
            if ( $attributes->{$code}->{disabled} ) {
443
            # Remove any current values of same type
444
            @extended_attributes = grep { $_->{code} ne $code } @extended_attributes;
440
445
441
                # The attribute is disabled, we remove it for this borrower !
446
            # The attribute is disabled, we remove it for this borrower !
442
                eval {
447
            if ( !$attributes->{$code}->{disabled} ) {
443
                    $patron->extended_attributes->search( { 'me.code' => $code } )
448
                push @extended_attributes, { code => $code, attribute => $_}
444
                        ->filter_by_branch_limitations->delete;
449
                    for @{ $attributes->{$code}->{values} };
445
                };
446
                push @errors, { error => $@ } if $@;
447
            } else {
448
                eval {
449
                    $patron->extended_attributes->search( { 'me.code' => $code } )
450
                        ->filter_by_branch_limitations->delete;
451
                    $patron->add_extended_attribute( { code => $code, attribute => $_ } )
452
                        for @{ $attributes->{$code}->{values} };
453
                };
454
                push @errors, { error => $@ } if $@;
455
            }
450
            }
451
456
        }
452
        }
457
453
454
        try {
455
            $patron->extended_attributes(\@extended_attributes);
456
        } catch {
457
            my $message =  blessed $_ ? $_->full_message() : $_;
458
            push @errors, { error => $message };
459
        };
460
458
        # Handle patron messages
461
        # Handle patron messages
459
        my $message      = $input->param('message');
462
        my $message      = $input->param('message');
460
        my $branchcode   = C4::Context::mybranch;
463
        my $branchcode   = C4::Context::mybranch;
461
- 

Return to bug 26744