diff options
author | Simon Rettberg | 2017-11-29 10:54:40 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-29 10:54:40 +0100 |
commit | 7efcf3cfebcec5cf3c154b6eb339ce6794cb1e96 (patch) | |
tree | 629734f08bf2680fff099792ab21cff9a1846963 | |
parent | [statistics] Introduce state column to get rid of complicated state determina... (diff) | |
download | slx-admin-7efcf3cfebcec5cf3c154b6eb339ce6794cb1e96.tar.gz slx-admin-7efcf3cfebcec5cf3c154b6eb339ce6794cb1e96.tar.xz slx-admin-7efcf3cfebcec5cf3c154b6eb339ce6794cb1e96.zip |
[runmode] Implement delete-machine action
-rw-r--r-- | modules-available/runmode/inc/runmode.inc.php | 44 | ||||
-rw-r--r-- | modules-available/runmode/page.inc.php | 8 | ||||
-rw-r--r-- | modules-available/runmode/templates/module-machine-list.html | 2 |
3 files changed, 30 insertions, 24 deletions
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 @@ <a href="?do={{module}}">{{modulename}}</a> </h2> -<form method="post" action="?do=runmode" onclick="return confirm('{{lang_confirmDelete}}')"> +<form method="post" action="?do=runmode" onsubmit="return confirm('{{lang_confirmDelete}}')"> <input type="hidden" name="token" value="{{token}}"> <input type="hidden" name="action" value="delete-machine"> <table class="table"> |