summaryrefslogtreecommitdiffstats
path: root/modules-available/exams
diff options
context:
space:
mode:
authorSimon Rettberg2019-04-01 18:10:07 +0200
committerSimon Rettberg2019-04-01 18:15:42 +0200
commitb264b6cae9a2aaea445becd1c420c88233aeb46e (patch)
treef3bf972fa9d7a82fbf9a6b1230078aad02b034fa /modules-available/exams
parent[exams] Shortcut for permcheck (diff)
downloadslx-admin-b264b6cae9a2aaea445becd1c420c88233aeb46e.tar.gz
slx-admin-b264b6cae9a2aaea445becd1c420c88233aeb46e.tar.xz
slx-admin-b264b6cae9a2aaea445becd1c420c88233aeb46e.zip
[exams] Add constraints to exams_x_location table
Diffstat (limited to 'modules-available/exams')
-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');
}