From 568d12cbd8d5897b1c9562cf109ce67f6caf2d37 Mon Sep 17 00:00:00 2001 From: Kate Robinson <49044345+kterobinson@users.noreply.github.com> Date: Tue, 19 Oct 2021 05:54:34 -0600 Subject: [PATCH] Modified SQL delete statement for vrf is null (#13199) * Modified SQL delete for is NULL instead of = null * Fixed spacing * Fixed more spacing issues * Replaced double quotes with single quotes for echo statement * Fixed more spacing issues * Modified null vrf db check to match vrp.inc.php * Clean up comments * Modified git username to fix CLA * Revert bgp-peers.inc.php Co-authored-by: Kate Robinson Co-authored-by: Tony Murray --- includes/discovery/bgp-peers/timos.inc.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/discovery/bgp-peers/timos.inc.php b/includes/discovery/bgp-peers/timos.inc.php index 713af6a0ae..3058e481a6 100644 --- a/includes/discovery/bgp-peers/timos.inc.php +++ b/includes/discovery/bgp-peers/timos.inc.php @@ -43,6 +43,7 @@ if (Config::get('enable_bgp')) { foreach ($bgpPeers as $vrfOid => $vrf) { $vrfId = dbFetchCell('SELECT vrf_id from `vrfs` WHERE vrf_oid = ?', [$vrfOid]); + d_echo($vrfId); foreach ($vrf as $address => $value) { $astext = get_astext($value['tBgpPeerNgPeerAS4Byte']); @@ -80,11 +81,15 @@ if (Config::get('enable_bgp')) { $peers = dbFetchRows('SELECT `B`.`vrf_id` AS `vrf_id`, `bgpPeerIdentifier`, `vrf_oid` FROM `bgpPeers` AS B LEFT JOIN `vrfs` AS V ON `B`.`vrf_id` = `V`.`vrf_id` WHERE `B`.`device_id` = ?', [$device['device_id']]); foreach ($peers as $value) { $vrfId = $value['vrf_id']; + $checkVrf = ' AND vrf_id = ? '; + if (empty($vrfId)) { + $checkVrf = ' AND `vrf_id` IS NULL '; + } $vrfOid = $value['vrf_oid']; $address = $value['bgpPeerIdentifier']; if (empty($bgpPeers[$vrfOid][$address])) { - $deleted = dbDelete('bgpPeers', 'device_id = ? AND bgpPeerIdentifier = ? AND vrf_id = ?', [$device['device_id'], $address, $vrfId]); + $deleted = dbDelete('bgpPeers', 'device_id = ? AND bgpPeerIdentifier = ? ' . $checkVrf, [$device['device_id'], $address, $vrfId]); echo str_repeat('-', $deleted); echo PHP_EOL;