Lines 22-27
use Modern::Perl;
Link Here
|
22 |
|
22 |
|
23 |
use Carp; |
23 |
use Carp; |
24 |
use Mojo::JSON; |
24 |
use Mojo::JSON; |
|
|
25 |
use Try::Tiny; |
25 |
|
26 |
|
26 |
use Koha::Database; |
27 |
use Koha::Database; |
27 |
use Koha::Exceptions::Object; |
28 |
use Koha::Exceptions::Object; |
Lines 119-125
Returns:
Link Here
|
119 |
sub store { |
120 |
sub store { |
120 |
my ($self) = @_; |
121 |
my ($self) = @_; |
121 |
|
122 |
|
122 |
return $self->_result()->update_or_insert() ? $self : undef; |
123 |
try { |
|
|
124 |
return $self->_result()->update_or_insert() ? $self : undef; |
125 |
} |
126 |
catch { |
127 |
# Catch problems and raise relevant exceptions |
128 |
if (ref($_) eq 'DBIx::Class::Exception') { |
129 |
if ( $_->{msg} =~ /Cannot add or update a child row: a foreign key constraint fails/ ) { |
130 |
# FK constraints |
131 |
# FIXME: MySQL error, if we support more DB engines we should implement this for each |
132 |
if ( $_->{msg} =~ /FOREIGN KEY \(`(?<column>.*?)`\)/ ) { |
133 |
Koha::Exceptions::Object::FKConstraint->throw( |
134 |
error => 'Broken FK constraint', |
135 |
broken_fk => $+{column} |
136 |
); |
137 |
} |
138 |
else { |
139 |
# Catch-all for foreign key breakages. It will help find other use cases |
140 |
$->rethrow(); |
141 |
} |
142 |
} |
143 |
else { |
144 |
# TODO: find other exceptions we could handle |
145 |
$->rethrow(); |
146 |
} |
147 |
} |
148 |
} |
123 |
} |
149 |
} |
124 |
|
150 |
|
125 |
=head3 $object->delete(); |
151 |
=head3 $object->delete(); |
126 |
- |
|
|