From 3268fca4cf50113cd8dbd1a12479cedca22e7141 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Thu, 30 Aug 2018 14:38:29 -0500 Subject: [PATCH] Set ip to null when a device is renamed (#9112) Oddly this doesn't check if the target hostname exists in the database, so that is left to the caller. (likely the target rrd directory will exist). If we wanted to check that in function this I'd probably covert it to Exception errors so we could signal the different types of failures. DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply `, i.e `./scripts/github-apply 5926` --- includes/functions.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 64f9038580..f62a2066ab 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -502,20 +502,16 @@ function getImageName($device, $use_database = true, $dir = 'images/os/') function renamehost($id, $new, $source = 'console') { - global $config; + $host = gethostbyid($id); - $host = dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id)); if (!is_dir(get_rrd_dir($new)) && rename(get_rrd_dir($host), get_rrd_dir($new)) === true) { - dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id)); + dbUpdate(['hostname' => $new, 'ip' => null], 'devices', 'device_id=?', [$id]); log_event("Hostname changed -> $new ($source)", $id, 'system', 3); - } else { - log_event("Renaming of $host failed", $id, 'system', 5); - if (__FILE__ === $_SERVER['SCRIPT_FILE_NAME']) { - echo "Renaming of $host failed\n"; - } else { - return "Renaming of $host failed\n"; - } + return ''; } + + log_event("Renaming of $host failed", $id, 'system', 5); + return "Renaming of $host failed\n"; } function delete_device($id)