Changeset 898 for trunk/Packages/Common/Modules/ModuleManager.php
- Timestamp:
- Feb 4, 2021, 11:55:44 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Modules/ModuleManager.php
r897 r898 22 22 $this->Manager->OnInstallModel = array($this, 'InstallModel'); 23 23 $this->Manager->OnUninstallModel = array($this, 'UninstallModel'); 24 $this->Manager->OnInstallModule = array($this, 'InstallModule'); 25 $this->Manager->OnUninstallModule = array($this, 'UninstallModule'); 24 26 25 27 Core::Cast($this->System)->RegisterPage(['modules'], 'PageModules'); … … 140 142 function DoBeforeInstall(): void 141 143 { 144 $this->AddModelDatabase(Module::GetDesc()); 145 $this->Manager->OnInstallModule = array($this, 'InstallModule'); 146 $this->Manager->OnUninstallModule = array($this, 'UninstallModule'); 147 $this->AddModelDatabase(ModuleModel::GetDesc()); 142 148 $this->Manager->OnInstallModel = array($this, 'InstallModel'); 143 149 $this->Manager->OnUninstallModel = array($this, 'UninstallModel'); … … 148 154 $this->Manager->OnInstallModel = null; 149 155 $this->Manager->OnUninstallModel = null; 156 $this->RemoveModelDatabase(ModuleModel::GetDesc()); 157 $this->Manager->OnInstallModule = null; 158 $this->Manager->OnUninstallModule = null; 159 $this->RemoveModelDatabase(Module::GetDesc()); 150 160 } 151 161 152 162 function GetModels(): array 153 163 { 154 return array(Module::GetClassName(), ModuleModel::GetClassName(), ModuleModelField::GetClassName(), 155 ModuleDependency::GetClassName()); 156 } 157 158 function InstallModel(ModelDesc $ModelDesc) 164 return array(ModuleModelField::GetClassName(), ModuleDependency::GetClassName()); 165 } 166 167 function AddModelDatabase(ModelDesc $ModelDesc) 159 168 { 160 169 $Query = "CREATE TABLE IF NOT EXISTS `".$ModelDesc->Name."` (\n"; … … 212 221 } 213 222 214 function UninstallModel(ModelDesc $ModelDesc)223 function RemoveModelDatabase(ModelDesc $ModelDesc) 215 224 { 216 225 /*$Query = ''; … … 227 236 */ 228 237 $this->Database->query('SET foreign_key_checks = 0; DROP TABLE IF EXISTS `'.$ModelDesc->Name.'`'); 238 } 239 240 function InstallModel(ModelDesc $ModelDesc, AppModule $Module) 241 { 242 $this->AddModelDatabase($ModelDesc); 243 $this->Database->insert('ModuleModel', array('Name' => $ModelDesc->Name, 'Module' => $Module->Id)); 244 $ModelId = $this->Database->insert_id; 245 foreach ($ModelDesc->Columns as $Field) 246 { 247 $this->Database->insert('ModuleModelField', array('Name' => $Field->Name, 'Model' => $ModelId, 248 'Type' => ModelColumnType::GetName($Field->Type), 'Nullable' => (int)$Field->Nullable)); 249 } 250 } 251 252 function UninstallModel(ModelDesc $ModelDesc, AppModule $Module) 253 { 254 $this->Database->delete('ModuleModel', '(Name='.$ModelDesc->Name.') AND (Module='.$Module->Id.')'); 255 $this->RemoveModelDatabase($ModelDesc); 256 } 257 258 function InstallModule(AppModule $Module) 259 { 260 echo('Install module '.$Module->Name); 261 $this->Database->insert('Module', array( 262 'Name' => $Module->Name, 263 'Title' => $Module->Title, 264 'Creator' => $Module->Creator, 265 'Version' => $Module->Version, 266 'License' => $Module->License, 267 'Installed' => (int)$Module->Installed, 268 'Description' => $Module->Description, 269 'InstalledVersion' => $Module->InstalledVersion 270 )); 271 $Module->Id = $this->Database->insert_id; 272 } 273 274 function UninstallModule(AppModule $Module) 275 { 276 echo('Uninstall module '.$Module->Name); 277 $this->Database->delete('Module', 'Name='.$Module->Name); 229 278 } 230 279 … … 519 568 $Desc = new ModelDesc(self::GetClassName()); 520 569 $Desc->AddString('Name'); 521 $Desc->AddReference('Mod ule', ModuleModel::GetClassName());570 $Desc->AddReference('Model', ModuleModel::GetClassName()); 522 571 $Desc->AddString('Type'); 523 572 $Desc->AddBoolean('Nullable');
Note:
See TracChangeset
for help on using the changeset viewer.