Changeset 593 for trunk/Common/AppModule.php
- Timestamp:
- Nov 2, 2013, 11:00:41 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.