Lines 2326-2368
sub add_to_bundle {
Link Here
|
2326 |
); |
2326 |
); |
2327 |
} catch { |
2327 |
} catch { |
2328 |
|
2328 |
|
2329 |
# FIXME: See if we can move the below copy/paste from Koha::Object::store into it's own class and catch at a lower level in the Schema instantiation, take inspiration from DBIx::Error |
2329 |
# Use centralized exception translation instead of duplicated code |
2330 |
if ( ref($_) eq 'DBIx::Class::Exception' ) { |
2330 |
$schema->translate_exception($_); |
2331 |
if ( $_->{msg} =~ /Cannot add or update a child row: a foreign key constraint fails/ ) { |
|
|
2332 |
|
2333 |
# FK constraints |
2334 |
# FIXME: MySQL error, if we support more DB engines we should implement this for each |
2335 |
if ( $_->{msg} =~ /FOREIGN KEY \(`(?<column>.*?)`\)/ ) { |
2336 |
Koha::Exceptions::Object::FKConstraint->throw( |
2337 |
error => 'Broken FK constraint', |
2338 |
broken_fk => $+{column} |
2339 |
); |
2340 |
} |
2341 |
} elsif ( $_->{msg} =~ /Duplicate entry '(.*?)' for key '(?<key>.*?)'/ ) { |
2342 |
Koha::Exceptions::Object::DuplicateID->throw( |
2343 |
error => 'Duplicate ID', |
2344 |
duplicate_id => $+{key} |
2345 |
); |
2346 |
} elsif ( $_->{msg} =~ /Incorrect (?<type>\w+) value: '(?<value>.*)' for column \W?(?<property>\S+)/ ) |
2347 |
{ # The optional \W in the regex might be a quote or backtick |
2348 |
my $type = $+{type}; |
2349 |
my $value = $+{value}; |
2350 |
my $property = $+{property}; |
2351 |
$property =~ s/['`]//g; |
2352 |
Koha::Exceptions::Object::BadValue->throw( |
2353 |
type => $type, |
2354 |
value => $value, |
2355 |
property => $property =~ /(\w+\.\w+)$/ |
2356 |
? $1 |
2357 |
: $property, # results in table.column without quotes or backtics |
2358 |
); |
2359 |
} |
2360 |
|
2361 |
# Catch-all for foreign key breakages. It will help find other use cases |
2362 |
$_->rethrow(); |
2363 |
} else { |
2364 |
$_->rethrow(); |
2365 |
} |
2366 |
}; |
2331 |
}; |
2367 |
} |
2332 |
} |
2368 |
|
2333 |
|
2369 |
- |
|
|