From 1b772281f02f0000f47e2483d2de894985d4de7f Mon Sep 17 00:00:00 2001 From: arjen Date: Thu, 24 Mar 2011 09:59:21 +0000 Subject: [PATCH] When removing an object, clean up logs, parameters and notifications. --- src/web/objects.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/src/web/objects.php b/src/web/objects.php index b2a4bfc..b17e638 100644 --- a/src/web/objects.php +++ b/src/web/objects.php @@ -9,7 +9,7 @@ *********************** ** FILE NAME : objects.php ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring -** VERSION NUMBER : $Revision: 1.11 $ +** VERSION NUMBER : $Revision: 1.12 $ ** ** DESCRIPTION : Objects Administration page. ** Input parameters: action (POST) : empty, 'Create' @@ -23,13 +23,16 @@ ******************************** ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl ** CREATION DATE : Dec 04, 2002 -** LAST UPDATE : Aug 04, 2003 +** LAST UPDATE : Jul 13, 2010 ** MODIFICATIONS : **************************************************************************/ /***************************** $Log: objects.php,v $ - Revision 1.11 2007-11-21 14:38:06 arjen + Revision 1.12 2011-03-24 09:59:21 arjen + When removing an object, clean up logs, parameters and notifications. + + Revision 1.11 2007/11/21 14:38:06 arjen The buttonbar at the top of each page is now a fixed 'div' element instead of a framed page. Contributed by Edwin Nadorp. @@ -67,7 +70,7 @@ ******************************/ -// RCSID = "$Id: objects.php,v 1.11 2007-11-21 14:38:06 arjen Exp $"; +// RCSID = "$Id: objects.php,v 1.12 2011-03-24 09:59:21 arjen Exp $"; ini_set('include_path', '.:./classes:../phpclasses'); @@ -155,9 +158,47 @@ class object_page extends page VALUES ('" . $_POST['objectname'] . "', '0', '0', '0')"); } - if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname'])) + if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectid'])) { - pg_exec($this->database, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'"); + $oid = $_POST['objectid']; + + // Cleanup notifications for this object + + $r = pg_exec($this->database, "SELECT notificationid FROM notification WHERE objectid='$oid'"); + for ($i = 0; $i < pg_numrows($r); $i++) + { + $notif = pg_fetch_object($r, $i); + $notid = $notif->notificationid; + pg_exec($this->database, "DELETE FROM log_notification WHERE notificationid='$notid'"); + pg_exec($this->database, "DELETE FROM action_user WHERE notificationid='$notid'"); + pg_exec($this->database, "DELETE FROM parameter_notification WHERE notificationid='$notid'"); + } + pg_exec($this->database, "DELETE FROM notification WHERE objectid='$oid'"); + + // Cleanup parameters for this object + + $r = pg_exec($this->database, "SELECT paramid FROM parameter WHERE objectid='$oid'"); + for ($i = 0; $i < pg_numrows($r); $i++) + { + $param = pg_fetch_object($r, $i); + $parid = $param->paramid; + pg_exec($this->database, "DELETE FROM history WHERE paramid='$parid'"); + pg_exec($this->database, "DELETE FROM property WHERE paramid='$parid'"); + } + pg_exec($this->database, "DELETE FROM parameter WHERE objectid='$oid'"); + + // Cleanup log and abuses for this object + + pg_exec($this->database, "DELETE FROM log_abuse WHERE objectid='$oid'"); + pg_exec($this->database, "DELETE FROM object_abuse WHERE objectid='$oid'"); + pg_exec($this->database, "DELETE FROM log WHERE objectid='$oid'"); + + // Cleanup services, statistics, users and finally, the object itself. + + pg_exec($this->database, "DELETE FROM object_service WHERE objectid='$oid'"); + pg_exec($this->database, "DELETE FROM object_statistics WHERE objectid='$oid'"); + pg_exec($this->database, "DELETE FROM object_user WHERE objectid='$oid'"); + pg_exec($this->database, "DELETE FROM object WHERE objectid='$oid'"); } if (isset($_GET['oid'])) @@ -419,7 +460,7 @@ class object_page extends page . " " ?>
- +
-- 2.11.0