From 1397a8052143a8d90a3e94f0c65f61f426c99197 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 1 Apr 2019 18:10:07 +0200 Subject: [exams] Add constraints to exams_x_location table --- modules-available/exams/install.inc.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/modules-available/exams/install.inc.php b/modules-available/exams/install.inc.php index 1af5031d..dfd0ec7c 100644 --- a/modules-available/exams/install.inc.php +++ b/modules-available/exams/install.inc.php @@ -9,7 +9,8 @@ $res[] = tableCreate('exams', ' `endtime` int(11) NOT NULL, `autologin` char(36) NULL, `description` varchar(500) DEFAULT NULL, - PRIMARY KEY (`examid`) + PRIMARY KEY (`examid`), + KEY `idx_daterange` ( `starttime` , `endtime` ) '); $res[] = tableCreate('exams_x_location', ' @@ -18,14 +19,6 @@ $res[] = tableCreate('exams_x_location', ' PRIMARY KEY (`examid`, `locationid`) '); -if (Database::exec("ALTER TABLE exams ADD INDEX `idx_daterange` ( `starttime` , `endtime` )") === false) { - if (!preg_match('/\b1061\b/', Database::lastError())) { - finalResponse(UPDATE_FAILED, 'Could not add startdate/enddate index: ' . Database::lastError()); - } -} else { - $res[] = UPDATE_DONE; -} - if (!tableHasColumn('exams', 'lectureid')) { $ret = Database::exec("ALTER TABLE `exams` ADD `lectureid` CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NULL DEFAULT NULL AFTER `examid`"); if ($ret === false) { @@ -43,6 +36,11 @@ if (!tableHasColumn('exams', 'autologin')) { Database::exec("ALTER TABLE `exams` CHANGE `description` `description` varchar(500) DEFAULT NULL"); +$res[] = tableAddConstraint('exams_x_location', 'examid', 'exams', 'examid', + 'ON DELETE CASCADE ON UPDATE CASCADE'); +$res[] = tableAddConstraint('exams_x_location', 'locationid', 'location', 'locationid', + 'ON DELETE CASCADE ON UPDATE CASCADE'); + if (in_array(UPDATE_DONE, $res)) { finalResponse(UPDATE_DONE, 'Tables created successfully'); } -- cgit v1.2.3-55-g7522