From 1b5ecd7071f96555c62689878381eecb6e93c994 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 18 Feb 2021 16:26:47 +0100 Subject: [statistics] Add soft-delete feature: Resets a client's IP and location Soft-deleting a client doesn't remove its entire data and usage history from the database, but just resets IP and location, so it doesn't appear in its former location anymore. In case a client is removed from a room, this declutters the client statistics. Once the client boots again, location and and IP address will be updated again. --- modules-available/statistics/page.inc.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'modules-available/statistics/page.inc.php') diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index b51e2956..20ff929a 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -70,8 +70,10 @@ class Page_Statistics extends Page )); Message::addSuccess('notes-saved'); Util::redirect('?do=statistics&uuid=' . $uuid); + } elseif ($action === 'clear-machines') { + $this->deleteMachines(true); } elseif ($action === 'delmachines') { - $this->deleteMachines(); + $this->deleteMachines(false); Util::redirect('?do=statistics', true); } elseif ($action === 'rebootmachines') { $this->rebootControl(true); @@ -184,7 +186,7 @@ class Page_Statistics extends Page } } - private function deleteMachines() + private function deleteMachines($soft) { $ids = Request::post('uuid', [], 'array'); $ids = array_values($ids); @@ -209,8 +211,18 @@ class Page_Statistics extends Page } } if (!empty($delete)) { - Database::exec('DELETE FROM machine WHERE machineuuid IN (:delete)', compact('delete')); - Message::addSuccess('deleted-n-machines', count($delete)); + if ($soft) { + // "Soft delete" -- keep all data, but set IP address to 0.0.0.0, so it will not be assigned to its + // old location anymore. Upon next boot some time in the future, the machine is hopefully relocated + // to somewhere else and will appear in a new location + Database::exec("UPDATE machine SET clientip = '0.0.0.0', fixedlocationid = NULL, subnetlocationid = NULL + WHERE machineuuid IN (:delete)", compact('delete')); + Message::addSuccess('cleared-n-machines', count($delete)); + } else { + // Actually purge from DB + Database::exec('DELETE FROM machine WHERE machineuuid IN (:delete)', compact('delete')); + Message::addSuccess('deleted-n-machines', count($delete)); + } } if (!empty($ids)) { Message::addWarning('unknown-machine', implode(', ', array_keys($ids))); -- cgit v1.2.3-55-g7522