Bugzilla – Attachment 186648 Details for
Bug 19871
Use new exceptions Koha::Exceptions::Object::DuplicateID and FKConstraint
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19871: Update Koha::Patron::Modification to use centralized exception handling
Bug-19871-Update-KohaPatronModification-to-use-cen.patch (text/plain), 4.92 KB, created by
Martin Renvoize (ashimema)
on 2025-09-21 15:15:11 UTC
(
hide
)
Description:
Bug 19871: Update Koha::Patron::Modification to use centralized exception handling
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-09-21 15:15:11 UTC
Size:
4.92 KB
patch
obsolete
>From e2da96dabba83bd9386ba427d8bbbaa486f02dc2 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Sun, 21 Sep 2025 15:35:34 +0100 >Subject: [PATCH] Bug 19871: Update Koha::Patron::Modification to use > centralized exception handling > >Replace manual DBIx::Class::Exception handling in the approve() method with >the centralized exception translation system while preserving domain-specific >exception behavior. > >Changes: >- Use $schema->safe_do() for database operations with automatic exception translation >- Wrap safe_do in try/catch to convert any exception to domain-specific Patron::Modification exception >- Simplify exception handling logic while maintaining the same API contract >- Remove manual DBIx::Class::Exception type checking > >This maintains backward compatibility by always throwing >Koha::Exceptions::Patron::Modification exceptions as before, but leverages >the centralized system for consistent database exception handling. >--- > Koha/Patron/Modification.pm | 67 +++++++++++++++++++------------------ > 1 file changed, 35 insertions(+), 32 deletions(-) > >diff --git a/Koha/Patron/Modification.pm b/Koha/Patron/Modification.pm >index 5c36a71cbca..0939eb0f815 100644 >--- a/Koha/Patron/Modification.pm >+++ b/Koha/Patron/Modification.pm >@@ -111,43 +111,46 @@ sub approve { > }; > } > >- $self->_result->result_source->schema->txn_do( >+ my $schema = $self->_result->result_source->schema; >+ $schema->txn_do( > sub { > try { >- $patron->store(); >- >- # Deal with attributes >- my @codes = uniq( map { $_->{code} } @{$extended_attributes} ); >- foreach my $code (@codes) { >- map { $_->delete } Koha::Patron::Attributes->search( >- { >- borrowernumber => $patron->borrowernumber, >- code => $code >+ $schema->safe_do( >+ sub { >+ $patron->store(); >+ >+ # Deal with attributes >+ my @codes = uniq( map { $_->{code} } @{$extended_attributes} ); >+ foreach my $code (@codes) { >+ map { $_->delete } Koha::Patron::Attributes->search( >+ { >+ borrowernumber => $patron->borrowernumber, >+ code => $code >+ } >+ )->as_list; > } >- )->as_list; >- } >- foreach my $attr ( @{$extended_attributes} ) { >- $attr->{attribute} = exists $attr->{attribute} ? $attr->{attribute} : $attr->{value}; >- Koha::Patron::Attribute->new( >- { >- borrowernumber => $patron->borrowernumber, >- code => $attr->{code}, >- attribute => $attr->{attribute}, >+ foreach my $attr ( @{$extended_attributes} ) { >+ $attr->{attribute} = exists $attr->{attribute} ? $attr->{attribute} : $attr->{value}; >+ Koha::Patron::Attribute->new( >+ { >+ borrowernumber => $patron->borrowernumber, >+ code => $attr->{code}, >+ attribute => $attr->{attribute}, >+ } >+ )->store >+ if $attr->{attribute} # there's a value >+ or ( >+ defined $attr->{attribute} # there's a value that is 0, and not >+ && $attr->{attribute} ne "" # the empty string which means delete >+ && $attr->{attribute} == 0 >+ ); > } >- )->store >- if $attr->{attribute} # there's a value >- or ( >- defined $attr->{attribute} # there's a value that is 0, and not >- && $attr->{attribute} ne "" # the empty string which means delete >- && $attr->{attribute} == 0 >- ); >- } >+ } >+ ); > } catch { >- if ( $_->isa('DBIx::Class::Exception') ) { >- Koha::Exceptions::Patron::Modification->throw( $_->{msg} ); >- } else { >- Koha::Exceptions::Patron::Modification->throw($_); >- } >+ >+ # Convert any exception to domain-specific exception >+ Koha::Exceptions::Patron::Modification->throw($_); > }; > } > ); >-- >2.51.0
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 19871
:
186634
|
186635
|
186644
|
186645
|
186646
|
186647
| 186648 |
186649
|
186650