Changeset 593
- Timestamp:
- Nov 2, 2013, 11:00:41 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/System.php
r592 r593 26 26 $this->Pages = array(); 27 27 $this->ModuleManager = new AppModuleManager($this); 28 $this->ModuleManager->FileName = dirname(__FILE__).'/../Config/ModulesConfig.php'; 28 29 $this->Database = new Database(); 29 30 $this->FormManager = new FormManager($this->Database); -
trunk/Application/Version.php
r592 r593 1 1 <?php 2 2 3 $Revision = 59 2; // Subversion revision3 $Revision = 593; // Subversion revision 4 4 $DatabaseRevision = 591; // SQL structure revision 5 5 $ReleaseTime = '2013-11-02'; -
trunk/Common/AppModule.php
r592 r593 1 1 <?php 2 3 /* This implementation will not support installation from remote source. Just 4 * installation of already presented modules mainly to persistence preparation. 5 */ 2 6 3 7 class ModuleType … … 37 41 var $License; 38 42 var $Creator; 43 var $HomePage; 39 44 var $Description; 45 var $Running; 46 var $Enabled; 40 47 var $Installed; 41 48 var $InstalledVersion; 42 var $Running;43 var $Enabled;44 49 /** @var ModuleType */ 45 50 var $Type; … … 49 54 /** @var System */ 50 55 var $System; 51 /** @var ModularSystem*/56 /** @var AppModuleManager */ 52 57 var $Manager; 53 58 var $OnChange; 54 59 55 function __construct( $System)60 function __construct(System $System) 56 61 { 57 62 $this->System = &$System; 58 63 $this->Database = &$System->Database; 59 64 $this->Installed = false; 65 $this->Enabled = false; 66 $this->Running = false; 60 67 $this->Dependencies = array(); 61 68 $this->Type = ModuleType::Normal; … … 70 77 $this->DoInstall(); 71 78 $this->Installed = true; 79 $this->InstalledVersion = $this->Version; 72 80 $this->Manager->Modules[$this->Name] = $this; 73 81 } … … 78 86 $this->Stop(); 79 87 $this->Installed = false; 80 unset($this->Manager->Modules[$this->Name]);81 88 $List = array(); 82 89 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed)); 83 90 $this->Manager->Perform($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed)); 84 91 $this->DoUninstall(); 92 } 93 94 function Upgrade() 95 { 96 if(!$this->Installed) return; 97 $List = array(); 98 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed)); 99 $this->Manager->Perform($List, array(ModuleAction::Upgrade), array(ModuleCondition::Installed)); 100 $this->DoUpgrade(); 85 101 } 86 102 … … 161 177 var $Modules; 162 178 var $System; 163 var $Repository;164 179 var $FileName; 165 166 function __construct($System) 180 var $OnLoadModules; 181 182 function __construct(System $System) 167 183 { 168 184 $this->Modules = array(); 169 185 $this->System = &$System; 170 $this->Repository = new AppModuleRepository($System); 171 $this->Repository->Manager = $this; 172 $this->FileName = 'Config.php'; 186 $this->FileName = 'Config/Modules.php'; 173 187 } 174 188 … … 203 217 { 204 218 $DepModule = $this->Modules[$Dependency]; 205 219 if(in_array(ModuleCondition::All, $Conditions) or 206 220 ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or 207 221 (!$Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or 222 ($Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or 223 (!$Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or 208 224 ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 209 225 (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions))) … … 224 240 ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or 225 241 (!$Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or 242 ($Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or 243 (!$Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or 226 244 ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 227 245 (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)))) … … 235 253 function Start() 236 254 { 237 $this-> Repository->LoadModules();238 $this->Load();255 $this->LoadModules(); 256 if(file_exists($this->FileName)) $this->LoadState(); 239 257 $this->StartEnabled(); 240 258 } … … 271 289 } 272 290 273 function Load ()291 function LoadState() 274 292 { 275 293 include($this->FileName); 276 $this->Modules = array();277 294 foreach($ConfigModules as $Mod) 278 295 { 279 if(array_key_exists($Mod['Name'], $this-> Repository->Modules))280 { 281 $this->Modules[$Mod['Name']] = $this-> Repository->Modules[$Mod['Name']];296 if(array_key_exists($Mod['Name'], $this->Modules)) 297 { 298 $this->Modules[$Mod['Name']] = $this->Modules[$Mod['Name']]; 282 299 $this->Modules[$Mod['Name']]->Enabled = $Mod['Enabled']; 283 $this->Modules[$Mod['Name']]->Version = $Mod['Version']; 300 $this->Modules[$Mod['Name']]->Installed = $Mod['Installed']; 301 $this->Modules[$Mod['Name']]->InstalledVersion = $Mod['Version']; 284 302 } 285 303 } 286 304 } 287 305 288 function Save ()306 function SaveState() 289 307 { 290 308 $Data = array(); … … 292 310 { 293 311 $Data[] = array('Name' => $Module->Name, 'Enabled' => $Module->Enabled, 294 'Version' => $Module->Version); 295 } 296 file_put_contents($this->FileName, "<?php \n\n\$ConfigModules = ".var_export($Data).";\n"); 297 } 298 } 299 300 /* Manager available modules for installation */ 301 class AppModuleRepository 302 { 303 var $Modules; 304 var $System; 305 var $Manager; 306 var $OnLoadModules; 307 308 function __construct($System) 309 { 310 $this->Modules = array(); 311 $this->System = &$System; 312 'Version' => $Module->Version, 'Installed' => $Module->Installed); 313 } 314 file_put_contents($this->FileName, "<?php \n\n\$ConfigModules = ".var_export($Data, true).";\n"); 312 315 } 313 316 314 317 function RegisterModule(AppModule $Module) 315 318 { 316 $this->Modules[$Module->Name] = &$Module; 317 $Module->Manager = &$this ->Manager;319 $this->Modules[$Module->Name] = &$Module; 320 $Module->Manager = &$this; 318 321 $Module->OnChange = &$this->OnModuleChange; 319 322 } … … 321 324 function UnregisterModule($Module) 322 325 { 323 unset($this->Modules[array_search($Module, $this->Modules)]); 324 } 325 326 unset($this->Modules[array_search($Module, $this->Modules)]); 327 } 328 326 329 function LoadModulesFromDir($Directory) 327 330 { … … 331 334 if(is_dir($Directory.'/'.$Item) and ($Item != '.') and ($Item != '..') and ($Item != '.svn')) 332 335 { 333 334 335 336 include_once($Directory.'/'.$Item.'/'.$Item.'.php'); 337 $ModuleName = 'Module'.$Item; 338 $this->RegisterModule(new $ModuleName($this->System)); 336 339 } 337 340 } … … 341 344 { 342 345 if(method_exists($this->OnLoadModules[0], $this->OnLoadModules[1])) 343 346 $this->OnLoadModules(); 344 347 else $this->LoadModulesFromDir(dirname(__FILE__).'/../Modules'); 345 348 } -
trunk/Common/Config.php
r592 r593 47 47 function SaveToFile($FileName) 48 48 { 49 file_put_contents($FileName, "<?php \n\n\$ConfigData = ".var_export($this->Data ).";\n");49 file_put_contents($FileName, "<?php \n\n\$ConfigData = ".var_export($this->Data, true).";\n"); 50 50 } 51 51 -
trunk/Common/Global.php
r592 r593 23 23 24 24 $UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB'); 25 $YesNo = array(false => 'Ne', true => 'Ano'); 25 26 26 27 function HumanSize($Value) -
trunk/Common/Setup/Setup.php
r592 r593 28 28 { 29 29 $Output = '<h3>Přihlášení k instalaci</h3>'. 30 '<form action=" " method="post">'.30 '<form action="?" method="post">'. 31 31 '<table>'. 32 32 '<tr><td>Systémové heslo:</td><td> <input type="password" name="SystemPassword" value=""/></td></tr>'. … … 39 39 function ControlPanel() 40 40 { 41 $YesNo = array(false => 'Ne', true => 'Ano');42 $Output = ' <form action="" method="post">';41 global $YesNo; 42 $Output = ''; 43 43 44 44 $Output .= 'Je připojení k databázi: '.$YesNo[$this->UpdateManager->Database->Connected()].'<br/>'; … … 53 53 { 54 54 if(!$this->UpdateManager->IsUpToDate()) 55 $Output .= '<input type="submit" name="update" value="Aktualizovat"/> '; 56 $Output .= '<input type="submit" name="insert_sample_data" value="Vložit vzorová data"/> '; 57 $Output .= '<input type="submit" name="uninstall" value="Odinstalovat"/><br/><br/>'; 58 $Output .= 'Nainstalované moduly'.$this->ShowList(); 59 $Output .= 'Dostupné moduly<br>'.$this->ShowListAvail(); 60 } else $Output .= '<input type="submit" name="install" value="Instalovat"/> '; 61 } 62 $Output .= '<input type="submit" name="configure" value="Nastavit"/> '; 63 $Output .= '<input type="submit" name="logout" value="Odhlásit"/> '; 64 $Output .= '</form>'; 55 $Output .= '<a href="?action=upgrade">Povýšit</a> '; 56 $Output .= '<a href="?action=insert_sample_data">Vložit vzorová data</a> '; 57 $Output .= '<a href="?action=uninstall">Odinstalovat</a> '; 58 $Output .= '<a href="?action=modules">Správa modulů</a> '; 59 } else $Output .= '<a href="?action=install">Instalovat</a> '; 60 } 61 $Output .= '<a href="?action=configure">Nastavit</a> '; 62 $Output .= '<a href="?action=logout">Odhlásit</a> '; 63 $Output .= ''; 65 64 return($Output); 66 65 } … … 93 92 $this->UpdateManager->InstallMethod = 'FullInstall'; 94 93 95 if(array_key_exists('logout', $_POST)) 94 if(array_key_exists('action', $_GET)) $Action = $_GET['action']; 95 else $Action = ''; 96 if($Action == 'logout') 96 97 { 97 98 $_SESSION['SystemPassword'] = ''; … … 99 100 $Output .= $this->LoginPanel(); 100 101 } else 101 if(array_key_exists('update', $_POST)) 102 { 103 $Output .= '<h3>Aktualizace</h3>'; 104 $Output .= $this->UpdateManager->Update(); 105 $Output .= $this->ControlPanel(); 106 } else 107 if(array_key_exists('install', $_POST)) 108 { 109 $Output .= '<h3>Instalace</h3>'; 110 $this->UpdateManager->Install(); 111 $Output .= $this->UpdateManager->Update(); 112 $Output .= $this->ControlPanel(); 113 } else 114 if(array_key_exists('uninstall', $_POST)) 115 { 116 $Output .= '<h3>Odinstalace</h3>'; 117 $this->UpdateManager->Uninstall(); 118 $Output .= $this->ControlPanel(); 119 } else 120 if(array_key_exists('insert_sample_data', $_POST)) 121 { 122 $Output .= '<h3>Vložení vzorových dat</h3>'; 123 $this->UpdateManager->InsertSampleData(); 124 $Output .= $this->ControlPanel(); 125 } else 126 if(array_key_exists('configure_save', $_POST)) 127 { 128 $Output .= $this->ConfigSave($this->Config); 129 $Output .= $this->ControlPanel(); 130 } else 131 if(array_key_exists('configure', $_POST)) 132 { 133 $Output .= $this->PrepareConfig($this->Config); 134 } else 135 { 136 $Output .= $this->ControlPanel(); 137 } 102 if($Action == 'upgrade') 103 { 104 $Output .= '<h3>Povýšení</h3>'; 105 $Output .= $this->System->Setup->Upgrade(); 106 $Output .= $this->ControlPanel(); 107 } else 108 if($Action == 'install') 109 { 110 $Output .= '<h3>Instalace</h3>'; 111 $this->System->Setup->Install(); 112 $Output .= $this->System->Setup->Upgrade(); 113 $Output .= $this->ControlPanel(); 114 } else 115 if($Action == 'uninstall') 116 { 117 $Output .= '<h3>Odinstalace</h3>'; 118 $this->System->Setup->Uninstall(); 119 $Output .= $this->ControlPanel(); 120 } else 121 if($Action == 'insert_sample_data') 122 { 123 $Output .= '<h3>Vložení vzorových dat</h3>'; 124 $this->System->Setup->InsertSampleData(); 125 $Output .= $this->ControlPanel(); 126 } else 127 if($Action == 'modules') 128 { 129 $Output .= $this->ShowModules(); 130 } else 131 if($Action == 'configure_save') 132 { 133 $Output .= $this->ConfigSave($this->Config); 134 $Output .= $this->ControlPanel(); 135 } else 136 if($Action == 'configure') 137 { 138 $Output .= $this->PrepareConfig($this->Config); 139 } else 140 { 141 $Output .= $this->ControlPanel(); 142 } 138 143 } 139 144 } else … … 150 155 } 151 156 157 function ShowModules() 158 { 159 $Output = ''; 160 if(array_key_exists('op', $_GET)) $Operation = $_GET['op']; 161 else $Operation = ''; 162 if($Operation == 'install') 163 { 164 $this->System->ModuleManager->Modules[$_GET['name']]->Install(); 165 $this->System->ModuleManager->SaveState(); 166 $Output .= 'Modul '.$_GET['name'].' instalován<br/>'; 167 } else 168 if($Operation == 'uninstall') 169 { 170 $this->System->ModuleManager->Modules[$_GET['name']]->Uninstall(); 171 $this->System->ModuleManager->SaveState(); 172 $Output .= 'Modul '.$_GET['name'].' odinstalován<br/>'; 173 } else 174 if($Operation == 'enable') 175 { 176 $this->System->ModuleManager->Modules[$_GET['name']]->Enable(); 177 $this->System->ModuleManager->SaveState(); 178 $Output .= 'Modul '.$_GET['name'].' povolen<br/>'; 179 } else 180 if($Operation == 'disable') 181 { 182 $this->System->ModuleManager->Modules[$_GET['name']]->Disable(); 183 $this->System->ModuleManager->SaveState(); 184 $Output .= 'Modul '.$_GET['name'].' zakázán<br/>'; 185 } else 186 if($Operation == 'upgrade') 187 { 188 $this->System->ModuleManager->Modules[$_GET['name']]->Upgrade(); 189 $this->System->ModuleManager->SaveState(); 190 $Output .= 'Modul '.$_GET['name'].' povýšen<br/>'; 191 } 192 $Output .= '<h3>Správa modulů</h3>'; 193 $Output .= $this->ShowList(); 194 return($Output); 195 } 196 152 197 function ShowList() 153 198 { 199 global $YesNo; 200 154 201 $Output = ''; 155 202 $PageList = GetPageList(count($this->System->ModuleManager->Modules)); 156 157 $Output .= $PageList['Output'];158 $Output .= '<table class="WideTable" style="font-size: small;">';159 160 $TableColumns = array(161 array('Name' => 'Name', 'Title' => 'Jméno'),162 array('Name' => 'Creator', 'Title' => 'Tvůrce'),163 array('Name' => 'Version', 'Title' => 'Verze'),164 array('Name' => 'License', 'Title' => 'Licence'),165 array('Name' => 'Enabled', 'Title' => 'Povoleno'),166 array('Name' => 'Description', 'Title' => 'Popis'),167 array('Name' => 'Dependencies', 'Title' => 'Závislosti'),168 array('Name' => '', 'Title' => 'Akce'),169 );170 $Order = GetOrderTableHeader($TableColumns, 'Name', 0);171 $Output .= $Order['Output'];172 173 foreach($this->System->ModuleManager->Modules as $Module)174 {175 if(($Module->Dependencies) > 0) $Dependencies = implode(',', $Module->Dependencies);176 else $Dependencies = ' ';177 if($Module->Enabled == true) $Enabled = 'Ano';178 else $Enabled = 'Ne';179 $Actions = '<a href="?A=Uninstall&Name='.$Module->Name.'">Odinstalovat</a>';180 if($Module->Enabled == true) $Actions .= ' <a href="?A=Disable&Name='.$Module->Name.'">Zakázat</a>';181 else $Actions .= ' <a href="?A=Enable&Name='.$Module->Name.'">Povolit</a>';182 $Output .= '<tr><td>'.$Module->Name.'</td>'.183 '<td>'.$Module->Creator.'</td>'.184 '<td>'.$Module->Version.'</td>'.185 '<td>'.$Module->License.'</td>'.186 '<td>'.$Enabled.'</td>'.187 '<td>'.$Module->Description.'</td>'.188 '<td>'.$Dependencies.'</td>'.189 '<td>'.$Actions.'</td></tr>';190 }191 $Output .= '</table>';192 $Output .= $PageList['Output'];193 //$Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>';194 return($Output);195 }196 197 function ShowListAvail()198 {199 $Output = '';200 $PageList = GetPageList(count($this->System->ModuleManager->Repository->Modules));201 203 202 204 $Output .= $PageList['Output']; … … 209 211 array('Name' => 'License', 'Title' => 'Licence'), 210 212 array('Name' => 'Installed', 'Title' => 'Instalováno'), 213 array('Name' => 'Enabled', 'Title' => 'Povoleno'), 211 214 array('Name' => 'Description', 'Title' => 'Popis'), 212 215 array('Name' => 'Dependencies', 'Title' => 'Závislosti'), … … 216 219 $Output .= $Order['Output']; 217 220 218 foreach($this->System->ModuleManager-> Repository->Modules as $Module)221 foreach($this->System->ModuleManager->Modules as $Module) 219 222 { 220 223 if(($Module->Dependencies) > 0) $Dependencies = implode(',', $Module->Dependencies); 221 else $Dependencies = ' '; 222 if($Module->Installed == true) $Installed = 'Ano'; 223 else $Installed = 'Ne'; 224 if($Module->Installed == true) $Actions = '<a href="?A=Uninstall&Name='.$Module->Name.'">Odinstalovat</a>'; 225 else $Actions = '<a href="?A=Install&Name='.$Module->Name.'">Instalovat</a>'; 224 else $Dependencies = ' '; 225 $Actions = ''; 226 if($Module->Installed == true) 227 { 228 $Actions .= ' <a href="?action=modules&op=uninstall&name='.$Module->Name.'">Odinstalovat</a>'; 229 if($Module->Enabled == true) $Actions .= ' <a href="?action=modules&op=disable&name='.$Module->Name.'">Zakázat</a>'; 230 else $Actions .= ' <a href="?action=modules&op=enable&name='.$Module->Name.'">Povolit</a>'; 231 if($Module->InstalledVersion != $Module->Version) $Actions .= ' <a href="?action=modules&op=upgrade&name='.$Module->Name.'">Povýšit</a>'; 232 } else $Actions .= ' <a href="?action=modules&op=install&name='.$Module->Name.'">Instalovat</a>'; 233 226 234 $Output .= '<tr><td>'.$Module->Name.'</td>'. 227 235 '<td>'.$Module->Creator.'</td>'. 228 236 '<td>'.$Module->Version.'</td>'. 229 237 '<td>'.$Module->License.'</td>'. 230 '<td>'.$Installed.'</td>'. 238 '<td>'.$YesNo[$Module->Installed].'</td>'. 239 '<td>'.$YesNo[$Module->Enabled].'</td>'. 231 240 '<td>'.$Module->Description.'</td>'. 232 241 '<td>'.$Dependencies.'</td>'. … … 247 256 $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože soubor config.php není povolen pro zápis!'; 248 257 $Output .= '<h3>Nastavení systému</h3>'. 249 '<form action=" " method="post">'.258 '<form action="?action=configure_save" method="post">'. 250 259 '<table>'; 251 260 foreach($this->ConfigDefinition as $Def) … … 385 394 $this->UpdateManager->IsUpToDate()); 386 395 } 396 397 function Install() 398 { 399 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemVersion` ( 400 `Id` int(11) NOT NULL AUTO_INCREMENT, 401 `Revision` int(11) NOT NULL, 402 PRIMARY KEY (`Id`) 403 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'); 404 $this->Database->query("INSERT INTO `SystemVersion` (`Id`, `Revision`) VALUES 405 (1, 591);"); 406 } 407 408 function Uninstall() 409 { 410 $this->Database->query('DROP TABLE `SystemVersion`'); 411 } 412 413 function IsInstalled() 414 { 415 $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->VersionTable.'"'); 416 return($DbResult->num_rows > 0); 417 } 418 419 function Upgrade() 420 { 421 $Output = $this->ModuleManager->Update(); 422 return($Output); 423 } 387 424 } -
trunk/Modules/EmailQueue/EmailQueue.php
r586 r593 32 32 } 33 33 34 function UnInstall()34 function DoUninstall() 35 35 { 36 36 } -
trunk/Modules/User/User.php
r586 r593 401 401 function DoInstall() 402 402 { 403 $this->Database->query("CREATE TABLE IF NOT EXISTS `User` ( 404 `Id` int(11) NOT NULL AUTO_INCREMENT, 405 `Login` varchar(64) NOT NULL, 406 `Name` varchar(128) NOT NULL, 407 `Password` varchar(255) NOT NULL, 408 `Salt` varchar(255) NOT NULL, 409 `Email` varchar(128) NOT NULL DEFAULT '', 410 `LastIpAddress` varchar(16) NOT NULL DEFAULT '', 411 `LastLoginTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 412 `RegistrationTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 413 `Locked` tinyint(1) NOT NULL DEFAULT '0', 414 `ICQ` int(11) NOT NULL DEFAULT '0', 415 `PhoneNumber` varchar(32) NOT NULL DEFAULT '', 416 `InitPassword` varchar(255) NOT NULL, 417 PRIMARY KEY (`Id`), 418 UNIQUE KEY `Name` (`Login`), 419 UNIQUE KEY `Nick` (`Name`) 420 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 421 $this->Database->query("CREATE TABLE IF NOT EXISTS `UserOnline` ( 422 `Id` int(11) NOT NULL AUTO_INCREMENT, 423 `User` int(11) DEFAULT NULL COMMENT 'User.Id', 424 `ActivityTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 425 `LoginTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 426 `SessionId` varchar(255) NOT NULL DEFAULT '', 427 `IpAddress` varchar(16) NOT NULL DEFAULT '', 428 `HostName` varchar(255) NOT NULL DEFAULT '', 429 `ScriptName` varchar(255) NOT NULL, 430 PRIMARY KEY (`Id`), 431 KEY `User` (`User`) 432 ) ENGINE=MEMORY DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 403 433 } 404 434 405 435 function DoUninstall() 406 436 { 437 $this->Database->query('DROP TABLE `UserOnline`'); 438 $this->Database->query('DROP TABLE `User`'); 407 439 } 408 440
Note:
See TracChangeset
for help on using the changeset viewer.