summaryrefslogtreecommitdiffstats
path: root/modules-available/usblockoff/install.inc.php
blob: 47a07573a729d69232895f6e35dbc5c759f04813 (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
67
68
69
70
71
72
73
<?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 ($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 ($t4 === UPDATE_NOOP) {
	Database::exec("ALTER TABLE `usb_configs`
		ADD `configdesc` VARCHAR(200)");
}


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

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