Changeset 342 for trunk/Modules/Module.php
- Timestamp:
- Jan 17, 2012, 10:37:59 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Module.php
r341 r342 11 11 var $Description; 12 12 var $Dependencies; 13 var $Models ;13 var $Models = array(); 14 14 var $Database; 15 15 var $Installed; … … 23 23 { 24 24 DebugLog('Installing module '.$this->Name.'...'); 25 parent::Install();26 25 foreach($this->Models as $ModelName) 27 26 { 28 $Model = new $ModelName(); 29 $Query = 'CREATE TABLE IF NOT EXISTS `'.$ModelName.'` ( 30 `Id` int(11) NOT NULL AUTO_INCREMENT,'; 31 foreach($Model->Properties as $Property) 32 { 33 if($Property['Type'] == PropertyDateTime) 34 $Query .= '`'.$Property['Name'].'` DATETIME NOT NULL,'; 35 else if($Property['Type'] == PropertyString) 36 $Query .= '`'.$Property['Name'].'` VARCHAR(255) COLLATE utf8_general_ci NOT NULL,'; 37 else if($Property['Type'] == PropertyText) 38 $Query .= '`'.$Property['Name'].'` TEXT COLLATE utf8_general_ci NOT NULL,'; 39 else if($Property['Type'] == PropertyInteger) 40 $Query .= '`'.$Property['Name'].'` INT(11) NOT NULL,'; 41 else if($Property['Type'] == PropertyFloat) 42 $Query .= '`'.$Property['Name'].'` FLOAT NOT NULL,'; 43 else if($Property['Type'] == PropertyOneToMany) 44 $Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'. 45 'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),'; 46 else if($Property['Type'] == PropertyManyToOne) 47 $Query .= ''; 48 else if($Property['Type'] == PropertyManyToMany) 49 ; // Create many-to-many table 50 //$Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'. 51 // 'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),'; 52 } 53 $Query .= 'PRIMARY KEY (`Id`),'. 54 ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1 ;'; 55 $this->Database->query($Query); 27 $Model = new $ModelName($this->Database); 28 $Model->Install(); 29 unset($Model); 56 30 } 57 unset($Model);31 $this->Database->query('UPDATE Module SET Installed=1 WHERE Name="'.$this->Name.'"'); 58 32 } 59 33 … … 61 35 { 62 36 DebugLog('Uninstalling module '.$this->Name.'...'); 63 parent::UnInstall();64 37 foreach($this->Models as $ModelName) 65 38 { 66 $Model = new $ModelName(); 67 if($Model['Type'] == PropertyManyToMany) 68 ; // Delete many-to-many table 69 $this->Database->query('DROP TABLE IF EXISTS `'.$ModelName.'`'); 39 $Model = new $ModelName($this->Database); 40 $Model->UnInstall(); 70 41 unset($Model); 71 42 } 43 $this->Database->query('UPDATE Module SET Installed=0 WHERE Name="'.$this->Name.'"'); 72 44 } 73 45 } … … 81 53 { 82 54 $this->Database = &$Database; 83 $DbResult = $this->Database->query('SELECT * FROM Module WHERE Installed=1'); 55 } 56 57 function Init($Installed = true) 58 { 59 $Query = 'SELECT * FROM `Module`'; 60 if($Installed) $Query .= ' WHERE `Installed`=1'; 61 else $Query .= ' WHERE `Installed`=0'; 62 $DbResult = $this->Database->query($Query); 84 63 while($Module = $DbResult->fetch_array()) 85 64 { 86 include_once('Modules/'.$File.'/'.$File.'.php'); 87 $this->Modules[] = new $Module['Name']($this->Database); 88 } 65 include_once('Modules/'.$Module['Name'].'/'.$Module['Name'].'.php'); 66 $ModuleClassName = 'Module'.$Module['Name']; 67 $this->Modules[$Module['Name']] = new $ModuleClassName($this->Database); 68 } 89 69 } 90 70 … … 99 79 `License` varchar(255) COLLATE utf8_czech_ci NOT NULL, 100 80 `Installed` int(11) NOT NULL, 81 `Description` text COLLATE utf8_czech_ci NOT NULL, 101 82 PRIMARY KEY (`Id`) 102 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;'); 103 foreach($this->Modules as $Module) 83 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 84 $this->ReloadList(); 85 $this->Init(false); 86 foreach($this->Modules as $Index => $Module) 104 87 { 105 $ Module->Install();88 $this->Modules[$Index]->Install(); 106 89 } 107 90 } … … 110 93 { 111 94 DebugLog('Uninstalling modular system core...'); 112 foreach($this->Modules as $ Module)113 $ Module->UnInstall();95 foreach($this->Modules as $Index => $Module) 96 $this->Modules[$Index]->UnInstall(); 114 97 $this->Database->query('DROP TABLE IF EXISTS `Module`'); 115 98 } … … 119 102 // Load list of modules from database 120 103 $Modules = array(); 121 $DbResult = $this->Database->query('SELECT * FROM Module');104 $DbResult = $this->Database->query('SELECT * FROM `Module`'); 122 105 while($DbRow = $DbResult->fetch_assoc()) 123 106 $Modules[$DbRow['Name']] = $DbRow; … … 129 112 if(is_dir('Modules/'.$File) and ($File != '.') and ($File != '..')) 130 113 { 131 DebugLog($File.',');132 114 $ModulesOnDisk[] = $File; 133 115 } … … 153 135 // Remove missing 154 136 foreach($Modules as $Module) 155 if( $Module['Installed'] == 0)137 if(($Module['Installed'] == 0) and !in_array($Module['Name'], $ModulesOnDisk)) 156 138 { 157 DebugLog('Removing module '.$Module Name.' from list');158 $this->Database->query('DELETE FROM Module WHERE Id= '.$Module['Id']);139 DebugLog('Removing module '.$Module['Name'].' from list'); 140 $this->Database->query('DELETE FROM `Module` WHERE `Id` = '.$Module['Id']); 159 141 } 160 142 }
Note:
See TracChangeset
for help on using the changeset viewer.