summaryrefslogblamecommitdiffstats
path: root/modules-available/usblockoff/install.inc.php
blob: dda0ac3569d82f93e43c915257140a2db1140b00 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11


               

                                             
                                         




                                                  
                                         




                                              
 
                                           

                                                            














                                                                              



                                
  

                                                    

                                                           
                                                    
 
 

                                                                                         
                             
                                                                                                
         

 
                                                                                                  
 
                                                                                              

                                                               
                                                                                                                                                             
 
 
                        
 
<?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);