|
Lines 2442-2484
sub add_to_bundle {
Link Here
|
| 2442 |
); |
2442 |
); |
| 2443 |
} catch { |
2443 |
} catch { |
| 2444 |
|
2444 |
|
| 2445 |
# 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 |
2445 |
# Use centralized exception translation instead of duplicated code |
| 2446 |
if ( ref($_) eq 'DBIx::Class::Exception' ) { |
2446 |
$schema->translate_exception($_); |
| 2447 |
if ( $_->{msg} =~ /Cannot add or update a child row: a foreign key constraint fails/ ) { |
|
|
| 2448 |
|
| 2449 |
# FK constraints |
| 2450 |
# FIXME: MySQL error, if we support more DB engines we should implement this for each |
| 2451 |
if ( $_->{msg} =~ /FOREIGN KEY \(`(?<column>.*?)`\)/ ) { |
| 2452 |
Koha::Exceptions::Object::FKConstraint->throw( |
| 2453 |
error => 'Broken FK constraint', |
| 2454 |
broken_fk => $+{column} |
| 2455 |
); |
| 2456 |
} |
| 2457 |
} elsif ( $_->{msg} =~ /Duplicate entry '(.*?)' for key '(?<key>.*?)'/ ) { |
| 2458 |
Koha::Exceptions::Object::DuplicateID->throw( |
| 2459 |
error => 'Duplicate ID', |
| 2460 |
duplicate_id => $+{key} |
| 2461 |
); |
| 2462 |
} elsif ( $_->{msg} =~ /Incorrect (?<type>\w+) value: '(?<value>.*)' for column \W?(?<property>\S+)/ ) |
| 2463 |
{ # The optional \W in the regex might be a quote or backtick |
| 2464 |
my $type = $+{type}; |
| 2465 |
my $value = $+{value}; |
| 2466 |
my $property = $+{property}; |
| 2467 |
$property =~ s/['`]//g; |
| 2468 |
Koha::Exceptions::Object::BadValue->throw( |
| 2469 |
type => $type, |
| 2470 |
value => $value, |
| 2471 |
property => $property =~ /(\w+\.\w+)$/ |
| 2472 |
? $1 |
| 2473 |
: $property, # results in table.column without quotes or backtics |
| 2474 |
); |
| 2475 |
} |
| 2476 |
|
| 2477 |
# Catch-all for foreign key breakages. It will help find other use cases |
| 2478 |
$_->rethrow(); |
| 2479 |
} else { |
| 2480 |
$_->rethrow(); |
| 2481 |
} |
| 2482 |
}; |
2447 |
}; |
| 2483 |
} |
2448 |
} |
| 2484 |
|
2449 |
|
| 2485 |
- |
|
|