summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-04-01 18:10:07 +0200
committerSimon Rettberg2019-04-01 18:10:07 +0200
commit1397a8052143a8d90a3e94f0c65f61f426c99197 (patch)
tree22c97aabf4852786f51a1532f55e045bd4493c72
parent[exams] Shortcut for permcheck (diff)
downloadslx-admin-1397a8052143a8d90a3e94f0c65f61f426c99197.tar.gz
slx-admin-1397a8052143a8d90a3e94f0c65f61f426c99197.tar.xz
slx-admin-1397a8052143a8d90a3e94f0c65f61f426c99197.zip
[exams] Add constraints to exams_x_location table
-rw-r--r--modules-available/exams/install.inc.php16
1 files 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');
}