summaryrefslogtreecommitdiffstats
path: root/modules-available/runmode
diff options
context:
space:
mode:
authorSimon Rettberg2017-11-30 18:30:01 +0100
committerSimon Rettberg2017-11-30 18:30:01 +0100
commitb90c97b1f096008b5fa9abf8c50a120a85c47a4e (patch)
tree2e6de58e0de3d044549946b352cb6b2bd61916fd /modules-available/runmode
parentUpdate translations (diff)
downloadslx-admin-b90c97b1f096008b5fa9abf8c50a120a85c47a4e.tar.gz
slx-admin-b90c97b1f096008b5fa9abf8c50a120a85c47a4e.tar.xz
slx-admin-b90c97b1f096008b5fa9abf8c50a120a85c47a4e.zip
[roomplanner] Refactor to use runmode
Diffstat (limited to 'modules-available/runmode')
-rw-r--r--modules-available/runmode/inc/runmode.inc.php23
-rw-r--r--modules-available/runmode/page.inc.php21
2 files changed, 40 insertions, 4 deletions
diff --git a/modules-available/runmode/inc/runmode.inc.php b/modules-available/runmode/inc/runmode.inc.php
index 59f8cf01..50ae2d72 100644
--- a/modules-available/runmode/inc/runmode.inc.php
+++ b/modules-available/runmode/inc/runmode.inc.php
@@ -36,6 +36,9 @@ class RunMode
*/
public static function setRunMode($machineuuid, $moduleId, $modeId, $modeData = null, $isClient = null)
{
+ if (is_object($moduleId)) {
+ $moduleId = $moduleId->getIdentifier();
+ }
// - Check if machine exists
$machine = Statistics::getMachine($machineuuid, Machine::NO_DATA);
if ($machine === false)
@@ -196,6 +199,21 @@ class RunMode
return call_user_func($conf->getModeName, $modeId);
}
+ /**
+ * Delete given runmode.
+ *
+ * @param string|\Module $module Module runmode belongs to
+ * @param string $modeId run mode id
+ */
+ public static function deleteMode($module, $modeId)
+ {
+ if (is_object($module)) {
+ $module = $module->getIdentifier();
+ }
+ Database::exec('DELETE FROM runmode WHERE module = :module AND modeid = :modeId',
+ compact('module', 'modeId'));
+ }
+
}
/* *\
@@ -235,6 +253,10 @@ class RunModeModuleConfig
* @var bool If true, config.tgz should not be downloaded by the client
*/
public $noSysconfig = false;
+ /**
+ * @var bool Allow adding and removing machines to this mode via the generic form
+ */
+ public $allowGenericEditor = true;
public function __construct($file)
{
@@ -248,6 +270,7 @@ class RunModeModuleConfig
$this->loadType($data, 'configHook', 'string');
$this->loadType($data, 'isClient', 'boolean');
$this->loadType($data, 'noSysconfig', 'boolean');
+ $this->loadType($data, 'allowGenericEditor', 'boolean');
}
private function loadType($data, $key, $type)
diff --git a/modules-available/runmode/page.inc.php b/modules-available/runmode/page.inc.php
index 24566cec..ef42e7be 100644
--- a/modules-available/runmode/page.inc.php
+++ b/modules-available/runmode/page.inc.php
@@ -26,20 +26,33 @@ class Page_RunMode extends Page
$machines = array_filter(Request::post('machines', [], 'array'), 'is_string');
$module = Request::post('module', false, 'string');
$modeId = Request::post('modeid', false, 'string');
- // TODO Validate
+ $modConfig = RunMode::getModuleConfig($module);
+ if ($modConfig === false) {
+ Message::addError('module-hasnt-runmode', $module);
+ return;
+ }
+ if (!$modConfig->allowGenericEditor) {
+ Message::addError('cannot-edit-module', $module);
+ return;
+ }
+ $test = RunMode::getModeName($module, $modeId);
+ if ($test === false) {
+ Message::addError('invalid-modeid', $module, $modeId);
+ return;
+ }
$active = 0;
foreach ($machines as $machine) {
$ret = RunMode::setRunMode($machine, $module, $modeId, null, null);
if ($ret) {
$active++;
} else {
- Message::addError('invalid-module-or-machine', $module, $machine);
+ Message::addError('runmode.machine-not-found', $machine);
}
}
$deleted = Database::exec('DELETE FROM runmode
WHERE module = :module AND modeid = :modeId AND machineuuid NOT IN (:machines)',
compact('module', 'modeId', 'machines'));
- Message::addError('enabled-removed-save', $active, $deleted);
+ Message::addSuccess('runmode.enabled-removed-save', $active, $deleted);
$redirect = Request::post('redirect', false, 'string');
if ($redirect !== false) {
Util::redirect($redirect);
@@ -141,7 +154,7 @@ class Page_RunMode extends Page
$moduleId = $module->getIdentifier();
$modeName = RunMode::getModeName($moduleId, $modeId);
if ($modeName === false) {
- Message::addError('invalid-modeid', $modeId);
+ Message::addError('invalid-modeid', $moduleId, $modeId);
Util::redirect('?do=runmode');
}
Render::addTemplate('machine-selector', [