Changeset 899 for trunk/Packages/Common/Modules/ModuleManager.php
- Timestamp:
- Feb 17, 2021, 12:30:23 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Modules/ModuleManager.php
r898 r899 1 1 <?php 2 2 3 class ModuleModuleManager extends AppModule3 class ModuleModuleManager extends Module 4 4 { 5 5 public UpdateManager $UpdateManager; … … 13 13 $this->License = 'GNU/GPLv3'; 14 14 $this->Description = 'User interface for module management.'; 15 $this->Dependencies = array( 'Setup');15 $this->Dependencies = array(ModuleSetup::GetName()); 16 16 $this->Revision = 1; 17 17 $this->Type = ModuleType::System; 18 $this->Models = array(ModelField::GetClassName(), ModuleDependency::GetClassName()); 18 19 } 19 20 … … 142 143 function DoBeforeInstall(): void 143 144 { 144 $this->AddModelDatabase(Module::Get Desc());145 $this->AddModelDatabase(Module::GetModelDesc()); 145 146 $this->Manager->OnInstallModule = array($this, 'InstallModule'); 146 147 $this->Manager->OnUninstallModule = array($this, 'UninstallModule'); 147 $this->AddModelDatabase(Mod uleModel::GetDesc());148 $this->AddModelDatabase(Model::GetModelDesc()); 148 149 $this->Manager->OnInstallModel = array($this, 'InstallModel'); 149 150 $this->Manager->OnUninstallModel = array($this, 'UninstallModel'); … … 154 155 $this->Manager->OnInstallModel = null; 155 156 $this->Manager->OnUninstallModel = null; 156 $this->RemoveModelDatabase(Mod uleModel::GetDesc());157 $this->RemoveModelDatabase(Model::GetModelDesc()); 157 158 $this->Manager->OnInstallModule = null; 158 159 $this->Manager->OnUninstallModule = null; 159 $this->RemoveModelDatabase(Module::GetDesc()); 160 } 161 162 function GetModels(): array 163 { 164 return array(ModuleModelField::GetClassName(), ModuleDependency::GetClassName()); 160 $this->RemoveModelDatabase(Module::GetModelDesc()); 161 } 162 163 function DoInstall(): void 164 { 165 $this->InstallModel(Module::GetModelDesc(), $this->System->GetModule($this::GetName())); 166 $this->InstallModel(Model::GetModelDesc(), $this->System->GetModule($this::GetName())); 165 167 } 166 168 … … 238 240 } 239 241 240 function InstallModel(ModelDesc $ModelDesc, AppModule $Module)242 function InstallModel(ModelDesc $ModelDesc, Module $Module) 241 243 { 242 244 $this->AddModelDatabase($ModelDesc); 243 $this->Database->insert('Mod uleModel', array('Name' => $ModelDesc->Name, 'Module' => $Module->Id));245 $this->Database->insert('Model', array('Name' => $ModelDesc->Name, 'Module' => $Module->Id)); 244 246 $ModelId = $this->Database->insert_id; 245 247 foreach ($ModelDesc->Columns as $Field) 246 248 { 247 $this->Database->insert('Mod uleModelField', array('Name' => $Field->Name, 'Model' => $ModelId,249 $this->Database->insert('ModelField', array('Name' => $Field->Name, 'Model' => $ModelId, 248 250 'Type' => ModelColumnType::GetName($Field->Type), 'Nullable' => (int)$Field->Nullable)); 249 251 } 250 252 } 251 253 252 function UninstallModel(ModelDesc $ModelDesc, AppModule $Module) 253 { 254 $this->Database->delete('ModuleModel', '(Name='.$ModelDesc->Name.') AND (Module='.$Module->Id.')'); 254 function UninstallModel(ModelDesc $ModelDesc, Module $Module) 255 { 256 $DbResult = $this->Database->select('Model', 'Id', '(Name="'.$ModelDesc->Name.'") AND (Module='.$Module->Id.')'); 257 if ($DbResult->num_rows > 0) 258 { 259 $DbRow = $DbResult->fetch_assoc(); 260 $ModelId = $DbRow['Id']; 261 $DbResult = $this->Database->delete('ModelField', '(Model='.$ModelId.')'); 262 } 263 $this->Database->delete('Model', '(Id='.$ModelId.')'); 255 264 $this->RemoveModelDatabase($ModelDesc); 256 265 } 257 266 258 function InstallModule(AppModule $Module) 259 { 260 echo('Install module '.$Module->Name); 267 function InstallModule(Module $Module) 268 { 261 269 $this->Database->insert('Module', array( 270 'Id' => $Module->Id, 262 271 'Name' => $Module->Name, 263 272 'Title' => $Module->Title, … … 269 278 'InstalledVersion' => $Module->InstalledVersion 270 279 )); 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); 278 } 279 280 function ModuleChange(AppModule $Module): void 280 } 281 282 function UninstallModule(Module $Module) 283 { 284 $this->Database->delete('Module', 'Name="'.$Module->Name.'"'); 285 } 286 287 function ModuleChange(Module $Module): void 281 288 { 282 289 if ($Module->Installed) $Installed = 1; … … 293 300 while ($Module = $DbResult->fetch_array()) 294 301 { 295 //echo($Module['Name'].',');296 302 include_once('Modules/'.$Module['Name'].'/'.$Module['Name'].'.php'); 297 303 $ModuleClassName = 'Module'.$Module['Name']; … … 534 540 } 535 541 536 class Mod uleextends Model542 class ModelField extends Model 537 543 { 538 static function Get Desc(): ModelDesc544 static function GetModelDesc(): ModelDesc 539 545 { 540 546 $Desc = new ModelDesc(self::GetClassName()); 541 547 $Desc->AddString('Name'); 542 $Desc->AddString('Title'); 543 $Desc->AddString('Creator'); 544 $Desc->AddString('Version'); 545 $Desc->AddString('License'); 546 $Desc->AddBoolean('Installed'); 547 $Desc->AddString('InstalledVersion'); 548 $Desc->AddString('Description'); 549 return $Desc; 550 } 551 } 552 553 class ModuleModel extends Model 554 { 555 static function GetDesc(): ModelDesc 556 { 557 $Desc = new ModelDesc(self::GetClassName()); 558 $Desc->AddString('Name'); 559 $Desc->AddReference('Module', Module::GetClassName()); 560 return $Desc; 561 } 562 } 563 564 class ModuleModelField extends Model 565 { 566 static function GetDesc(): ModelDesc 567 { 568 $Desc = new ModelDesc(self::GetClassName()); 569 $Desc->AddString('Name'); 570 $Desc->AddReference('Model', ModuleModel::GetClassName()); 548 $Desc->AddReference('Model', Model::GetClassName()); 571 549 $Desc->AddString('Type'); 572 550 $Desc->AddBoolean('Nullable'); … … 577 555 class ModuleDependency extends Model 578 556 { 579 static function Get Desc(): ModelDesc557 static function GetModelDesc(): ModelDesc 580 558 { 581 559 $Desc = new ModelDesc(self::GetClassName());
Note:
See TracChangeset
for help on using the changeset viewer.