- Timestamp:
- Mar 30, 2012, 2:02:51 PM (13 years ago)
- Location:
- branches/Modular
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Modular/Common/Database.php
r358 r401 37 37 var $ShowSQLError = false; 38 38 var $ShowSQLQuery = false; 39 var $Database = ''; 39 40 40 41 function __construct($Host, $User, $Password, $Database) 41 42 { 43 $this->Database = $Database; 42 44 if($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database; 43 45 else if($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host; … … 49 51 function select_db($Database) 50 52 { 53 $this->Database = $Database; 51 54 $this->query('USE '.$Database); 52 55 } -
branches/Modular/Common/Global.php
r384 r401 73 73 $System->RootFolder = $Config['Web']['RootFolder']; 74 74 $System->Config = &$Config; 75 $System->Install();76 $System->Init();77 75 } 78 76 -
branches/Modular/Common/Model.php
r398 r401 236 236 $this->Module->Models[$Property['TargetModel']]->Install(); 237 237 } 238 $this->Database->query('ALTER TABLE `'.$this->Name.'` ADD FOREIGN KEY (`'.$Property['Name'].'`) REFERENCES `'.$Property['TargetModel'].'` (`Id`);'); 238 $this->Database->query('ALTER TABLE `'.$this->Name.'` ADD CONSTRAINT `'. 239 $this->Name.'_ibfk_'.$Property['Name'].'` FOREIGN KEY (`'.$Property['Name'].'`) REFERENCES `'.$Property['TargetModel'].'` (`Id`);'); 239 240 } 240 } 241 } 241 } } 242 242 243 243 function UnInstall() … … 247 247 if($Property['Type'] == PropertyManyToMany) 248 248 ; // Delete many-to-many table 249 else 250 {if($Property['Type'] == PropertyOneToMany) 251 $this->Database->query('ALTER TABLE `'.$this->Name.'` DROP FOREIGN KEY `'. 252 $this->Name.'_ibfk_'.$Property['Name'].'`'); 253 echo('ss'); 254 } 249 255 } 250 $this->Database->query('DROP TABLE IF EXISTS `'.$this->Name.'`');256 //$this->Database->query('DROP TABLE IF EXISTS `'.$this->Name.'`'); 251 257 $this->Installed = false; 252 258 } -
branches/Modular/Common/Module.php
r398 r401 120 120 { 121 121 //DebugLog('Installing modular system core...'); 122 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemVersion` ( 123 `Id` int(11) NOT NULL AUTO_INCREMENT, 124 `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL, 125 `Description` datetime NOT NULL, 126 PRIMARY KEY (`Id`) 127 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 122 128 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModule` ( 123 129 `Id` int(11) NOT NULL AUTO_INCREMENT, … … 140 146 UNIQUE (`Module` , `DependencyModule`) 141 147 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 142 $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');143 $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD FOREIGN KEY ( `DependencyModule` ) REFERENCES `SystemModule` (`Id`)');148 $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)'); 149 $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_2` FOREIGN KEY ( `DependencyModule` ) REFERENCES `SystemModule` (`Id`)'); 144 150 145 151 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModel` ( … … 150 156 PRIMARY KEY (`Id`) 151 157 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 152 $this->Database->query('ALTER TABLE `SystemModel` ADD FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');158 $this->Database->query('ALTER TABLE `SystemModel` ADD CONSTRAINT `SystemModel_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)'); 153 159 154 160 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModelProperty` ( … … 160 166 PRIMARY KEY (`Id`) 161 167 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 162 $this->Database->query('ALTER TABLE `SystemModelProperty` ADD FOREIGN KEY ( `Model` ) REFERENCES `SystemModel` (`Id`)');168 $this->Database->query('ALTER TABLE `SystemModelProperty` ADD CONSTRAINT `SystemModelProperty_ibfk_1` FOREIGN KEY ( `Model` ) REFERENCES `SystemModel` (`Id`)'); 163 169 164 170 $this->ReloadList(); … … 178 184 179 185 // Delete tables with reverse order 186 $this->Database->query('ALTER TABLE `SystemModelProperty` DROP FOREIGN KEY `SystemModelProperty_ibfk_1`'); 180 187 $this->Database->query('DROP TABLE IF EXISTS `SystemModelProperty`'); 188 $this->Database->query('ALTER TABLE `SystemModel` DROP FOREIGN KEY `SystemModel_ibfk_1`'); 181 189 $this->Database->query('DROP TABLE IF EXISTS `SystemModel`'); 190 $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_1`'); 191 $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_2`'); 182 192 $this->Database->query('DROP TABLE IF EXISTS `SystemModuleDependency`'); 183 193 $this->Database->query('DROP TABLE IF EXISTS `SystemModule`'); 194 $this->Database->query('DROP TABLE IF EXISTS `SystemVersion`'); 195 } 196 197 function IsInstalled() 198 { 199 $DbResult = $this->Database->query('SELECT table_name FROM information_schema.tables 200 WHERE table_schema = "'.$this->Database->Database.'" AND table_name = "SystemVersion";'); 201 if($DbResult->num_rows > 0) return(true); 202 else return(false); 184 203 } 185 204 -
branches/Modular/Install.php
r377 r401 2 2 3 3 include_once('Common/Global.php'); 4 GlobalInit(); 4 5 6 function ShowDefault() 7 { 8 global $System; 9 10 if($System->IsInstalled()) 11 { 12 echo('System je již nainstalován.<br/>'); 13 echo('<a href="?a=uninstall">Odinstalovat systém</a>'); 14 } else 15 { 16 echo('System ještě není instalován.<br/>'); 17 echo('<a href="?a=install">Instalovat systém</a>'); 18 } 19 } 20 21 if(array_key_exists('a', $_GET)) 22 { 23 if($_GET['a'] == 'install') 24 { 25 $System->Install(); 26 $System->Init(); 27 ShowDefault(); 28 } 29 else if($_GET['a'] == 'uninstall') 30 { 31 $System->Init(); 32 $System->Uninstall(); 33 ShowDefault(); 34 } 35 else ShowDefault(); 36 } else ShowDefault(); 5 37 6 38 ?> -
branches/Modular/index.php
r384 r401 3 3 include_once('Common/Global.php'); 4 4 GlobalInit(); 5 if(!$System->IsInstalled()) die('System not installed.'); 6 $System->Init(); 5 7 $System->PathItems = ProcessURL(); 6 8 //print_r($_GET);
Note:
See TracChangeset
for help on using the changeset viewer.