View | Details | Raw Unified | Return to bug 37510
Collapse All | Expand All

(-)a/Koha/Exceptions/Object.pm (+5 lines)
Lines 33-38 use Exception::Class ( Link Here
33
        description => "Foreign key constraint broken",
33
        description => "Foreign key constraint broken",
34
        fields      =>  ['broken_fk', 'value'],
34
        fields      =>  ['broken_fk', 'value'],
35
    },
35
    },
36
    'Koha::Exceptions::Object::FKConstraintDeletion' => {
37
        isa         => 'Koha::Exceptions::Object',
38
        description => "Foreign key constraint broken on deleting resource",
39
        fields      => [ 'column', 'fk', 'table', 'constraint' ],
40
    },
36
    'Koha::Exceptions::Object::MethodNotFound' => {
41
    'Koha::Exceptions::Object::MethodNotFound' => {
37
        isa => 'Koha::Exceptions::Object',
42
        isa => 'Koha::Exceptions::Object',
38
        description => "Invalid method",
43
        description => "Invalid method",
(-)a/Koha/Object.pm (-3 / +23 lines)
Lines 233-243 Returns: Link Here
233
sub delete {
233
sub delete {
234
    my ($self) = @_;
234
    my ($self) = @_;
235
235
236
    my $deleted = $self->_result()->delete;
236
    my $deleted;
237
238
    try {
239
        $deleted = $self->_result()->delete;
240
    } catch {
241
        if ( ref($_) eq 'DBIx::Class::Exception' ) {
242
            if ( $_->{msg} =~
243
                /Cannot delete or update a parent row\: a foreign key constraint fails \(\`(?<database>.*?)\`\.\`(?<table>.*?)\`, CONSTRAINT \`(?<constraint>.*?)\` FOREIGN KEY \(\`(?<fk>.*?)\`\) REFERENCES \`.*\` \(\`(?<column>.*?)\`\)/
244
                )
245
            {
246
                Koha::Exceptions::Object::FKConstraintDeletion->throw(
247
                    column     => $+{column},
248
                    constraint => $+{constraint},
249
                    fk         => $+{fk},
250
                    table      => $+{table},
251
                );
252
            }
253
            $_->rethrow();
254
        }
255
    };
256
237
    if ( ref $deleted ) {
257
    if ( ref $deleted ) {
238
        my $object_class  = Koha::Object::_get_object_class( $self->_result->result_class );
258
        my $object_class = Koha::Object::_get_object_class( $self->_result->result_class );
239
        $deleted = $object_class->_new_from_dbic($deleted);
259
        $deleted = $object_class->_new_from_dbic($deleted);
240
    }
260
    }
261
241
    return $deleted;
262
    return $deleted;
242
}
263
}
243
264
244
- 

Return to bug 37510