Changeset 895
- Timestamp:
- Jan 12, 2021, 10:29:50 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Core.php
r887 r895 22 22 public string $RootURLFolder; 23 23 public bool $ShowPage; 24 public Setup $Setup;25 24 public array $PageHeaders; 26 25 public BaseView $BaseView; … … 78 77 } 79 78 80 function AddModule($Module): void81 {82 $this->ModuleManager->Modules[get_class($Module)] = $Module;83 }84 85 79 function HumanDate(int $Time): string 86 80 { … … 131 125 $this->Config = &$Config; 132 126 133 try { 127 try 128 { 134 129 $this->Database->Connect($this->Config['Database']['Host'], $this->Config['Database']['User'], 135 130 $this->Config['Database']['Password'], $this->Config['Database']['Database']); … … 140 135 if (isset($this->Config['Web']['LogSQLQuery'])) 141 136 $this->Database->LogSQLQuery = $this->Config['Web']['LogSQLQuery']; 142 } catch (Exception $E) { 137 } catch (Exception $E) 138 { 143 139 //$Output .= 'Nelze se připojit k databázi.'; 144 140 } … … 162 158 RegisterFormClasses($this->FormManager); 163 159 164 // Register and start existing modules 165 $this->Setup = new Setup($this); 166 $this->Setup->Start(); 167 if ($this->Setup->CheckState()) 168 { 169 $this->ModuleManager->Start(); 170 } 160 $this->ModuleManager->Start(); 171 161 } 172 162 -
trunk/Modules/Network/Network.php
r894 r895 184 184 'API' => array('Type' => 'TDeviceAPIType', 'Caption' => 'API', 'Default' => '', 'Null' => true), 185 185 'Logs' => array('Type' => 'TDeviceLogList', 'Caption' => 'Záznamy', 'Default' => ''), 186 'InboundNATPriority' => array('Type' => 'Integer', 'Caption' => 'Priorita příchozího NATu', 'Default' => '1'), 186 187 ), 187 188 'AfterInsert' => array($this, 'AfterInsertNetworkDevice'), -
trunk/Modules/Network/NetworkModels.php
r894 r895 32 32 $Desc->AddString('LoginPassword'); 33 33 $Desc->AddReference('API', DeviceAPIType::GetClassName()); 34 $Desc->AddInteger('InboundNATPriority'); 34 35 return $Desc; 35 36 } -
trunk/Modules/Portal/Portal.php
r893 r895 14 14 $this->Description = 'Community portal.'; 15 15 $this->Dependencies = array('News', 'User'); 16 } 17 18 function GetModels(): array 19 { 20 return array(Panel::GetClassName(), PanelColumn::GetClassName()); 21 } 22 23 function DoInstall(): void 24 { 25 /* $this->Database->query("INSERT INTO `PanelColumn` (`Id`, `Width`) VALUES 26 (1, ''), 27 (2, ''), 28 (3, '70%');"); 29 $this->Database->query("INSERT INTO `Panel` (`Id`, `Module`, `Parameters`, `Order`, `PanelColumn`) VALUES 30 (1, 'ActionGroup', 1, 2, 1), 31 (2, 'ActionGroup', 4, 1, 2), 32 (3, 'ActionGroup', 5, 2, 2), 33 (4, 'ActionGroup', 6, 3, 2), 34 (5, 'ActionGroup', 2, 4, 2), 35 (6, 'ActionGroup', 3, 5, 2), 36 (7, 'NewsGroupList', '', 2, 3), 37 (8, 'Webcam', '', 3, 1), 38 (9, 'UserOptions', '', 1, 3), 39 (10, 'ActionGroup', 9, 1, 1), 40 (11, 'Meteo', '', 4, 1);");*/ 16 41 } 17 42 … … 35 60 )); 36 61 ModuleUser::Cast($this->System->GetModule('User'))->UserPanel[] = array('PagePortal', 'UserPanel'); 62 } 63 } 64 65 class PanelColumn extends Model 66 { 67 static function GetDesc(): ModelDesc 68 { 69 $Desc = new ModelDesc(self::GetClassName()); 70 $Desc->AddString('Width'); 71 return $Desc; 72 } 73 } 74 75 class Panel extends Model 76 { 77 static function GetDesc(): ModelDesc 78 { 79 $Desc = new ModelDesc(self::GetClassName()); 80 $Desc->AddString('Module'); 81 $Desc->AddString('Parameters'); 82 $Desc->AddInteger('Order'); 83 $Desc->AddInteger('PanelColumn'); 84 return $Desc; 37 85 } 38 86 } … … 216 264 217 265 $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; 218 $DbResult = $this->Database->update('Member', 'Id='.$User->User['Member'], 266 $DbResult = $this->Database->query('SELECT `Customer` FROM `UserCustomerRel` '. 267 'WHERE `User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id']); 268 $CustomerUserRel = $DbResult->fetch_assoc(); 269 $CustomerId = $CustomerUserRel['Member']; 270 271 $DbResult = $this->Database->update('Member', 'Id='.$CustomerId, 219 272 array('FamilyMemberCount' => $Form->Values['FamilyMemberCount'])); 220 $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$ User->User['Member']);273 $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$CustomerId); 221 274 $Member = $DbResult->fetch_assoc(); 222 275 $DbResult = $this->Database->update('Subject', 'Id='.$Member['Subject'], … … 231 284 'Subject.Name, Subject.AddressStreet, Subject.AddressTown, Subject.AddressPSC, '. 232 285 'Subject.AddressCountry, Subject.IC, Subject.DIC FROM Member JOIN Subject '. 233 'ON Subject.Id = Member.Subject WHERE Member.Id='.$ User->User['Member']);286 'ON Subject.Id = Member.Subject WHERE Member.Id='.$CustomerId); 234 287 $DbRow = $DbResult->fetch_array(); 235 288 foreach ($Form->Definition['Items'] as $Index => $Item) -
trunk/Modules/Subject/Subject.php
r894 r895 133 133 function GetModels(): array 134 134 { 135 return array( Country::GetClassName(),Subject::GetClassName(), ContactCategory::GetClassName(),135 return array(Subject::GetClassName(), ContactCategory::GetClassName(), 136 136 Contact::GetClassName()); 137 137 } … … 166 166 } 167 167 168 class Country extends Model169 {170 static function GetDesc(): ModelDesc171 {172 $Desc = new ModelDesc(self::GetClassName());173 $Desc->AddString('Name');174 return $Desc;175 }176 }177 178 168 class Contact extends Model 179 169 { -
trunk/Modules/System/System.php
r894 r895 1 1 <?php 2 3 include_once(dirname(__FILE__).'/SystemModels.php'); 2 4 3 5 class PageModules extends Page … … 109 111 $this->Description = 'Base system module'; 110 112 $this->Dependencies = array(); 113 $this->SystemModule = true; 111 114 } 112 115 … … 115 118 return array(UnitOfMeasure::GetClassName(), ActionIcon::GetClassName(), ActionGroup::GetClassName(), 116 119 ActionType::GetClassName(), Action::GetClassName(), Language::GetClassName(), Country::GetClassName()); 120 } 121 122 function DoBeforeInstall(): void 123 { 124 $this->Manager->OnInstallModel = array($this, 'InstallModel'); 125 $this->Manager->OnUninstallModel = array($this, 'UninstallModel'); 126 } 127 128 function DoAfterUninstall(): void 129 { 130 $this->Manager->OnInstallModel = null; 131 $this->Manager->OnUninstallModel = null; 117 132 } 118 133 … … 184 199 function DoStart(): void 185 200 { 201 $this->Manager->OnInstallModel = array($this, 'InstallModel'); 202 $this->Manager->OnUninstallModel = array($this, 'UninstallModel'); 203 186 204 $this->System->RegisterPage(['module'], 'PageModules'); 187 205 $this->System->FormManager->RegisterClass('Action', array( … … 404 422 //$this->Manager->OnModuleChange = array($this, 'ModuleChange'); 405 423 //$this->LoadFromDatabase(); 424 } 425 426 function InstallModel(ModelDesc $ModelDesc) 427 { 428 $Query = "CREATE TABLE IF NOT EXISTS `".$ModelDesc->Name."` (\n"; 429 $Query .= ' `'.$ModelDesc->PrimaryKey.'` int(11) NOT NULL AUTO_INCREMENT,'."\n"; 430 foreach ($ModelDesc->Columns as $Column) 431 { 432 $Query .= " `".$Column->Name."` "; 433 if ($Column->Type == ModelColumnType::Integer) $Query .= 'int(11)'; 434 else if ($Column->Type == ModelColumnType::String) $Query .= 'varchar(255)'; 435 else if ($Column->Type == ModelColumnType::Float) $Query .= 'varchar(255)'; 436 else if ($Column->Type == ModelColumnType::Text) $Query .= 'text'; 437 else if ($Column->Type == ModelColumnType::DateTime) $Query .= 'datetime'; 438 else if ($Column->Type == ModelColumnType::Reference) $Query .= 'int(11)'; 439 else if ($Column->Type == ModelColumnType::Boolean) $Query .= 'tinyint(1)'; 440 else if ($Column->Type == ModelColumnType::Date) $Query .= 'date'; 441 else if ($Column->Type == ModelColumnType::BigInt) $Query .= 'bigint(20)'; 442 else if ($Column->Type == ModelColumnType::Enum) 443 { 444 $Query .= 'enum("'.implode('", "', $Column->States).'")'; 445 } 446 447 if ($Column->Nullable) $Query .= ''; 448 else $Query .= ' NOT NULL'; 449 450 $Query .= ' COLLATE utf8_general_ci'; 451 452 if ($Column->HasDefault) 453 { 454 if ($Column->Default == null) 455 $Query .= ' DEFAULT NULL'; 456 else $Query .= ' DEFAULT '.$Column->GetDefault(); 457 } 458 $Query .= ",\n"; 459 } 460 $Query .= ' PRIMARY KEY (`'.$ModelDesc->PrimaryKey.'`)'; 461 foreach ($ModelDesc->Columns as $Column) 462 { 463 if ($Column->Type == ModelColumnType::Reference) 464 $Query .= ','."\n".' KEY `'.$Column->Name.'` (`'.$Column->Name.'`)'; 465 else if ($Column->Unique) 466 $Query .= ','."\n".' UNIQUE KEY `'.$Column->Name.'` (`'.$Column->Name.'`)'; 467 } 468 $Query .= "\n"; 469 470 if ($ModelDesc->Memory) $Engine = 'MEMORY'; 471 else $Engine = 'InnoDB'; 472 $Query .= ') ENGINE='.$Engine.' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'; 473 $I = 1; 474 foreach ($ModelDesc->Columns as $Column) 475 { 476 if ($Column->Type == ModelColumnType::Reference) 477 $Query .= "ALTER TABLE `".$ModelDesc->Name."` ". 478 "ADD CONSTRAINT `".$ModelDesc->Name."_ibfk_".$I."` FOREIGN KEY (`".$Column->Name."`) REFERENCES `".$Column->RefTable."` (`Id`);"; 479 $I++; 480 } 481 $this->Database->query($Query); 482 } 483 484 function UninstallModel(ModelDesc $ModelDesc) 485 { 486 $this->Database->query('DROP TABLE IF EXISTS `'.$ModelDesc->Name.'`'); 406 487 } 407 488 … … 544 625 } 545 626 } 546 547 class UnitOfMeasure extends Model548 {549 static function GetDesc(): ModelDesc550 {551 $Desc = new ModelDesc(self::GetClassName());552 $Desc->AddString('Name');553 $Desc->AddString('Unit');554 return $Desc;555 }556 }557 558 class Action extends Model559 {560 static function GetDesc(): ModelDesc561 {562 $Desc = new ModelDesc(self::GetClassName());563 $Desc->AddString('Title');564 $Desc->AddString('URL');565 $Desc->AddReference('Icon', ActionIcon::GetClassName());566 $Desc->AddReference('Type', ActionType::GetClassName());567 $Desc->AddReference('Group', ActionGroup::GetClassName());568 $Desc->AddReference('PermissionOperation', PermissionOperation::GetClassName());569 $Desc->AddBoolean('Enable');570 return $Desc;571 }572 }573 574 class ActionIcon extends Model575 {576 static function GetDesc(): ModelDesc577 {578 $Desc = new ModelDesc(self::GetClassName());579 $Desc->AddString('Name');580 return $Desc;581 }582 }583 584 class ActionGroup extends Model585 {586 static function GetDesc(): ModelDesc587 {588 $Desc = new ModelDesc(self::GetClassName());589 $Desc->AddString('Name');590 return $Desc;591 }592 }593 594 class ActionType extends Model595 {596 static function GetDesc(): ModelDesc597 {598 $Desc = new ModelDesc(self::GetClassName());599 $Desc->AddString('Name');600 return $Desc;601 }602 }603 604 class Language extends Model605 {606 static function GetDesc(): ModelDesc607 {608 $Desc = new ModelDesc(self::GetClassName());609 $Desc->AddString('Name');610 return $Desc;611 }612 }613 614 class Country extends Model615 {616 static function GetDesc(): ModelDesc617 {618 $Desc = new ModelDesc(self::GetClassName());619 $Desc->AddString('Name');620 return $Desc;621 }622 }623 -
trunk/Modules/User/User.php
r894 r895 29 29 } 30 30 31 function DoInstall(): void 32 { 33 $this->Database->insert('PermissionGroup', array('Id' => 1, 'Description' => 'Ostatní')); 34 $this->Database->insert('PermissionGroup', array('Id' => 2, 'Description' => 'Registrovaní uživatelé')); 35 $this->Database->insert('PermissionGroup', array('Id' => 3, 'Description' => 'Zákazníci')); 36 $this->Database->insert('PermissionGroup', array('Id' => 4, 'Description' => 'Správci sítě')); 37 $this->Database->insert('PermissionGroup', array('Id' => 5, 'Description' => 'Systémoví správci')); 38 } 39 31 40 function DoStart(): void 32 41 { … … 181 190 $Output = 'Uživatelů: '.$DbRow['0'].'<br/>'; 182 191 return $Output; 183 }184 185 function DoStop(): void186 {187 192 } 188 193 -
trunk/Modules/User/UserModel.php
r894 r895 75 75 $Desc->AddString('Salt'); 76 76 $Desc->AddString('Email'); 77 $Desc->AddString('LastIpAddress'); 78 $Desc->AddString('LastLoginTime'); 77 $Column = $Desc->AddString('LastIpAddress'); 78 $Column->HasDefault = true; 79 $Column->Nullable = true; 80 $Column = $Desc->AddDateTime('LastLoginTime'); 81 $Column->Nullable = true; 82 $Column->HasDefault = true; 79 83 $Desc->AddDateTime('RegistrationTime'); 80 84 $Desc->AddBoolean('Locked'); 81 $Desc->AddString('InitPassword'); 85 $Column = $Desc->AddString('InitPassword'); 86 $Column->Nullable = true; 87 $Column->HasDefault = true; 82 88 return $Desc; 83 89 } … … 118 124 if ($Row['User'] != '') 119 125 { 120 $Query = $this->Database->query('SELECT `User`.*, `UserCustomerRel`.`Customer` AS `Member` FROM `User` '. 121 ' LEFT JOIN `UserCustomerRel` ON `UserCustomerRel`.`User`=`User`.`Id` WHERE `User`.`Id`='.$Row['User']); 126 $Query = $this->Database->query('SELECT `User`.* FROM `User` WHERE `User`.`Id`='.$Row['User']); 122 127 $this->User = $Query->fetch_assoc(); 123 128 $Result = USER_LOGGED; … … 500 505 { 501 506 $Desc = new ModelDesc(self::GetClassName()); 502 $Desc->AddReference('Module', Module::GetClassName());507 //$Desc->AddReference('Module', Module::GetClassName()); 503 508 $Desc->AddString('Operation'); 504 509 $Desc->AddString('Item'); -
trunk/Modules/User/UserPage.php
r887 r895 21 21 function ShowContacts(): string 22 22 { 23 if (!$this->System->ModuleManager->ModuleRunning('Subject')) return ''; 24 23 25 $Query = 'SELECT `Contact`.`Value`, `Contact`.`Description`, (SELECT `Name` FROM `ContactCategory` WHERE `ContactCategory`.`Id` = `Contact`.`Category`) AS `Category` '. 24 26 'FROM `Contact` WHERE `User` = '. … … 39 41 $Order = GetOrderTableHeader('Contacts', $TableColumns, 'Value', 0); 40 42 $Output .= $Order['Output']; 41 42 43 $Query = $Query.' '.$Order['SQL'].$PageList['SQLLimit']; 43 44 44 $DbResult = $this->Database->query($Query); 45 45 while ($Contact = $DbResult->fetch_assoc()) … … 49 49 '<td>'.$Contact['Value'].'</td>'. 50 50 '<td>'.$Contact['Description'].'</td>'. 51 '</tr>';51 '</tr>'; 52 52 } 53 53 $Output .= '</table>'; -
trunk/Modules/Wiki/Wiki.php
r894 r895 46 46 static function GetDesc(): ModelDesc 47 47 { 48 $Desc = new ModelDesc( 'WikiPage');48 $Desc = new ModelDesc(self::GetClassName()); 49 49 $Desc->AddString('Name'); 50 50 $Desc->AddString('NormalizedName'); -
trunk/Packages/Common/AppModule.php
r894 r895 32 32 const Running = 5; 33 33 const NotRunning = 6; 34 const System = 7; 35 const User = 8; 34 36 } 35 37 … … 55 57 public $OnChange; 56 58 public array $Models; 59 public bool $SystemModule; 57 60 58 61 function __construct(Application $System) … … 71 74 $this->Type = ModuleType::Normal; 72 75 $this->Models = array(); 76 $this->SystemModule = false; 73 77 } 74 78 … … 84 88 $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotInstalled)); 85 89 $this->Manager->Perform($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled)); 90 $this->DoBeforeInstall(); 86 91 $this->InstallModels(); 87 92 $this->DoInstall(); 88 93 $this->Installed = true; 94 $this->Enabled = true; // Automatically enable installed module 89 95 $this->InstalledVersion = $this->Version; 90 96 $this->Manager->Modules[$this->Name] = $this; … … 101 107 $this->DoUninstall(); 102 108 $this->UninstallModels(); 109 $this->DoAfterUninstall(); 103 110 } 104 111 … … 175 182 } 176 183 184 protected function DoBeforeInstall(): void 185 { 186 } 187 177 188 protected function DoInstall(): void 178 189 { … … 183 194 } 184 195 185 protected function DoUpgrade(): void 186 { 196 protected function DoAfterUninstall(): void 197 { 198 } 199 200 protected function DoUpgrade(): string 201 { 202 return ''; 187 203 } 188 204 … … 194 210 function InstallModels(): void 195 211 { 196 foreach ($this->GetModels() as $Model) 197 { 198 $this->InstallModel($Model::GetDesc()); 212 if ($this->Manager->OnInstallModel != null) 213 { 214 foreach ($this->GetModels() as $Model) 215 { 216 call_user_func($this->Manager->OnInstallModel, $Model::GetDesc()); 217 } 199 218 } 200 219 } … … 202 221 function UninstallModels(): void 203 222 { 204 foreach (array_reverse($this->GetModels()) as $Model) 205 { 206 $this->UninstallModel($Model::GetDesc()); 207 } 208 } 209 210 function InstallModel(ModelDesc $ModelDesc) 211 { 212 $Query = "CREATE TABLE IF NOT EXISTS `".$ModelDesc->Name."` (\n"; 213 $Query .= ' `'.$ModelDesc->PrimaryKey.'` int(11) NOT NULL AUTO_INCREMENT,'."\n"; 214 foreach ($ModelDesc->Columns as $Column) 215 { 216 $Query .= " `".$Column->Name."` "; 217 if ($Column->Type == ModelColumnType::Integer) $Query .= 'int(11)'; 218 else if ($Column->Type == ModelColumnType::String) $Query .= 'varchar(255)'; 219 else if ($Column->Type == ModelColumnType::Float) $Query .= 'varchar(255)'; 220 else if ($Column->Type == ModelColumnType::Text) $Query .= 'text'; 221 else if ($Column->Type == ModelColumnType::DateTime) $Query .= 'datetime'; 222 else if ($Column->Type == ModelColumnType::Reference) $Query .= 'int(11)'; 223 else if ($Column->Type == ModelColumnType::Boolean) $Query .= 'tinyint(1)'; 224 else if ($Column->Type == ModelColumnType::Date) $Query .= 'date'; 225 else if ($Column->Type == ModelColumnType::BigInt) $Query .= 'bigint(20)'; 226 else if ($Column->Type == ModelColumnType::Enum) 227 { 228 $Query .= 'enum("'.implode('", "', $Column->States).'")'; 229 } 230 231 if ($Column->Nullable) $Query .= ''; 232 else $Query .= ' NOT NULL'; 233 234 $Query .= ' COLLATE utf8_general_ci'; 235 236 if ($Column->HasDefault) 237 { 238 if ($Column->Default == null) 239 $Query .= ' DEFAULT NULL'; 240 $Query .= ' DEFAULT '.$Column->GetDefault(); 241 } 242 $Query .= ",\n"; 243 } 244 $Query .= ' PRIMARY KEY (`'.$ModelDesc->PrimaryKey.'`)'; 245 foreach ($ModelDesc->Columns as $Column) 246 { 247 if ($Column->Type == ModelColumnType::Reference) 248 $Query .= ','."\n".' KEY `'.$Column->Name.'` (`'.$Column->Name.'`)'; 249 else if ($Column->Unique) 250 $Query .= ','."\n".' UNIQUE KEY `'.$Column->Name.'` (`'.$Column->Name.'`)'; 251 } 252 $Query .= "\n"; 253 254 if ($ModelDesc->Memory) $Engine = 'MEMORY'; 255 else $Engine = 'InnoDB'; 256 $Query .= ') ENGINE='.$Engine.' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'; 257 $I = 1; 258 foreach ($ModelDesc->Columns as $Column) 259 { 260 if ($Column->Type == ModelColumnType::Reference) 261 $Query .= "ALTER TABLE `".$ModelDesc->Name."` ". 262 "ADD CONSTRAINT `".$ModelDesc->Name."_ibfk_".$I."` FOREIGN KEY (`".$Column->Name."`) REFERENCES `".$Column->RefTable."` (`Id`);"; 263 $I++; 264 } 265 $this->Database->query($Query); 266 } 267 268 function UninstallModel(ModelDesc $ModelDesc) 269 { 270 $this->Database->query('DROP TABLE IF EXISTS `'.$ModelDesc->Name.'`'); 223 if ($this->Manager->OnUninstallModel != null) 224 { 225 foreach (array_reverse($this->GetModels()) as $Model) 226 { 227 call_user_func($this->Manager->OnUninstallModel, $Model::GetDesc()); 228 } 229 } 271 230 } 272 231 } … … 280 239 public string $ModulesDir; 281 240 public $OnLoadModules; 241 public $OnInstallModel; 242 public $OnUninstsallModel; 282 243 283 244 function __construct(System $System) … … 287 248 $this->FileName = dirname(__FILE__).'/../../Config/ModulesConfig.php'; 288 249 $this->ModulesDir = dirname(__FILE__).'/../../Modules'; 250 $this->OnInstallModel = null; 251 $this->OnUninstallModel = null; 289 252 } 290 253 291 254 function Perform(array $List, array $Actions, array $Conditions = array(ModuleCondition::All)): void 292 255 { 293 foreach ($List as $ Index => $Module)256 foreach ($List as $Module) 294 257 { 295 258 if (in_array(ModuleCondition::All, $Conditions) or … … 299 262 (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)) or 300 263 ($Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or 301 (!$Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions))) 264 (!$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))) 302 267 { 303 268 foreach ($Actions as $Action) … … 328 293 (!$DepModule->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or 329 294 ($DepModule->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 330 (!$DepModule->Installed and in_array(ModuleCondition::NotInstalled, $Conditions))) 295 (!$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))) 331 298 { 332 299 array_push($List, $DepModule); … … 347 314 (!$RefModule->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or 348 315 ($RefModule->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 349 (!$RefModule->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)))) 350 { 316 (!$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)))) 319 { 351 320 array_push($List, $RefModule); 352 321 $this->EnumSuperiorDependenciesCascade($RefModule, $List, $Conditions); … … 357 326 function Start(): void 358 327 { 359 $this->LoadModules(); 360 if (file_exists($this->FileName)) $this->LoadState(); 361 $this->StartEnabled(); 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 } 362 344 } 363 345 … … 370 352 { 371 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)); 372 359 } 373 360 … … 383 370 } 384 371 372 function InstallSystem(): void 373 { 374 $this->Perform($this->Modules, array(ModuleAction::Install), array(ModuleCondition::System)); 375 $this->SaveState(); 376 } 377 385 378 function UninstallAll(): void 386 379 { … … 425 418 foreach ($this->Modules as $Module) 426 419 { 427 //DebugLog($Module->Name.' '.$Module->Id);428 420 if ($Module->Id == $Id) return $Module->Name; 429 421 } … … 452 444 foreach ($this->Modules as $Module) 453 445 { 454 $Data[] = array('Name' => $Module->Name, 'Enabled' => $Module->Enabled, 455 'Version' => $Module->Version, 'Installed' => $Module->Installed); 446 $Data[] = array( 447 'Name' => $Module->Name, 448 'Enabled' => $Module->Enabled, 449 'Version' => $Module->Version, 450 'Installed' => $Module->Installed 451 ); 456 452 } 457 453 if (file_put_contents($this->FileName, "<?php \n\n\$ConfigModules = ".var_export($Data, true).";\n") === FALSE) … … 473 469 } 474 470 471 function LoadModule(string $FileName): AppModule 472 { 473 include_once($FileName); 474 $ModuleName = 'Module'.pathinfo($FileName, PATHINFO_FILENAME); 475 $Module = new $ModuleName($this->System); 476 $this->RegisterModule($Module); 477 return $Module; 478 } 479 475 480 function LoadModulesFromDir(string $Directory): void 476 481 { … … 480 485 if (is_dir($Directory.'/'.$Item) and ($Item != '.') and ($Item != '..') and ($Item != '.svn')) 481 486 { 482 include_once($Directory.'/'.$Item.'/'.$Item.'.php'); 483 $ModuleName = 'Module'.$Item; 484 $this->RegisterModule(new $ModuleName($this->System)); 487 $this->LoadModule($Directory.'/'.$Item.'/'.$Item.'.php'); 485 488 } 486 489 } -
trunk/Packages/Common/Application.php
r887 r895 65 65 function GetModule(string $Name): AppModule 66 66 { 67 return $this->ModuleManager->Modules[$Name]; 67 if (array_key_exists($Name, $this->ModuleManager->Modules)) 68 return $this->ModuleManager->Modules[$Name]; 69 else return null; 68 70 } 69 71 -
trunk/Packages/Common/Setup.php
r891 r895 1 1 <?php 2 2 3 class PageSetup extends Page3 class PageSetupModules extends Page 4 4 { 5 public UpdateManager $UpdateManager;6 public array $ConfigDefinition;7 public array $Config;8 public int $DatabaseRevision;9 public int $Revision;10 public string $ConfigDir;11 5 public array $YesNo; 12 6 … … 14 8 { 15 9 parent::__construct($System); 16 $this->FullTitle = T('Application setup'); 17 $this->ShortTitle = T('Application setup'); 18 //$this->ParentClass = 'PagePortal'; 19 $this->ConfigDir = dirname(dirname(dirname(__FILE__))).'/Config'; 10 $this->FullTitle = T('Modules'); 11 $this->ShortTitle = T('Modules'); 12 $this->ParentClass = 'PageSetup'; 20 13 $this->YesNo = array(false => T('No'), true => T('Yes')); 21 14 } 22 15 23 function LoginPanel(): string24 {25 $Output = '<h3>Přihlášení k instalaci</h3>'.26 '<form action="?" method="post">'.27 '<table>'.28 '<tr><td>Systémové heslo:</td><td> <input type="password" name="SystemPassword" value=""/></td></tr>'.29 '</table>'.30 '<input type="submit" name="login" value="'.T('Login').'"/>'.31 '</form>';32 return $Output;33 }34 35 function ControlPanel(): string36 {37 $Output = '<h3>'.T('Instance management').'</h3>';38 39 $Output .= 'Je připojení k databázi: '.$this->YesNo[$this->UpdateManager->Database->Connected()].'<br/>';40 if ($this->UpdateManager->Database->Connected())41 {42 $Output .= 'Je instalováno: '.$this->YesNo[$this->UpdateManager->IsInstalled()].'<br/>';43 if ($this->UpdateManager->IsInstalled())44 $Output .= 'Je aktuální: '.$this->YesNo[$this->UpdateManager->IsUpToDate()].'<br/>'.45 'Verze databáze: '.$this->UpdateManager->GetDbVersion().'<br/>';46 $Output .= 'Verze databáze kódu: '.$this->UpdateManager->Revision.'<br/>';47 if ($this->UpdateManager->IsInstalled())48 {49 if (!$this->UpdateManager->IsUpToDate())50 $Output .= '<a href="?action=upgrade">'.T('Upgrade').'</a> ';51 $Output .= '<a href="?action=insert_sample_data">Vložit vzorová data</a> ';52 $Output .= '<a href="?action=reload_modules">Obnovit seznam modulů</a> ';53 $Output .= '<a href="?action=uninstall">Odinstalovat</a> ';54 $Output .= '<a href="?action=modules">Správa modulů</a> ';55 $Output .= '<a href="?action=models">Přegenerovat modely</a> ';56 } else $Output .= '<a href="?action=install">Instalovat</a> ';57 }58 $Output .= '<a href="?action=configure">Nastavit</a> ';59 $Output .= '<a href="?action=logout">Odhlásit</a> ';60 $Output .= '<a href="'.$this->System->Link('/').'">'.T('Go to main page').'</a> ';61 $Output .= '';62 return $Output;63 }64 65 16 function Show(): string 66 {67 global $ConfigDefinition, $DatabaseRevision, $Config, $Updates;68 69 $this->UpdateManager = $this->System->Setup->UpdateManager;70 $DefaultConfig = new DefaultConfig();71 $this->ConfigDefinition = $DefaultConfig->Get();72 $this->DatabaseRevision = $DatabaseRevision;73 $this->Config = &$Config;74 75 $Output = '';76 if (isset($this->Config))77 {78 if (!array_key_exists('SystemPassword', $_SESSION)) $_SESSION['SystemPassword'] = '';79 if (array_key_exists('login', $_POST)) $_SESSION['SystemPassword'] = $_POST['SystemPassword'];80 if (sha1($_SESSION['SystemPassword']) != $this->Config['SystemPassword'])81 {82 $Output .= $this->LoginPanel();83 } else84 {85 if (array_key_exists('action', $_GET)) $Action = $_GET['action'];86 else $Action = '';87 if ($Action == 'logout')88 {89 $_SESSION['SystemPassword'] = '';90 $Output .= 'Odhlášen';91 $Output .= $this->LoginPanel();92 } else93 if ($Action == 'models')94 {95 $this->System->FormManager->UpdateSQLMeta();96 } else97 if ($Action == 'upgrade')98 {99 $Output .= '<h3>Povýšení</h3>';100 try {101 $Output .= $this->System->Setup->Upgrade();102 } catch (Exception $E) {103 $Output .= $this->SystemMessage('Chyba aktualizace',104 'Došlo k chybě v SQL dotazu při aktualizaci: <br/>'.$E->getMessage());105 }106 $Output .= $this->ControlPanel();107 } else108 if ($Action == 'install')109 {110 $Output .= '<h3>Instalace</h3>';111 $this->System->Setup->Install();112 $this->System->ModuleManager->LoadModules();113 $this->System->ModuleManager->SaveState();114 //$Output .= $this->System->Setup->Upgrade();115 $Output .= $this->ControlPanel();116 } else117 if ($Action == 'uninstall')118 {119 $Output .= '<h3>Odinstalace</h3>';120 $this->System->Setup->Uninstall();121 $Output .= $this->ControlPanel();122 } else123 if ($Action == 'reload_modules')124 {125 $Output .= '<h3>Znovunačtení seznamu modulů</h3>';126 $this->System->ModuleManager->LoadModules();127 $this->System->ModuleManager->SaveState();128 $Output .= $this->ControlPanel();129 } else130 if ($Action == 'insert_sample_data')131 {132 $Output .= '<h3>Vložení vzorových dat</h3>';133 $this->System->Setup->InsertSampleData();134 $Output .= $this->ControlPanel();135 } else136 if ($Action == 'modules')137 {138 $Output .= $this->ShowModules();139 } else140 if ($Action == 'configure_save')141 {142 $Output .= $this->ConfigSave($this->Config);143 $Output .= $this->ControlPanel();144 } else145 if ($Action == 'configure')146 {147 $Output .= $this->PrepareConfig($this->Config);148 } else149 {150 $Output .= $this->ControlPanel();151 }152 }153 } else154 {155 if (array_key_exists('configure_save', $_POST))156 {157 $Output .= $this->ConfigSave(array());158 $Output .= 'Pokračujte k přihlášení <a href="">zde</a>';159 } else {160 $Output .= $this->PrepareConfig(array());161 }162 }163 return $Output;164 }165 166 function ShowModules(): string167 17 { 168 18 $Output = ''; … … 237 87 $Table->Table->Cells[] = array($Module->Name, 238 88 $Module->Creator, $Module->Version, 239 $Module->License, $this->YesNo[$Module->Installed],89 $Module->License, $this->YesNo[$Module->Installed], 240 90 $this->YesNo[$Module->Enabled], $Module->Description, 241 91 $Dependencies, $Actions); … … 245 95 $Output .= $Pageing->Show(); 246 96 //$Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>'; 97 return $Output; 98 } 99 } 100 101 class PageSetup extends Page 102 { 103 public UpdateManager $UpdateManager; 104 public array $ConfigDefinition; 105 public array $Config; 106 public int $DatabaseRevision; 107 public int $Revision; 108 public string $ConfigDir; 109 public array $YesNo; 110 111 function __construct(System $System) 112 { 113 parent::__construct($System); 114 $this->FullTitle = T('Application setup'); 115 $this->ShortTitle = T('Application setup'); 116 //$this->ParentClass = 'PagePortal'; 117 $this->ConfigDir = dirname(dirname(dirname(__FILE__))).'/Config'; 118 $this->YesNo = array(false => T('No'), true => T('Yes')); 119 } 120 121 function LoginPanel(): string 122 { 123 $Output = '<h3>Přihlášení k instalaci</h3>'. 124 '<form action="?" method="post">'. 125 '<table>'. 126 '<tr><td>Systémové heslo:</td><td> <input type="password" name="SystemPassword" value=""/></td></tr>'. 127 '</table>'. 128 '<input type="submit" name="login" value="'.T('Login').'"/>'. 129 '</form>'; 130 return $Output; 131 } 132 133 function ControlPanel(): string 134 { 135 $Output = '<h3>'.T('Instance management').'</h3>'; 136 137 $Output .= 'Je připojení k databázi: '.$this->YesNo[$this->UpdateManager->Database->Connected()].'<br/>'; 138 if ($this->UpdateManager->Database->Connected()) 139 { 140 $Output .= 'Je instalováno: '.$this->YesNo[$this->UpdateManager->IsInstalled()].'<br/>'; 141 if ($this->UpdateManager->IsInstalled()) 142 $Output .= 'Je aktuální: '.$this->YesNo[$this->UpdateManager->IsUpToDate()].'<br/>'. 143 'Verze databáze: '.$this->UpdateManager->GetDbVersion().'<br/>'; 144 $Output .= 'Verze databáze kódu: '.$this->UpdateManager->Revision.'<br/>'; 145 if ($this->UpdateManager->IsInstalled()) 146 { 147 if (!$this->UpdateManager->IsUpToDate()) 148 $Output .= '<a href="?action=upgrade">'.T('Upgrade').'</a> '; 149 $Output .= '<a href="?action=insert_sample_data">Vložit vzorová data</a> '; 150 $Output .= '<a href="?action=reload_modules">Obnovit seznam modulů</a> '; 151 $Output .= '<a href="?action=uninstall">Odinstalovat</a> '; 152 $Output .= '<a href="'.$this->System->Link('/setup/modules/').'">Správa modulů</a> '; 153 $Output .= '<a href="?action=models">Přegenerovat modely</a> '; 154 } else $Output .= '<a href="?action=install">Instalovat</a> '; 155 } 156 $Output .= '<a href="?action=configure">Nastavit</a> '; 157 $Output .= '<a href="?action=logout">Odhlásit</a> '; 158 $Output .= '<a href="'.$this->System->Link('/').'">'.T('Go to main page').'</a> '; 159 $Output .= ''; 160 return $Output; 161 } 162 163 function Show(): string 164 { 165 global $ConfigDefinition, $DatabaseRevision, $Config, $Updates; 166 167 $this->UpdateManager = ModuleSetup::Cast($this->System->GetModule('Setup'))->UpdateManager; 168 $DefaultConfig = new DefaultConfig(); 169 $this->ConfigDefinition = $DefaultConfig->Get(); 170 $this->DatabaseRevision = $DatabaseRevision; 171 $this->Config = &$Config; 172 173 $Output = ''; 174 if (isset($this->Config)) 175 { 176 if (!array_key_exists('SystemPassword', $_SESSION)) $_SESSION['SystemPassword'] = ''; 177 if (array_key_exists('login', $_POST)) $_SESSION['SystemPassword'] = $_POST['SystemPassword']; 178 if (sha1($_SESSION['SystemPassword']) != $this->Config['SystemPassword']) 179 { 180 $Output .= $this->LoginPanel(); 181 } else 182 { 183 if (array_key_exists('action', $_GET)) $Action = $_GET['action']; 184 else $Action = ''; 185 if ($Action == 'logout') 186 { 187 $_SESSION['SystemPassword'] = ''; 188 $Output .= 'Odhlášen'; 189 $Output .= $this->LoginPanel(); 190 } 191 else if ($Action == 'models') 192 { 193 $this->System->FormManager->UpdateSQLMeta(); 194 } 195 else if ($Action == 'upgrade') 196 { 197 $Output .= '<h3>Povýšení</h3>'; 198 try 199 { 200 $Output .= ModuleSetup::Cast($this->System->GetModule('Setup'))->Upgrade(); 201 } catch (Exception $E) 202 { 203 $Output .= $this->SystemMessage('Chyba aktualizace', 204 'Došlo k chybě v SQL dotazu při aktualizaci: <br/>'.$E->getMessage()); 205 } 206 $Output .= $this->ControlPanel(); 207 } 208 else if ($Action == 'install') 209 { 210 $Output .= '<h3>Instalace</h3>'; 211 ModuleSetup::Cast($this->System->GetModule('Setup'))->Install(); 212 $this->System->ModuleManager->LoadModules(); 213 $this->System->ModuleManager->SaveState(); 214 //$Output .= ModuleSetup::Cast($this->System->GetModule('Setup'))->Upgrade(); 215 $Output .= $this->ControlPanel(); 216 } 217 else if ($Action == 'uninstall') 218 { 219 $Output .= '<h3>Odinstalace</h3>'; 220 ModuleSetup::Cast($this->System->GetModule('Setup'))->Uninstall(); 221 $Output .= $this->ControlPanel(); 222 } 223 else if ($Action == 'reload_modules') 224 { 225 $Output .= '<h3>Znovunačtení seznamu modulů</h3>'; 226 $this->System->ModuleManager->LoadModules(); 227 $this->System->ModuleManager->SaveState(); 228 $Output .= $this->ControlPanel(); 229 } 230 else if ($Action == 'insert_sample_data') 231 { 232 $Output .= '<h3>Vložení vzorových dat</h3>'; 233 ModuleSetup::Cast($this->System->GetModule('Setup'))->InsertSampleData(); 234 $Output .= $this->ControlPanel(); 235 } 236 else if ($Action == 'configure_save') 237 { 238 $Output .= $this->ConfigSave($this->Config); 239 $Output .= $this->ControlPanel(); 240 } 241 else if ($Action == 'configure') 242 { 243 $Output .= $this->PrepareConfig($this->Config); 244 } 245 else 246 { 247 $Output .= $this->ControlPanel(); 248 } 249 } 250 } else 251 { 252 if (array_key_exists('configure_save', $_POST)) 253 { 254 $Output .= $this->ConfigSave(array()); 255 $Output .= 'Pokračujte k přihlášení <a href="">zde</a>'; 256 } else { 257 $Output .= $this->PrepareConfig(array()); 258 } 259 } 247 260 return $Output; 248 261 } … … 256 269 $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože soubor "'.$this->ConfigDir.'/Config.php" není povolen pro zápis!'; 257 270 $Output .= '<h3>Nastavení systému</h3>'. 258 259 271 '<form action="?action=configure_save" method="post">'. 272 '<table>'; 260 273 foreach ($this->ConfigDefinition as $Def) 261 274 { … … 279 292 } 280 293 $Output .= '</td></tr>'. 281 282 283 294 '<tr><td colspan="2"><input type="submit" name="configure_save" value="'.T('Save').'"/></td></tr>'. 295 '</table>'. 296 '</form>'; 284 297 return $Output; 285 298 } … … 365 378 if (!$this->Database->Connected()) $Output .= T('Can\'t connect to database').'<br>'; 366 379 else { 367 if (! $this->System->Setup->UpdateManager->IsInstalled())380 if (!ModuleSetup::Cast($this->System->GetModule('Setup'))->UpdateManager->IsInstalled()) 368 381 $Output .= T('System requires database initialization').'<br>'; 369 382 else 370 if (! $this->System->Setup->UpdateManager->IsUpToDate())383 if (!ModuleSetup::Cast($this->System->GetModule('Setup'))->UpdateManager->IsUpToDate()) 371 384 $Output .= T('System requires database upgrade').'<br>'; 372 385 } … … 376 389 } 377 390 378 class Setup extends Model391 class ModuleSetup extends AppModule 379 392 { 380 393 public UpdateManager $UpdateManager; 381 394 382 function Start()395 function __construct(System $System) 383 396 { 384 397 global $DatabaseRevision; 385 398 386 $this->System->RegisterPage([''], 'PageSetupRedirect'); 387 $this->System->RegisterPage(['setup'], 'PageSetup'); 399 parent::__construct($System); 400 $this->Name = 'Setup'; 401 $this->Version = '1.0'; 402 $this->Creator = 'Chronos'; 403 $this->License = 'GNU/GPLv3'; 404 $this->Description = 'Base setup module'; 405 $this->Dependencies = array(); 406 $this->Revision = 1; 407 $this->SystemModule = true; 388 408 389 409 // Check database persistence structure … … 394 414 } 395 415 396 function Stop() 416 static function Cast(AppModule $AppModule): ModuleSetup 417 { 418 if ($AppModule instanceof ModuleSetup) 419 { 420 return $AppModule; 421 } 422 throw new Exception('Expected ModuleSetup type but '.gettype($AppModule)); 423 } 424 425 function DoStart(): void 426 { 427 $this->System->RegisterPage([''], 'PageSetupRedirect'); 428 $this->System->RegisterPage(['setup'], 'PageSetup'); 429 $this->System->RegisterPage(['setup', 'modules'], 'PageSetupModules'); 430 } 431 432 function DoStop(): void 397 433 { 398 434 unset($this->UpdateManager); 399 435 $this->System->UnregisterPage(['']); 400 436 $this->System->UnregisterPage(['setup']); 437 $this->System->UnregisterPage(['setup', 'modules']); 401 438 } 402 439 … … 407 444 } 408 445 409 function Install()446 function DoInstall(): void 410 447 { 411 448 global $DatabaseRevision; … … 444 481 } 445 482 446 function Uninstall()483 function DoUninstall(): void 447 484 { 448 485 $this->System->ModuleManager->UninstallAll(); … … 459 496 } 460 497 461 function Upgrade(): string498 function DoUpgrade(): string 462 499 { 463 500 $Updates = new Updates(); … … 466 503 return $Output; 467 504 } 505 506 function InsertSampleData(): void 507 { 508 } 468 509 }
Note:
See TracChangeset
for help on using the changeset viewer.