From 02531d8bd907519cd849ef5317040e9094da6d9e Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Sat, 7 Apr 2012 22:31:45 +0000 Subject: [PATCH] Detect if the destination of a rename is already in the system. Patch by RobJE. git-svn-id: http://www.observium.org/svn/observer/trunk@2985 61d68cd4-352d-0410-923a-c4978735b2b8 --- includes/functions.php | 1 + renamehost.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 832d5c7580..ca03a8eb45 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -127,6 +127,7 @@ function renamehost($id, $new, $source = 'console') { global $config; + ## FIXME does not check if destination exists! $host = dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id)); rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new"); $return = dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id)); diff --git a/renamehost.php b/renamehost.php index e949a7ffcc..0abb5a8a6c 100755 --- a/renamehost.php +++ b/renamehost.php @@ -13,8 +13,15 @@ if ($argv[1] && $argv[2]) $id = getidbyname($host); if ($id) { - renamehost($id, $argv[2], 'console'); - echo("Renamed $host\n"); + $tohost = strtolower($argv[2]); + $toid = getidbyname($tohost); + if ($toid) + { + echo("NOT renamed. New hostname $tohost already exists.\n"); + } else { + renamehost($id, $tohost, 'console'); + echo("Renamed $host\n"); + } } else { echo("Host doesn't exist!\n"); }