summaryrefslogtreecommitdiffstats
path: root/modules-available/runmode/install.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2017-07-06 13:11:54 +0200
committerSimon Rettberg2017-07-06 13:11:54 +0200
commitff6e86e8e5db2728d3b34c10f561cfdb533afa87 (patch)
treebc9d492397689a4e95473840a5023972aa97af95 /modules-available/runmode/install.inc.php
parent[summernote] Make auto-loading dep (diff)
downloadslx-admin-ff6e86e8e5db2728d3b34c10f561cfdb533afa87.tar.gz
slx-admin-ff6e86e8e5db2728d3b34c10f561cfdb533afa87.tar.xz
slx-admin-ff6e86e8e5db2728d3b34c10f561cfdb533afa87.zip
[runmode] New module for managing special boot modes of clients
Diffstat (limited to 'modules-available/runmode/install.inc.php')
-rw-r--r--modules-available/runmode/install.inc.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/modules-available/runmode/install.inc.php b/modules-available/runmode/install.inc.php
new file mode 100644
index 00000000..962a0cc9
--- /dev/null
+++ b/modules-available/runmode/install.inc.php
@@ -0,0 +1,36 @@
+<?php
+
+$res = array();
+
+$res[] = tableCreate('runmode', '
+ `machineuuid` char(36) CHARACTER SET ascii NOT NULL,
+ `module` varchar(30) CHARACTER SET ascii NOT NULL,
+ `modeid` varchar(60) CHARACTER SET ascii NOT NULL,
+ `modedata` blob DEFAULT NULL,
+ PRIMARY KEY (`machineuuid`),
+ KEY `module` (`module`,`modeid`)
+');
+
+if (!tableExists('machine')) {
+ // Cannot add constraint yet
+ $res[] = UPDATE_RETRY;
+} else {
+ $c = tableGetContraints('runmode', 'machineuuid', 'machine', 'machineuuid');
+ if ($c === false)
+ finalResponse(UPDATE_FAILED, 'Cannot get constraints of runmode table: ' . Database::lastError());
+ if (empty($c)) {
+ $alter = Database::exec('ALTER TABLE runmode ADD FOREIGN KEY (machineuuid) REFERENCES machine (machineuuid)
+ ON DELETE CASCADE ON UPDATE CASCADE');
+ if ($alter === false)
+ finalResponse(UPDATE_FAILED, 'Cannot add machineuuid constraint to runmode table: ' . Database::lastError());
+ $res[] = UPDATE_DONE;
+ }
+}
+
+// Create response for browser
+
+if (in_array(UPDATE_DONE, $res)) {
+ finalResponse(UPDATE_DONE, 'Tables created successfully');
+}
+
+finalResponse(UPDATE_NOOP, 'Everything already up to date'); \ No newline at end of file