From 7efcf3cfebcec5cf3c154b6eb339ce6794cb1e96 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 29 Nov 2017 10:54:40 +0100 Subject: [runmode] Implement delete-machine action --- modules-available/runmode/inc/runmode.inc.php | 44 +++++++++++----------- modules-available/runmode/page.inc.php | 8 +++- .../runmode/templates/module-machine-list.html | 2 +- 3 files changed, 30 insertions(+), 24 deletions(-) (limited to 'modules-available/runmode') diff --git a/modules-available/runmode/inc/runmode.inc.php b/modules-available/runmode/inc/runmode.inc.php index 271542b8..f3e7f3d5 100644 --- a/modules-available/runmode/inc/runmode.inc.php +++ b/modules-available/runmode/inc/runmode.inc.php @@ -29,36 +29,36 @@ class RunMode * @param string|null $modeId an ID specific to the module to further specify the run mode, NULL to delete the run mode entry * @param string|null $modeData optional, additional data for the run mode * @param bool|null $isClient whether to count the machine as a client (in statistics etc.) NULL for looking at module's general runmode config - * @return bool whether it was set + * @return bool whether it was set/deleted */ - public static function setRunMode($machineuuid, $moduleId, $modeId, $modeData, $isClient) + public static function setRunMode($machineuuid, $moduleId, $modeId, $modeData = null, $isClient = null) { - // - Check if module provides runmode config at all - $config = self::getModuleConfig($moduleId); - if ($config === false) - return false; // - Check if machine exists $machine = Statistics::getMachine($machineuuid, Machine::NO_DATA); if ($machine === false) return false; + // - Delete entry if mode is null + if ($modeId === null) { + return Database::exec('DELETE FROM runmode WHERE machineuuid = :machineuuid', compact('machineuuid')) > 0; + } // - Add/replace entry in runmode table - if (is_null($modeId)) { - Database::exec('DELETE FROM runmode WHERE machineuuid = :machineuuid', compact('machineuuid')); - } else { - if ($isClient === null) { - $isClient = $config->isClient; - } - Database::exec('INSERT INTO runmode (machineuuid, module, modeid, modedata, isclient)' - . ' VALUES (:uuid, :module, :modeid, :modedata, :isclient)' - . ' ON DUPLICATE KEY' - . ' UPDATE module = VALUES(module), modeid = VALUES(modeid), modedata = VALUES(modedata), isclient = VALUES(isclient)', array( - 'uuid' => $machineuuid, - 'module' => $moduleId, - 'modeid' => $modeId, - 'modedata' => $modeData, - 'isclient' => ($isClient ? 1 : 0), - )); + // - Check if module provides runmode config at all + $config = self::getModuleConfig($moduleId); + if ($config === false) + return false; + if ($isClient === null) { + $isClient = $config->isClient; } + Database::exec('INSERT INTO runmode (machineuuid, module, modeid, modedata, isclient)' + . ' VALUES (:uuid, :module, :modeid, :modedata, :isclient)' + . ' ON DUPLICATE KEY' + . ' UPDATE module = VALUES(module), modeid = VALUES(modeid), modedata = VALUES(modedata), isclient = VALUES(isclient)', array( + 'uuid' => $machineuuid, + 'module' => $moduleId, + 'modeid' => $modeId, + 'modedata' => $modeData, + 'isclient' => ($isClient ? 1 : 0), + )); return true; } diff --git a/modules-available/runmode/page.inc.php b/modules-available/runmode/page.inc.php index 05f32f81..24566cec 100644 --- a/modules-available/runmode/page.inc.php +++ b/modules-available/runmode/page.inc.php @@ -48,7 +48,13 @@ class Page_RunMode extends Page } elseif ($action === 'delete-machine') { $machineuuid = Request::post('machineuuid', false, 'string'); if ($machineuuid === false) { - + Message::addError('machine-not-found', $machineuuid); + } else { + if (RunMode::setRunMode($machineuuid, null, null)) { + Message::addSuccess('machine-removed', $machineuuid); + } else { + Message::addWarning('machine-not-runmode', $machineuuid); + } } } } diff --git a/modules-available/runmode/templates/module-machine-list.html b/modules-available/runmode/templates/module-machine-list.html index a749a4a7..45f574ef 100644 --- a/modules-available/runmode/templates/module-machine-list.html +++ b/modules-available/runmode/templates/module-machine-list.html @@ -3,7 +3,7 @@ {{modulename}} -
+ -- cgit v1.2.3-55-g7522