Changeset 897 for trunk/Packages/Common/Modules/Setup.php
- Timestamp:
- Jan 22, 2021, 12:04:30 AM (4 years ago)
- Location:
- trunk/Packages/Common/Modules
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Modules/Setup.php
r896 r897 1 1 <?php 2 3 class PageSetupModules extends Page4 {5 public array $YesNo;6 7 function __construct(System $System)8 {9 parent::__construct($System);10 $this->FullTitle = T('Modules');11 $this->ShortTitle = T('Modules');12 $this->ParentClass = 'PageSetup';13 $this->YesNo = array(false => T('No'), true => T('Yes'));14 }15 16 function Show(): string17 {18 $Output = '';19 if (array_key_exists('op', $_GET)) $Operation = $_GET['op'];20 else $Operation = '';21 if ($Operation == 'install')22 {23 $this->System->ModuleManager->GetModule($_GET['name'])->Install();24 $this->System->ModuleManager->SaveState();25 $Output .= 'Modul '.$_GET['name'].' instalován<br/>';26 } else27 if ($Operation == 'uninstall')28 {29 $this->System->ModuleManager->GetModule($_GET['name'])->Uninstall();30 $this->System->ModuleManager->SaveState();31 $Output .= 'Modul '.$_GET['name'].' odinstalován<br/>';32 } else33 if ($Operation == 'enable')34 {35 $this->System->ModuleManager->GetModule($_GET['name'])->Enable();36 $this->System->ModuleManager->SaveState();37 $Output .= 'Modul '.$_GET['name'].' povolen<br/>';38 } else39 if ($Operation == 'disable')40 {41 $this->System->ModuleManager->GetModule($_GET['name'])->Disable();42 $this->System->ModuleManager->SaveState();43 $Output .= 'Modul '.$_GET['name'].' zakázán<br/>';44 } else45 if ($Operation == 'upgrade')46 {47 $this->System->ModuleManager->GetModule($_GET['name'])->Upgrade();48 $this->System->ModuleManager->SaveState();49 $Output .= 'Modul '.$_GET['name'].' povýšen<br/>';50 }51 $Output .= '<h3>Správa modulů</h3>';52 $Output .= $this->ShowList();53 return $Output;54 }55 56 function ShowList(): string57 {58 $Output = '';59 60 $Pageing = new Paging();61 $Pageing->TotalCount = count($this->System->ModuleManager->Modules);62 $Table = new VisualTable();63 $Table->SetColumns(array(64 array('Name' => 'Name', 'Title' => 'Jméno'),65 array('Name' => 'Creator', 'Title' => 'Tvůrce'),66 array('Name' => 'Version', 'Title' => 'Verze'),67 array('Name' => 'License', 'Title' => 'Licence'),68 array('Name' => 'Installed', 'Title' => 'Instalováno'),69 array('Name' => 'Enabled', 'Title' => 'Povoleno'),70 array('Name' => 'Description', 'Title' => 'Popis'),71 array('Name' => 'Dependencies', 'Title' => 'Závislosti'),72 array('Name' => '', 'Title' => 'Akce'),73 ));74 foreach ($this->System->ModuleManager->Modules as $Module)75 {76 if (($Module->Dependencies) > 0) $Dependencies = implode(',', $Module->Dependencies);77 else $Dependencies = ' ';78 $Actions = '';79 if ($Module->Installed == true)80 {81 $Actions .= ' <a href="?action=modules&op=uninstall&name='.$Module->Name.'">Odinstalovat</a>';82 if ($Module->Enabled == true) $Actions .= ' <a href="?action=modules&op=disable&name='.$Module->Name.'">Zakázat</a>';83 else $Actions .= ' <a href="?action=modules&op=enable&name='.$Module->Name.'">Povolit</a>';84 if ($Module->InstalledVersion != $Module->Version) $Actions .= ' <a href="?action=modules&op=upgrade&name='.$Module->Name.'">Povýšit</a>';85 } else $Actions .= ' <a href="?action=modules&op=install&name='.$Module->Name.'">Instalovat</a>';86 87 $Table->Table->Cells[] = array($Module->Name,88 $Module->Creator, $Module->Version,89 $Module->License, $this->YesNo[$Module->Installed],90 $this->YesNo[$Module->Enabled], $Module->Description,91 $Dependencies, $Actions);92 }93 $Output .= $Pageing->Show();94 $Output .= $Table->Show();95 $Output .= $Pageing->Show();96 //$Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>';97 return $Output;98 }99 }100 2 101 3 class PageSetup extends Page … … 148 50 $Output .= '<a href="?action=upgrade">'.T('Upgrade').'</a> '; 149 51 $Output .= '<a href="?action=insert_sample_data">Vložit vzorová data</a> '; 150 $Output .= '<a href="?action=reload _modules">Obnovit seznam modulů</a> ';52 $Output .= '<a href="?action=reload-modules">Obnovit seznam modulů</a> '; 151 53 $Output .= '<a href="?action=uninstall">Odinstalovat</a> '; 152 $Output .= '<a href="'.$this->System->Link('/ setup/modules/').'">Správa modulů</a> ';54 $Output .= '<a href="'.$this->System->Link('/modules/').'">Správa modulů</a> '; 153 55 $Output .= '<a href="?action=models">Přegenerovat modely</a> '; 154 56 } else $Output .= '<a href="?action=install">Instalovat</a> '; … … 198 100 try 199 101 { 200 $ Output .= ModuleSetup::Cast($this->System->GetModule('Setup'))->Upgrade();102 $this->System->ModuleManager->UpgradeAll(array(ModuleCondition::System)); 201 103 } catch (Exception $E) 202 104 { … … 208 110 else if ($Action == 'install') 209 111 { 210 $Output .= '<h3>Instalace </h3>';211 ModuleSetup::Cast($this->System->GetModule('Setup'))->Install();112 $Output .= '<h3>Instalace systém</h3>'; 113 $this->System->ModuleManager->InstallAll(array(ModuleCondition::System)); 212 114 $this->System->ModuleManager->LoadModules(); 213 115 $this->System->ModuleManager->SaveState(); … … 217 119 else if ($Action == 'uninstall') 218 120 { 219 $Output .= '<h3>Odinstalace </h3>';220 ModuleSetup::Cast($this->System->GetModule('Setup'))->Uninstall();221 $Output .= $this->ControlPanel(); 222 } 223 else if ($Action == 'reload _modules')121 $Output .= '<h3>Odinstalace vše</h3>'; 122 $this->System->ModuleManager->UninstallAll(array(ModuleCondition::System)); 123 $Output .= $this->ControlPanel(); 124 } 125 else if ($Action == 'reload-modules') 224 126 { 225 127 $Output .= '<h3>Znovunačtení seznamu modulů</h3>'; … … 376 278 { 377 279 $Output = ''; 378 if (!$this->Database->Connected()) $Output .= T('Can\'t connect to database').'<br>'; 379 else { 280 if (!$this->Database->Connected()) 281 { 282 $Output .= T('Can\'t connect to database.').'<br>'; 283 } else 284 { 380 285 if (!ModuleSetup::Cast($this->System->GetModule('Setup'))->UpdateManager->IsInstalled()) 381 $Output .= T('System requires database initialization').'<br>'; 382 else 286 { 287 $Output .= T('System requires database initialization.').'<br>'; 288 } else 383 289 if (!ModuleSetup::Cast($this->System->GetModule('Setup'))->UpdateManager->IsUpToDate()) 384 $Output .= T('System requires database upgrade').'<br>'; 385 } 386 $Output .= sprintf(T('Front page was not configured. Continue to %s'), '<a href="'.$this->System->Link('/setup/').'">'.T('setup').'</a>'); 290 { 291 $Output .= T('System requires database upgrade.').'<br>'; 292 } 293 } 294 $Output .= sprintf(T('Front page was not configured. Continue to %s.'), '<a href="'.$this->System->Link('/setup/').'">'.T('setup').'</a>'); 387 295 return $Output; 388 296 } … … 405 313 $this->Dependencies = array(); 406 314 $this->Revision = 1; 407 $this-> SystemModule = true;315 $this->Type = ModuleType::System; 408 316 409 317 // Check database persistence structure … … 427 335 Core::Cast($this->System)->RegisterPage([''], 'PageSetupRedirect'); 428 336 Core::Cast($this->System)->RegisterPage(['setup'], 'PageSetup'); 429 Core::Cast($this->System)->RegisterPage(['setup', 'modules'], 'PageSetupModules');430 337 } 431 338 … … 435 342 Core::Cast($this->System)->UnregisterPage(['']); 436 343 Core::Cast($this->System)->UnregisterPage(['setup']); 437 Core::Cast($this->System)->UnregisterPage(['setup', 'modules']);438 344 } 439 345 … … 442 348 return $this->Database->Connected() and $this->UpdateManager->IsInstalled() and 443 349 $this->UpdateManager->IsUpToDate(); 444 }445 446 function DoInstall(): void447 {448 global $DatabaseRevision;449 450 $this->Database->query('CREATE TABLE IF NOT EXISTS `'.$this->UpdateManager->VersionTable.'` (451 `Id` int(11) NOT NULL AUTO_INCREMENT,452 `Revision` int(11) NOT NULL,453 PRIMARY KEY (`Id`)454 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;');455 $this->Database->query("INSERT INTO `".$this->UpdateManager->VersionTable."` (`Id`, `Revision`) VALUES456 (1, ".$DatabaseRevision.");");457 $this->Database->query("CREATE TABLE IF NOT EXISTS `Module` (458 `Id` int(11) NOT NULL AUTO_INCREMENT,459 `Name` varchar(255) NOT NULL,460 `Title` varchar(255) NOT NULL,461 PRIMARY KEY (`Id`)462 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");463 $this->Database->query("CREATE TABLE IF NOT EXISTS `ModuleModel` (464 `Id` int(11) NOT NULL AUTO_INCREMENT,465 `Name` varchar(255) NOT NULL,466 `Module` int(11) NOT NULL,467 PRIMARY KEY (`Id`)468 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");469 $this->Database->query('ALTER TABLE `ModuleModel`470 ADD CONSTRAINT `ModuleModel_ibfk_1` FOREIGN KEY (`Module`) REFERENCES `Module` (`Id`);');471 $this->Database->query("CREATE TABLE IF NOT EXISTS `ModuleModelProperty` (472 `Id` int(11) NOT NULL AUTO_INCREMENT,473 `Name` varchar(255) NOT NULL,474 `Model` int(11) NOT NULL,475 `Type` int(11) NOT NULL,476 `Nullable` tinyint(1) NOT NULL,477 PRIMARY KEY (`Id`)478 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");479 $this->Database->query('ALTER TABLE `ModuleModelProperty`480 ADD CONSTRAINT `ModuleModelProperty_ibfk_1` FOREIGN KEY (`Model`) REFERENCES `ModuleModel` (`Id`);');481 }482 483 function DoUninstall(): void484 {485 $this->System->ModuleManager->UninstallAll();486 $this->Database->query('DROP TABLE `ModuleModelProperty`');487 $this->Database->query('DROP TABLE `ModuleModel`');488 $this->Database->query('DROP TABLE `Module`');489 $this->Database->query('DROP TABLE `'.$this->UpdateManager->VersionTable.'`');490 }491 492 function IsInstalled(): bool493 {494 $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->UpdateManager->VersionTable.'"');495 return $DbResult->num_rows > 0;496 350 } 497 351 … … 503 357 return $Output; 504 358 } 505 506 function InsertSampleData(): void507 {508 }509 359 }
Note:
See TracChangeset
for help on using the changeset viewer.