You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by jf...@apache.org on 2012/11/14 19:29:34 UTC
svn commit: r1409286 - in /vcl/trunk/web/.ht-inc: computers.php utils.php
Author: jfthomps
Date: Wed Nov 14 18:29:33 2012
New Revision: 1409286
URL: http://svn.apache.org/viewvc?rev=1409286&view=rev
Log:
VCL-451
Cannot add deleted computers
computers.php: modified submitDeleteComputer - when deleting a computer, change hostname to be current hostname with "-DELETED-<compid>" appended to it; when undeleting, remove "-DELETED-<compid>" from the hostname, and if this would cause a conflict with an existing computer, append "-UNDELETED-<compid>" to it
utils.php:
-modified getComputers - if deleted computers are included and the computer has been deleted, remove the "-DELETED-<compid>" part from the hostname
-modified sortComputers - remove "-(UN)DELETED-<num>" from the hostnames before comparing them
Modified:
vcl/trunk/web/.ht-inc/computers.php
vcl/trunk/web/.ht-inc/utils.php
Modified: vcl/trunk/web/.ht-inc/computers.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/computers.php?rev=1409286&r1=1409285&r2=1409286&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/computers.php (original)
+++ vcl/trunk/web/.ht-inc/computers.php Wed Nov 14 18:29:33 2012
@@ -1695,17 +1695,34 @@ function confirmDeleteComputer() {
function submitDeleteComputer() {
$compid = getContinuationVar("compid");
$deleted = getContinuationVar("deleted");
+ $compdata = getComputers(0, 1, $compid);
if($deleted) {
+ $newhostname = preg_replace('/-DELETED-[0-9]+$/', '', $compdata[$compid]['hostname']);
+ $newhostname = mysql_real_escape_string($newhostname);
+ $query = "SELECT id "
+ . "FROM computer "
+ . "WHERE hostname = '$newhostname' AND "
+ . "id != $compid";
+ $qh = doQuery($query);
+ if(mysql_num_rows($qh))
+ $newhostname = "$newhostname-UNDELETED-$compid";
$query = "UPDATE computer "
- . "SET deleted = 0 "
- . "WHERE id = $compid";
+ . "SET deleted = 0, "
+ . "hostname = '$newhostname' ";
+ if($compdata[$compid]['type'] == 'virtualmachine')
+ $query .= ", stateid = 10 ";
+ $query .= "WHERE id = $compid";
$qh = doQuery($query, 190);
}
else {
+ $newhostname = preg_replace('/-(UN)?DELETED-[0-9]+$/', '', $compdata[$compid]['hostname']);
+ $newhostname = "$newhostname-DELETED-$compid";
+ $newhostname = mysql_real_escape_string($newhostname);
$query = "UPDATE computer "
- . "SET deleted = 1, "
- . "vmhostid = NULL "
- . "WHERE id = $compid";
+ . "SET deleted = 1, "
+ . "vmhostid = NULL, "
+ . "hostname = '$newhostname' "
+ . "WHERE id = $compid";
$qh = doQuery($query, 191);
}
$_SESSION['userresources'] = array();
Modified: vcl/trunk/web/.ht-inc/utils.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/utils.php?rev=1409286&r1=1409285&r2=1409286&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/utils.php (original)
+++ vcl/trunk/web/.ht-inc/utils.php Wed Nov 14 18:29:33 2012
@@ -7301,6 +7301,8 @@ function getComputers($sort=0, $included
$query .= "ORDER BY c.hostname";
$qh = doQuery($query, 180);
while($row = mysql_fetch_assoc($qh)) {
+ if($includedeleted && $row['deleted'] == 1)
+ $row['hostname']= preg_replace('/-DELETED-[0-9]+$/', '', $row['hostname']);
$return[$row['id']] = $row;
}
if($sort) {
@@ -7576,6 +7578,9 @@ function sortComputers($a, $b) {
return -1;
}
+ $a['hostname'] = preg_replace('/-(UN)?DELETED-[0-9]+$/', '', $a['hostname']);
+ $b['hostname'] = preg_replace('/-(UN)?DELETED-[0-9]+$/', '', $b['hostname']);
+
# get hostname and first part of domain name
$tmp = explode('.', $a["hostname"]);
$h1 = array_shift($tmp);