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

(-)a/Koha/Exceptions/Patron.pm (+5 lines)
Lines 19-24 use Exception::Class ( Link Here
19
        isa         => 'Koha::Exceptions::Patron',
19
        isa         => 'Koha::Exceptions::Patron',
20
        description => "Deleting patron failed, AnonymousPatron is not deleteable"
20
        description => "Deleting patron failed, AnonymousPatron is not deleteable"
21
    },
21
    },
22
    'Koha::Exceptions::Patron::InvalidUserid' => {
23
        isa         => 'Koha::Exceptions::Patron',
24
        description => 'Field userid is not valid (probably not unique)',
25
        fields      => [ 'userid' ],
26
    },
22
    'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute' => {
27
    'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute' => {
23
        isa         => 'Koha::Exceptions::Patron',
28
        isa         => 'Koha::Exceptions::Patron',
24
        description => "Mandatory extended attribute missing",
29
        description => "Mandatory extended attribute missing",
(-)a/Koha/Patron.pm (-8 / +8 lines)
Lines 225-232 sub store { Link Here
225
            unless ( $self->in_storage ) {    #AddMember
225
            unless ( $self->in_storage ) {    #AddMember
226
226
227
                # Generate a valid userid/login if needed
227
                # Generate a valid userid/login if needed
228
                $self->generate_userid
228
                $self->generate_userid unless $self->userid;
229
                  if not $self->userid or not $self->has_valid_userid;
229
                Koha::Exceptions::Patron::InvalidUserid->throw( userid => $self->userid )
230
                    unless $self->has_valid_userid;
230
231
231
                # Add expiration date if it isn't already there
232
                # Add expiration date if it isn't already there
232
                unless ( $self->dateexpiry ) {
233
                unless ( $self->dateexpiry ) {
Lines 291-302 sub store { Link Here
291
            else {    #ModMember
292
            else {    #ModMember
292
293
293
                my $self_from_storage = $self->get_from_storage;
294
                my $self_from_storage = $self->get_from_storage;
294
                # FIXME We should not deal with that here, callers have to do this job
295
295
                # Moved from ModMember to prevent regressions
296
                # Do not accept invalid userid here
296
                unless ( $self->userid ) {
297
                $self->generate_userid unless $self->userid;
297
                    my $stored_userid = $self_from_storage->userid;
298
                Koha::Exceptions::Patron::InvalidUserid->throw( userid => $self->userid )
298
                    $self->userid($stored_userid);
299
                      unless $self->has_valid_userid;
299
                }
300
300
301
                # Password must be updated using $self->set_password
301
                # Password must be updated using $self->set_password
302
                $self->password($self_from_storage->password);
302
                $self->password($self_from_storage->password);
(-)a/t/db_dependent/Koha/Patrons.t (-14 / +8 lines)
Lines 1810-1833 subtest 'Test Koha::Patrons::merge' => sub { Link Here
1810
};
1810
};
1811
1811
1812
subtest '->store' => sub {
1812
subtest '->store' => sub {
1813
    plan tests => 8;
1813
    plan tests => 9;
1814
    my $schema = Koha::Database->new->schema;
1814
    my $schema = Koha::Database->new->schema;
1815
    $schema->storage->txn_begin;
1815
    $schema->storage->txn_begin;
1816
1816
1817
    my $print_error = $schema->storage->dbh->{PrintError};
1818
    $schema->storage->dbh->{PrintError} = 0; ; # FIXME This does not longer work - because of the transaction in Koha::Patron->store?
1819
1820
    my $patron_1 = $builder->build_object({class=> 'Koha::Patrons'});
1817
    my $patron_1 = $builder->build_object({class=> 'Koha::Patrons'});
1821
    my $patron_2 = $builder->build_object({class=> 'Koha::Patrons'});
1818
    my $patron_2 = $builder->build_object({class=> 'Koha::Patrons'});
1822
1819
1823
    {
1820
    throws_ok { $patron_2->userid( $patron_1->userid )->store; }
1824
        local *STDERR;
1821
        'Koha::Exceptions::Patron::InvalidUserid',
1825
        open STDERR, '>', '/dev/null';
1822
        'Koha::Patron->store raises an exception on duplicate ID';
1826
        throws_ok { $patron_2->userid( $patron_1->userid )->store; }
1823
1827
        'Koha::Exceptions::Object::DuplicateID',
1824
    # Clear userid and check regeneration
1828
          'Koha::Patron->store raises an exception on duplicate ID';
1825
    $patron_2->userid(undef)->store;
1829
        close STDERR;
1826
    like( $patron_2->userid, qr/\w+\.\w+/, 'Userid regenerated' ); # old school userid
1830
    }
1831
1827
1832
    # Test password
1828
    # Test password
1833
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
1829
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
Lines 1853-1859 subtest '->store' => sub { Link Here
1853
    $patron_1->relationship("")->store;
1849
    $patron_1->relationship("")->store;
1854
    is( $patron_1->relationship, undef, );
1850
    is( $patron_1->relationship, undef, );
1855
1851
1856
    $schema->storage->dbh->{PrintError} = $print_error;
1857
    $schema->storage->txn_rollback;
1852
    $schema->storage->txn_rollback;
1858
1853
1859
    subtest 'skip updated_on for BorrowersLog' => sub {
1854
    subtest 'skip updated_on for BorrowersLog' => sub {
1860
- 

Return to bug 32426