summaryrefslogtreecommitdiffstats
path: root/modules-available/usblockoff/install.inc.php
blob: dda0ac3569d82f93e43c915257140a2db1140b00 (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
<?php

$res = array();

$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`)
');

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

$t3 = $res[] = tableCreate('usb_rule_prop', '
	`ruleid` INT(10) UNSIGNED NOT NULL,
	`prop` CHAR(16),
	`value` VARCHAR(500)	
');

/*
$res[] = tableCreate('usb_configs', '
	`configid` int(10) UNSIGNED NOT NULL AUTO_INCREMENTloadAddDeviceModal,
	`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`");
//$ret = Database::exec("DROP TABLE `usb_configs`");


if ($t4 === UPDATE_DONE) {
	$ret = Database::exec("ALTER TABLE `usb_configs` ADD `configdesc` VARCHAR(200)");
	if ($ret === false) {
		finalResponse(UPDATE_FAILED, 'Adding column configdesc to usb_configs failed.');
	}
}

$res[] = tableAddConstraint("usblockoff_hw", "hwid", "statistic_hw", "hwid", "ON DELETE CASCADE");

// TODO: Works, as the one above already forces retry. How to write it in tableAddConstraint ?
if ($t2 === UPDATE_DONE) {
	$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');
}

responseFromArray($res);