summaryrefslogtreecommitdiffstats
path: root/modules-available/roomplanner/install.inc.php
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/roomplanner/install.inc.php
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/roomplanner/install.inc.php')
-rw-r--r--modules-available/roomplanner/install.inc.php43
1 files changed, 29 insertions, 14 deletions
diff --git a/modules-available/roomplanner/install.inc.php b/modules-available/roomplanner/install.inc.php
index a6d98384..13365fe1 100644
--- a/modules-available/roomplanner/install.inc.php
+++ b/modules-available/roomplanner/install.inc.php
@@ -6,7 +6,6 @@ $res = array();
$res[] = tableCreate('location_roomplan', "
`locationid` INT(11) NOT NULL,
`managerip` varchar(45) CHARACTER SET ascii DEFAULT '',
- `dedicatedmgr` tinyint(1) NOT NULL DEFAULT 0,
`tutoruuid` char(36) CHARACTER SET ascii DEFAULT NULL,
`roomplan` BLOB DEFAULT NULL,
PRIMARY KEY (`locationid`),
@@ -29,24 +28,40 @@ if (!tableHasColumn('location_roomplan', 'tutoruuid')) {
}
$res[] = UPDATE_DONE;
}
-if (!tableHasColumn('location_roomplan', 'dedicatedmgr')) {
- $ret = Database::exec("ALTER TABLE `location_roomplan` ADD `dedicatedmgr` tinyint(1) NOT NULL DEFAULT 0 AFTER `managerip`") !== false;
- if ($ret === false) {
- finalResponse(UPDATE_FAILED, 'Adding dedicatedmgr to location_roomplan failed: ' . Database::lastError());
- }
- $res[] = UPDATE_DONE;
-}
if (in_array(UPDATE_DONE, $res)) {
Database::exec("ALTER TABLE `location_roomplan`
- ADD CONSTRAINT `location_roomplan_ibfk_1` FOREIGN KEY (`locationid`) REFERENCES `location` (`locationid`) ON DELETE CASCADE");
+ ADD CONSTRAINT `location_roomplan_ibfk_1` FOREIGN KEY (`locationid`) REFERENCES `location` (`locationid`) ON DELETE CASCADE");
Database::exec("ALTER TABLE `location_roomplan`
- ADD CONSTRAINT `location_roomplan_ibfk_2` FOREIGN KEY (`tutoruuid`) REFERENCES `machine` (`machineuuid`) ON DELETE SET NULL ON UPDATE CASCADE");
+ ADD CONSTRAINT `location_roomplan_ibfk_2` FOREIGN KEY (`tutoruuid`) REFERENCES `machine` (`machineuuid`) ON DELETE SET NULL ON UPDATE CASCADE");
}
-if (in_array(UPDATE_DONE, $res)) {
- finalResponse(UPDATE_DONE, 'Table created successfully');
+// 2017-11-30: Refactor to runmode
+// managerip, dedicatedmgr, --> runmode
+if (tableHasColumn('location_roomplan', 'dedicatedmgr')) {
+ if (!tableExists('runmode') || !tableExists('machine')) {
+ $res[] = UPDATE_RETRY;
+ } else {
+ $ret = Database::simpleQuery('SELECT lr.locationid, lr.managerip, lr.dedicatedmgr, m.machineuuid
+ FROM location_roomplan lr INNER JOIN machine m ON (m.clientip = lr.managerip)');
+ if ($ret === false) {
+ $res[] = UPDATE_FAILED;
+ } else {
+ while ($row = $ret->fetch(PDO::FETCH_ASSOC)) {
+ $dedi = $row['dedicatedmgr'] != 0;
+ $data = json_encode(array('dedicatedmgr' => $dedi));
+ Database::exec("INSERT IGNORE INTO runmode (machineuuid, module, modeid, modedata, isclient)
+ VALUES (:machineuuid, 'roomplanner', :locationid, :modedata, :isclient)", array(
+ 'machineuuid' => $row['machineuuid'],
+ 'locationid' => $row['locationid'],
+ 'modedata' => $data,
+ 'isclient' => ($dedi ? 0 : 1)
+ ));
+ }
+ Database::exec('ALTER TABLE location_roomplan DROP COLUMN dedicatedmgr');
+ $res[] = UPDATE_DONE;
+ }
+ }
}
-finalResponse(UPDATE_NOOP, 'Everything already up to date');
-
+responseFromArray($res);