#476 log on delete for rows from related tables

This commit is contained in:
Oliver Gorwits
2019-01-02 21:44:36 +00:00
parent 3769b7b66b
commit 5bc0afa2f5
2 changed files with 40 additions and 3 deletions

View File

@@ -4,6 +4,9 @@ use base 'App::Netdisco::DB::ResultSet';
use strict;
use warnings;
use Try::Tiny;
require Dancer::Logger;
__PACKAGE__->load_components(qw/
+App::Netdisco::DB::ExplicitLocking
/);
@@ -222,12 +225,23 @@ handle the removal or archiving of nodes.
=cut
sub _plural { (shift || 0) == 1 ? 'entry' : 'entries' };
sub delete {
my $self = shift;
my $schema = $self->result_source->schema;
my $ports = $self->search(undef, { columns => 'ip' });
my $ip = undef;
{
no autovivification;
try { $ip ||= ${ $ports->{attrs}->{where}->{ip}->{'-in'} }->[1]->[1] };
try { $ip ||= $ports->{attrs}->{where}->{'me.ip'} };
}
die "cannot find IP address in \$ports query for delete\n"
unless $ip;
foreach my $set (qw/
DevicePortPower
DevicePortProperties
@@ -235,9 +249,12 @@ sub delete {
DevicePortWireless
DevicePortSsid
/) {
$schema->resultset($set)->search(
my $gone = $schema->resultset($set)->search(
{ ip => { '-in' => $ports->as_query }},
)->delete;
Dancer::Logger::debug sprintf ' [%s] db/ports - removed %d port %s from %s',
$ip, $gone, _plural($gone), $set if defined Dancer::Logger::logger();
}
$schema->resultset('Node')->search(