From 2382d53a3b6fda1a004f321c1eec049b09e3138c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 21 Jun 2017 18:37:55 +0200 Subject: [locationinfo] Update install script --- modules-available/locationinfo/install.inc.php | 35 +++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'modules-available/locationinfo/install.inc.php') diff --git a/modules-available/locationinfo/install.inc.php b/modules-available/locationinfo/install.inc.php index 0dc29578..a738a863 100644 --- a/modules-available/locationinfo/install.inc.php +++ b/modules-available/locationinfo/install.inc.php @@ -6,11 +6,10 @@ $t1 = $res[] = tableCreate('locationinfo_locationconfig', ' `locationid` INT(11) NOT NULL, `serverid` INT(10) UNSIGNED, `serverlocationid` VARCHAR(150), - `hidden` BOOLEAN NOT NULL DEFAULT 0, `openingtime` BLOB, - `config` BLOB, `calendar` BLOB, - `lastcalendarupdate` INT(11) NOT NULL DEFAULT 0, + `lastcalendarupdate` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `lastchange` int(10) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`locationid`) '); @@ -19,14 +18,42 @@ $t2 = $res[] = tableCreate('locationinfo_coursebackend', ' `servername` VARCHAR(200) NOT NULL, `servertype` VARCHAR(100) NOT NULL, `credentials` BLOB, - `error` VARCHAR(1000), + `error` VARCHAR(500), PRIMARY KEY (`serverid`) '); +$t3 = $res[] = tableCreate('locationinfo_panel', " + `paneluuid` char(36) CHARACTER SET ascii NOT NULL, + `panelname` varchar(30) NOT NULL, + `locationids` varchar(20) CHARACTER SET ascii NOT NULL, + `paneltype` enum('DEFAULT','SUMMARY') NOT NULL, + `panelconfig` blob NOT NULL, + `lastchange` int(10) UNSIGNED NOT NULL DEFAULT 0, + PRIMARY KEY (`paneluuid`), + KEY `panelname` (`panelname`) +"); + // Update if ($t1 === UPDATE_NOOP) { + if ($t3 === UPDATE_DONE) { + // Upgrade from old beta version - convert panels + Database::exec('INSERT INTO locationinfo_panel (paneluuid, panelname, locationids, paneltype, panelconfig, lastchange)' + . " SELECT UUID(), Concat('Import: ', l.locationname), o.locationid, 'DEFAULT', o.config, 0 " + . " FROM locationinfo_locationconfig o INNER JOIN location l USING (locationid)" + . ' WHERE Length(o.config) > 10 OR Length(o.openingtime) > 10'); + } Database::exec("ALTER TABLE locationinfo_locationconfig CHANGE `serverid` `serverid` INT(10) UNSIGNED NULL"); + tableDropColumn('locationinfo_locationconfig', 'hidden'); + tableDropColumn('locationinfo_locationconfig', 'config'); + if (!tableHasColumn('locationinfo_locationconfig', 'lastchange')) { + $ret = Database::exec('ALTER TABLE locationinfo_locationconfig ADD `lastchange` INT(10) UNSIGNED NOT NULL DEFAULT 0'); + if ($ret === false) { + finalResponse(UPDATE_FAILED, 'Could not add lastchange field'); + } elseif ($ret > 0) { + $ret[] = UPDATE_DONE; + } + } } if ($t1 === UPDATE_DONE || $t2 === UPDATE_DONE) { Database::exec('UPDATE locationinfo_locationconfig SET serverid = NULL WHERE serverid = 0'); -- cgit v1.2.3-55-g7522