Bugzilla – Attachment 101149 Details for
Bug 20443
Move C4::Members::Attributes to Koha namespace
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20443: Handle non existent attribute when importing patrons
Bug-20443-Handle-non-existent-attribute-when-impor.patch (text/plain), 3.53 KB, created by
Jonathan Druart
on 2020-03-20 14:48:39 UTC
(
hide
)
Description:
Bug 20443: Handle non existent attribute when importing patrons
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-03-20 14:48:39 UTC
Size:
3.53 KB
patch
obsolete
>From 0fccace87d61d51ec91b7ea454a97d3b6c38613c Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 20 Mar 2020 09:38:03 +0100 >Subject: [PATCH] Bug 20443: Handle non existent attribute when importing > patrons > >There is much more to do here, but this patch has the same behavior than >before: a warn is displayed in the log, the UI is not aware of it > >Signed-off-by: Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > Koha/Patron.pm | 9 ++++++++- > t/db_dependent/Koha/Patrons.t | 18 ++++++++++++++++-- > 2 files changed, 24 insertions(+), 3 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 9a06db38c1..4cd9099d6a 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -1467,7 +1467,14 @@ sub extended_attributes { > > # Insert the new ones > for my $attribute (@$attributes) { >- $self->_result->create_related('borrower_attributes', $attribute); >+ eval { >+ $self->_result->create_related('borrower_attributes', $attribute); >+ }; >+ # FIXME We should: >+ # 1 - Raise an exception >+ # 2 - Execute in a transaction and don't save >+ # or Insert anyway but display a message on the UI >+ warn $@ if $@; > } > } > ); >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 8a66a3d0ae..a6ab9dc680 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -2021,7 +2021,7 @@ subtest 'anonymize' => sub { > $schema->storage->txn_rollback; > > subtest 'extended_attributes' => sub { >- plan tests => 10; >+ plan tests => 11; > my $schema = Koha::Database->new->schema; > $schema->storage->txn_begin; > >@@ -2046,6 +2046,10 @@ subtest 'extended_attributes' => sub { > } > )->store; > >+ my $deleted_attribute_type = $builder->build_object({ class => 'Koha::Patron::Attribute::Types' }); >+ my $deleted_attribute_type_code = $deleted_attribute_type->code; >+ $deleted_attribute_type->delete; >+ > my $new_library = $builder->build( { source => 'Branch' } ); > my $attribute_type_limited = Koha::Patron::Attribute::Type->new( > { code => 'my code3', description => 'my description3' } )->store; >@@ -2074,6 +2078,10 @@ subtest 'extended_attributes' => sub { > { > attribute => 'my attribute limited 2', > code => $attribute_type_limited->code(), >+ }, >+ { >+ attribute => 'my nonexistent attribute 2', >+ code => $deleted_attribute_type_code, > } > ]; > >@@ -2084,7 +2092,13 @@ subtest 'extended_attributes' => sub { > $patron_1->extended_attributes->filter_by_branch_limitations->delete; > $patron_2->extended_attributes->filter_by_branch_limitations->delete; > $patron_1->extended_attributes($attributes_for_1); >- $patron_2->extended_attributes($attributes_for_2); >+ >+ my $print_error = $schema->storage->dbh->{PrintError}; >+ $schema->storage->dbh->{PrintError} = 0; >+ warning_like { >+ $patron_2->extended_attributes($attributes_for_2); >+ } [ qr/a foreign key constraint fails/, qr/a foreign key constraint fails/ ], 'nonexistent attribute should have not exploded but print a warning'; >+ $schema->storage->dbh->{PrintError} = $print_error; > > my $extended_attributes_for_1 = $patron_1->extended_attributes; > is( $extended_attributes_for_1->count, 3, 'There should be 3 attributes now for patron 1'); >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20443
:
101122
|
101123
|
101124
|
101125
|
101126
|
101127
|
101128
|
101129
|
101130
|
101131
|
101132
|
101133
|
101134
|
101135
|
101136
|
101137
|
101138
|
101139
|
101140
|
101141
|
101142
|
101143
|
101144
|
101145
|
101146
|
101147
|
101148
|
101149
|
101150
|
101209
|
101210
|
101211
|
101212
|
101213
|
101214
|
101215
|
101216
|
101217
|
101218
|
101219
|
101220
|
101221
|
101222
|
101223
|
101224
|
101225
|
101226
|
101227
|
101228
|
101229
|
101230
|
101231
|
101232
|
101233
|
101234
|
101235
|
101236
|
101237
|
101472
|
104519