Ignore:
Timestamp:
Nov 2, 2013, 11:00:41 PM (11 years ago)
Author:
chronos
Message:
  • Upraveno: Nastavení modulů je uloženo v adresáři Config, který musí povolen být pro zápis.
  • Upraveno: Instalace modulů nebude probíhat složitě z repozitáře, ale bude se udržovat jeden seznam modulů a nastavovat přímo příznak Installed.
  • Přidáno: Zprovozněno ruční ovládání instalace, odinstalace, povolení, zákázání a povýšení jednotlivých modulů.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/AppModule.php

    r592 r593  
    11<?php
     2
     3/* This implementation will not support installation from remote source. Just
     4 * installation of already presented modules mainly to persistence preparation.
     5 */
    26
    37class ModuleType
     
    3741  var $License;
    3842  var $Creator;
     43  var $HomePage;
    3944  var $Description;
     45  var $Running;
     46  var $Enabled;
    4047  var $Installed;
    4148  var $InstalledVersion;
    42   var $Running;
    43   var $Enabled;
    4449  /** @var ModuleType */
    4550  var $Type;
     
    4954  /** @var System */
    5055  var $System;
    51   /** @var ModularSystem */
     56  /** @var AppModuleManager */
    5257  var $Manager;
    5358  var $OnChange;
    5459 
    55   function __construct($System)
     60  function __construct(System $System)
    5661  {
    5762    $this->System = &$System;
    5863    $this->Database = &$System->Database;
    5964    $this->Installed = false;
     65    $this->Enabled = false;
     66    $this->Running = false;
    6067    $this->Dependencies = array();
    6168    $this->Type = ModuleType::Normal;
     
    7077    $this->DoInstall();
    7178        $this->Installed = true;
     79        $this->InstalledVersion = $this->Version;
    7280        $this->Manager->Modules[$this->Name] = $this;
    7381  }
     
    7886    $this->Stop();
    7987    $this->Installed = false;
    80     unset($this->Manager->Modules[$this->Name]);
    8188    $List = array();
    8289    $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed));
    8390    $this->Manager->Perform($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed));
    8491    $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();
    85101  }
    86102 
     
    161177  var $Modules;
    162178  var $System;
    163   var $Repository;
    164179  var $FileName;
    165  
    166   function __construct($System)
     180  var $OnLoadModules;
     181 
     182  function __construct(System $System)
    167183  {
    168184    $this->Modules = array();
    169185    $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';     
    173187  }
    174188 
     
    203217    {
    204218      $DepModule = $this->Modules[$Dependency];
    205        if(in_array(ModuleCondition::All, $Conditions) or
     219      if(in_array(ModuleCondition::All, $Conditions) or
    206220        ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or
    207221        (!$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
    208224        ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or
    209225        (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)))
     
    224240          ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or
    225241          (!$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
    226244          ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or
    227245          (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions))))
     
    235253  function Start()
    236254  {
    237     $this->Repository->LoadModules();
    238     $this->Load();
     255    $this->LoadModules();
     256    if(file_exists($this->FileName)) $this->LoadState();
    239257    $this->StartEnabled();
    240258  }
     
    271289  }
    272290 
    273   function Load()
     291  function LoadState()
    274292  {
    275293    include($this->FileName);
    276     $this->Modules = array();
    277294    foreach($ConfigModules as $Mod)
    278295    {
    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']];
    282299        $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'];
    284302      } 
    285303    }
    286304  }
    287305 
    288   function Save()
     306  function SaveState()
    289307  {
    290308    $Data = array();
     
    292310    {
    293311      $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");
    312315  }
    313316 
    314317  function RegisterModule(AppModule $Module)
    315318  {
    316     $this->Modules[$Module->Name] = &$Module; 
    317     $Module->Manager = &$this->Manager;
     319    $this->Modules[$Module->Name] = &$Module;
     320    $Module->Manager = &$this;
    318321    $Module->OnChange = &$this->OnModuleChange;
    319322  }
     
    321324  function UnregisterModule($Module)
    322325  {
    323     unset($this->Modules[array_search($Module, $this->Modules)]); 
    324   }
    325 
     326    unset($this->Modules[array_search($Module, $this->Modules)]);
     327  }
     328 
    326329  function LoadModulesFromDir($Directory)
    327330  {
     
    331334      if(is_dir($Directory.'/'.$Item) and ($Item != '.') and ($Item != '..') and ($Item != '.svn'))
    332335      {
    333           include_once($Directory.'/'.$Item.'/'.$Item.'.php');
    334           $ModuleName = 'Module'.$Item;
    335           $this->RegisterModule(new $ModuleName($this->System));
     336        include_once($Directory.'/'.$Item.'/'.$Item.'.php');
     337        $ModuleName = 'Module'.$Item;
     338        $this->RegisterModule(new $ModuleName($this->System));
    336339      }
    337340    }
     
    341344  {
    342345    if(method_exists($this->OnLoadModules[0], $this->OnLoadModules[1]))
    343                 $this->OnLoadModules();
     346      $this->OnLoadModules();
    344347    else $this->LoadModulesFromDir(dirname(__FILE__).'/../Modules');
    345348  }
Note: See TracChangeset for help on using the changeset viewer.