Changeset 899 for trunk/Packages/Common/Modules/Setup.php
- Timestamp:
- Feb 17, 2021, 12:30:23 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Modules/Setup.php
r897 r899 1 1 <?php 2 3 class ModuleSetup extends Module 4 { 5 public UpdateManager $UpdateManager; 6 7 function __construct(System $System) 8 { 9 global $DatabaseRevision; 10 11 parent::__construct($System); 12 $this->Name = 'Setup'; 13 $this->Version = '1.0'; 14 $this->Creator = 'Chronos'; 15 $this->License = 'GNU/GPLv3'; 16 $this->Description = 'Base setup module'; 17 $this->Revision = 1; 18 $this->Type = ModuleType::System; 19 20 // Check database persistence structure 21 $this->UpdateManager = new UpdateManager(); 22 $this->UpdateManager->Database = &$this->Database; 23 $this->UpdateManager->Revision = $DatabaseRevision; 24 $this->UpdateManager->InstallMethod = 'FullInstall'; 25 } 26 27 static function Cast(Module $Module): ModuleSetup 28 { 29 if ($Module instanceof ModuleSetup) 30 { 31 return $Module; 32 } 33 throw new Exception('Expected ModuleSetup type but '.gettype($Module)); 34 } 35 36 function DoStart(): void 37 { 38 Core::Cast($this->System)->RegisterPage([''], 'PageSetupRedirect'); 39 Core::Cast($this->System)->RegisterPage(['setup'], 'PageSetup'); 40 } 41 42 function DoStop(): void 43 { 44 unset($this->UpdateManager); 45 Core::Cast($this->System)->UnregisterPage(['']); 46 Core::Cast($this->System)->UnregisterPage(['setup']); 47 } 48 49 function CheckState(): bool 50 { 51 return $this->Database->Connected() and $this->UpdateManager->IsInstalled() and 52 $this->UpdateManager->IsUpToDate(); 53 } 54 55 function DoUpgrade(): string 56 { 57 $Updates = new Updates(); 58 $this->UpdateManager->Trace = $Updates->Get(); 59 $Output = $this->UpdateManager->Upgrade(); 60 return $Output; 61 } 62 63 function InsertSampleData(): void 64 { 65 } 66 } 2 67 3 68 class PageSetup extends Page … … 111 176 { 112 177 $Output .= '<h3>Instalace systém</h3>'; 178 global $DatabaseRevision; 179 180 $this->Database->query("CREATE TABLE IF NOT EXISTS `".$this->UpdateManager->VersionTable."` (". 181 '`Id` int(11) NOT NULL AUTO_INCREMENT, '. 182 '`Revision` int(11) NOT NULL, '. 183 'PRIMARY KEY (`Id`) '. 184 ') ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'); 185 $DbResult = $this->Database->select($this->UpdateManager->VersionTable, 'Id'); 186 if ($DbResult->num_rows == 0) 187 { 188 $this->Database->query("INSERT INTO `".$this->UpdateManager->VersionTable. 189 "` (`Id`, `Revision`) VALUES (1, ".$DatabaseRevision.");"); 190 } 113 191 $this->System->ModuleManager->InstallAll(array(ModuleCondition::System)); 114 192 $this->System->ModuleManager->LoadModules(); … … 121 199 $Output .= '<h3>Odinstalace vše</h3>'; 122 200 $this->System->ModuleManager->UninstallAll(array(ModuleCondition::System)); 201 $this->Database->query('DROP TABLE IF EXISTS `'.$this->UpdateManager->VersionTable.'`'); 123 202 $Output .= $this->ControlPanel(); 124 203 } … … 296 375 } 297 376 } 298 299 class ModuleSetup extends AppModule300 {301 public UpdateManager $UpdateManager;302 303 function __construct(System $System)304 {305 global $DatabaseRevision;306 307 parent::__construct($System);308 $this->Name = 'Setup';309 $this->Version = '1.0';310 $this->Creator = 'Chronos';311 $this->License = 'GNU/GPLv3';312 $this->Description = 'Base setup module';313 $this->Dependencies = array();314 $this->Revision = 1;315 $this->Type = ModuleType::System;316 317 // Check database persistence structure318 $this->UpdateManager = new UpdateManager();319 $this->UpdateManager->Database = &$this->Database;320 $this->UpdateManager->Revision = $DatabaseRevision;321 $this->UpdateManager->InstallMethod = 'FullInstall';322 }323 324 static function Cast(AppModule $AppModule): ModuleSetup325 {326 if ($AppModule instanceof ModuleSetup)327 {328 return $AppModule;329 }330 throw new Exception('Expected ModuleSetup type but '.gettype($AppModule));331 }332 333 function DoStart(): void334 {335 Core::Cast($this->System)->RegisterPage([''], 'PageSetupRedirect');336 Core::Cast($this->System)->RegisterPage(['setup'], 'PageSetup');337 }338 339 function DoStop(): void340 {341 unset($this->UpdateManager);342 Core::Cast($this->System)->UnregisterPage(['']);343 Core::Cast($this->System)->UnregisterPage(['setup']);344 }345 346 function CheckState(): bool347 {348 return $this->Database->Connected() and $this->UpdateManager->IsInstalled() and349 $this->UpdateManager->IsUpToDate();350 }351 352 function DoUpgrade(): string353 {354 $Updates = new Updates();355 $this->UpdateManager->Trace = $Updates->Get();356 $Output = $this->UpdateManager->Upgrade();357 return $Output;358 }359 }
Note:
See TracChangeset
for help on using the changeset viewer.