Changeset 897 for trunk/Packages/Common/AppModule.php
- Timestamp:
- Jan 22, 2021, 12:04:30 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/AppModule.php
r896 r897 8 8 { 9 9 const System = 0; 10 const Normal= 1;10 const Library = 1; 11 11 const Application = 2; 12 12 } … … 33 33 const NotRunning = 6; 34 34 const System = 7; 35 const User = 8; 35 const Library = 8; 36 const Application = 9; 36 37 } 37 38 … … 57 58 public $OnChange; 58 59 public array $Models; 59 public bool $SystemModule;60 60 61 61 function __construct(Application $System) … … 64 64 $this->Database = &$System->Database; 65 65 $this->Installed = false; 66 $this->InstalledVersion = ''; 66 67 $this->Enabled = false; 67 68 $this->Running = false; … … 72 73 $this->Description = ''; 73 74 $this->Dependencies = array(); 74 $this->Type = ModuleType:: Normal;75 $this->Type = ModuleType::Library; 75 76 $this->Models = array(); 76 $this->SystemModule = false;77 77 } 78 78 … … 87 87 $List = array(); 88 88 $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotInstalled)); 89 $this->Manager->Perform ($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled));89 $this->Manager->PerformList($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled)); 90 90 $this->DoBeforeInstall(); 91 91 $this->InstallModels(); … … 104 104 $List = array(); 105 105 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed)); 106 $this->Manager->Perform ($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed));106 $this->Manager->PerformList($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed)); 107 107 $this->DoUninstall(); 108 108 $this->UninstallModels(); … … 116 116 $List = array(); 117 117 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed)); 118 $this->Manager->Perform ($List, array(ModuleAction::Upgrade), array(ModuleCondition::Installed));118 $this->Manager->PerformList($List, array(ModuleAction::Upgrade), array(ModuleCondition::Installed)); 119 119 $this->DoUpgrade(); 120 120 } … … 133 133 $List = array(); 134 134 $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotRunning)); 135 $this->Manager->Perform ($List, array(ModuleAction::Start), array(ModuleCondition::NotRunning));135 $this->Manager->PerformList($List, array(ModuleAction::Start), array(ModuleCondition::NotRunning)); 136 136 $this->DoStart(); 137 137 $this->Running = true; … … 144 144 $List = array(); 145 145 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Running)); 146 $this->Manager->Perform ($List, array(ModuleAction::Stop), array(ModuleCondition::Running));146 $this->Manager->PerformList($List, array(ModuleAction::Stop), array(ModuleCondition::Running)); 147 147 $this->DoStop(); 148 148 } … … 160 160 $List = array(); 161 161 $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotEnabled)); 162 $this->Manager->Perform ($List, array(ModuleAction::Enable), array(ModuleCondition::NotEnabled));162 $this->Manager->PerformList($List, array(ModuleAction::Enable), array(ModuleCondition::NotEnabled)); 163 163 $this->Enabled = true; 164 164 } … … 171 171 $List = array(); 172 172 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Enabled)); 173 $this->Manager->Perform ($List, array(ModuleAction::Disable), array(ModuleCondition::Enabled));173 $this->Manager->PerformList($List, array(ModuleAction::Disable), array(ModuleCondition::Enabled)); 174 174 } 175 175 … … 252 252 } 253 253 254 function Perform(array $List, array $Actions, array $Conditions = array(ModuleCondition::All)): void 254 function Perform(array $Actions, array $Conditions = array(ModuleCondition::All)): void 255 { 256 $this->PerformList($this->Modules, $Actions, $Conditions); 257 } 258 259 function PerformList(array $List, array $Actions, array $Conditions = array(ModuleCondition::All)): void 255 260 { 256 261 foreach ($List as $Module) … … 263 268 ($Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or 264 269 (!$Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or 265 ($Module->SystemModule and in_array(ModuleCondition::System, $Conditions)) or 266 (!$Module->SystemModule and in_array(ModuleCondition::User, $Conditions))) 270 (($Module->Type == ModuleType::System) and in_array(ModuleCondition::System, $Conditions)) or 271 (($Module->Type == ModuleType::Application) and in_array(ModuleCondition::Application, $Conditions)) or 272 (($Module->Type == ModuleType::Library) and in_array(ModuleCondition::Library, $Conditions))) 267 273 { 268 274 foreach ($Actions as $Action) … … 294 300 ($DepModule->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 295 301 (!$DepModule->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)) or 296 ($DepModule->SystemModule and in_array(ModuleCondition::System, $Conditions)) or 297 (!$DepModule->SystemModule and in_array(ModuleCondition::User, $Conditions))) 302 (($Module->Type == ModuleType::System) and in_array(ModuleCondition::System, $Conditions)) or 303 (($Module->Type == ModuleType::Application) and in_array(ModuleCondition::Application, $Conditions)) or 304 (($Module->Type == ModuleType::Library) and in_array(ModuleCondition::Library, $Conditions))) 298 305 { 299 306 array_push($List, $DepModule); … … 315 322 ($RefModule->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 316 323 (!$RefModule->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)) or 317 ($RefModule->SystemModule and in_array(ModuleCondition::System, $Conditions)) or 318 (!$RefModule->SystemModule and in_array(ModuleCondition::User, $Conditions)))) 324 (($Module->Type == ModuleType::System) and in_array(ModuleCondition::System, $Conditions)) or 325 (($Module->Type == ModuleType::Application) and in_array(ModuleCondition::Application, $Conditions)) or 326 (($Module->Type == ModuleType::Library) and in_array(ModuleCondition::Library, $Conditions)))) 319 327 { 320 328 array_push($List, $RefModule); … … 324 332 } 325 333 326 function Start(): void 327 { 328 $ModuleSetup = $this->LoadModule(dirname(__FILE__).'/Setup.php'); 329 $this->LoadState(); 330 if (!$ModuleSetup->Installed) 331 { 332 $ModuleSetup->Install(); 333 $this->SaveState(); 334 } 335 $ModuleSetup->Start(); 336 if (ModuleSetup::Cast($ModuleSetup)->CheckState()) 337 { 338 $this->LoadModules(); 339 if (file_exists($this->FileName)) $this->LoadState(); 340 $this->InstallSystem(); 341 $this->StartSystem(); 342 $this->StartEnabled(); 343 } 344 } 345 346 function StartAll(): void 347 { 348 $this->Perform($this->Modules, array(ModuleAction::Start)); 349 } 350 351 function StartEnabled(): void 352 { 353 $this->Perform($this->Modules, array(ModuleAction::Start), array(ModuleCondition::Enabled)); 354 } 355 356 function StartSystem(): void 357 { 358 $this->Perform($this->Modules, array(ModuleAction::Start), array(ModuleCondition::System)); 359 } 360 361 function StopAll(): void 362 { 363 $this->Perform($this->Modules, array(ModuleAction::Stop)); 364 } 365 366 function InstallAll(): void 367 { 368 $this->Perform($this->Modules, array(ModuleAction::Install)); 334 function StartAll(array $Conditions = array(ModuleCondition::All)): void 335 { 336 $this->Perform(array(ModuleAction::Start), $Conditions); 337 } 338 339 function StopAll(array $Conditions = array(ModuleCondition::All)): void 340 { 341 $this->Perform(array(ModuleAction::Stop), $Conditions); 342 } 343 344 function InstallAll(array $Conditions = array(ModuleCondition::All)): void 345 { 346 $this->Perform(array(ModuleAction::Install), $Conditions); 369 347 $this->SaveState(); 370 348 } 371 349 372 function InstallSystem(): void373 { 374 $this->Perform( $this->Modules, array(ModuleAction::Install), array(ModuleCondition::System));350 function UninstallAll(array $Conditions = array(ModuleCondition::All)): void 351 { 352 $this->Perform(array(ModuleAction::Uninstall), $Conditions); 375 353 $this->SaveState(); 376 354 } 377 355 378 function UninstallAll(): void379 { 380 $this->Perform( $this->Modules, array(ModuleAction::Uninstall));356 function EnableAll(array $Conditions = array(ModuleCondition::All)): void 357 { 358 $this->Perform(array(ModuleAction::Enable), $Conditions); 381 359 $this->SaveState(); 382 360 } 383 361 384 function EnableAll(): void385 { 386 $this->Perform( $this->Modules, array(ModuleAction::Enable));362 function DisableAll(array $Conditions = array(ModuleCondition::All)): void 363 { 364 $this->Perform(array(ModuleAction::Disable), $Conditions); 387 365 $this->SaveState(); 388 366 } 389 367 390 function DisableAll(): void391 { 392 $this->Perform( $this->Modules, array(ModuleAction::Disable));368 function UpgradeAll(array $Conditions = array(ModuleCondition::All)): void 369 { 370 $this->Perform(array(ModuleAction::Upgrade), $Conditions); 393 371 $this->SaveState(); 394 372 } … … 426 404 { 427 405 $ConfigModules = array(); 428 include ($this->FileName);406 include $this->FileName; 429 407 foreach ($ConfigModules as $Mod) 430 408 { 431 if (array_key_exists($Mod['Name'], $this->Modules)) 432 { 433 $this->Modules[$Mod['Name']] = $this->Modules[$Mod['Name']]; 434 $this->Modules[$Mod['Name']]->Enabled = $Mod['Enabled']; 435 $this->Modules[$Mod['Name']]->Installed = $Mod['Installed']; 436 $this->Modules[$Mod['Name']]->InstalledVersion = $Mod['Version']; 409 $ModuleName = $Mod['Name']; 410 if (array_key_exists($ModuleName, $this->Modules)) 411 { 412 if (array_key_exists('Enabled', $Mod)) 413 { 414 $this->Modules[$ModuleName]->Enabled = $Mod['Enabled']; 415 } 416 if (array_key_exists('Installed', $Mod)) 417 { 418 $this->Modules[$ModuleName]->Installed = $Mod['Installed']; 419 } 420 if (array_key_exists('InstalledVersion', $Mod)) 421 { 422 $this->Modules[$ModuleName]->InstalledVersion = $Mod['InstalledVersion']; 423 } 437 424 } 438 425 } … … 447 434 'Name' => $Module->Name, 448 435 'Enabled' => $Module->Enabled, 449 ' Version' => $Module->Version,436 'InstalledVersion' => $Module->InstalledVersion, 450 437 'Installed' => $Module->Installed 451 438 );
Note:
See TracChangeset
for help on using the changeset viewer.