summaryrefslogtreecommitdiffstats
path: root/modules-available/usblockoff/install.inc.php
blob: 967771d163e0a84d69126f35a8ba2d57ac8d92c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

$res = array();
/*
$t1 = $res[] = tableCreate('usb_devices', '
	`uid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`id` varchar(50),
	`serial` varchar(512) NOT NULL DEFAULT 0,
	`name` varchar(1024) CHARACTER SET ascii DEFAULT NULL,
	`machineuuid` char(36) CHARACTER SET ascii DEFAULT NULL,
	`time` INT(11) NOT NULL DEFAULT 0,
	`user` varchar(8),
	`ruleInformation` varchar(1024),
	PRIMARY KEY (`uid`)
');
*/

$t1 = $res[] = tableCreate('usblockoff_hw', '
	`hwid` INT(10) UNSIGNED NOT NULL ,
	`serial` VARCHAR(128),
	PRIMARY KEY (`hwid`, `serial`)
');

$t2 = $res[] = tableCreate('usblockoff_hw_prop', '
	`hwid` INT(10) UNSIGNED NOT NULL ,
	`serial` VARCHAR(128),
	`prop` CHAR(16),
	`value` VARCHAR(500),
	PRIMARY KEY (`hwid`, `serial`, `prop`)
');

// TODO: ADD CONSTRAINT

$res[] = tableCreate('usb_configs', '
	`configid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`configname` VARCHAR(200) NOT NULL,
	`rulesconfig` BLOB,
	`daemonconfig` BLOB,
	PRIMARY KEY (`configid`)
');

//$ret = Database::exec("DROP TABLE `usb_devices`");
//$ret = Database::exec("DROP TABLE `usblockoff_hw`");
//$ret = Database::exec("DROP TABLE `usblockoff_hw_prop`");

if ($t1 === UPDATE_DONE || $t2 === UPDATE_DONE) {
	$ret = Database::exec('ALTER TABLE `usblockoff_hw`
		ADD CONSTRAINT `usblockoff_hw_ibfk_1` FOREIGN KEY (`hwid`) REFERENCES `statistic_hw` (`hwid`) ON DELETE CASCADE');
	if ($ret === false) {
		finalResponse(UPDATE_FAILED, 'Adding constraints to usblockoff_hw failed: ' . Database::lastError());
	}

	$ret = Database::exec('ALTER TABLE `usblockoff_hw_prop`
		ADD CONSTRAINT `usblockoff_hw__prop_ibfk_1` FOREIGN KEY (`hwid`, `serial`) REFERENCES `usblockoff_hw` (`hwid`, `serial`) ON DELETE CASCADE');
	if ($ret === false) {
		finalResponse(UPDATE_FAILED, 'Adding constraints to usblockoff_hw_prop failed: ' . Database::lastError());
	}
	$res[] = UPDATE_DONE;
}


if (in_array(UPDATE_DONE, $res)) {
	finalResponse(UPDATE_DONE, 'Table created successfully');
}

finalResponse(UPDATE_NOOP, 'Everything already up to date');