Ignore:
Timestamp:
Jan 22, 2021, 12:04:30 AM (4 years ago)
Author:
chronos
Message:
  • Modified: Setup module is always installed and enabled to be executed as base system module. From Setup module all other system modules can be installed.
  • Added: Allow to install, uninstall, enable, disable and upgrade all user modules.
  • Added: Created ModuleManager app module for managing other modules.
  • Modified: Keep InstalledVersion for installed modules in ModulesConfig.php.
  • Added: Distinction between system, library and application module types.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/AppModule.php

    r896 r897  
    88{
    99  const System = 0;
    10   const Normal = 1;
     10  const Library = 1;
    1111  const Application = 2;
    1212}
     
    3333  const NotRunning = 6;
    3434  const System = 7;
    35   const User = 8;
     35  const Library = 8;
     36  const Application = 9;
    3637}
    3738
     
    5758  public $OnChange;
    5859  public array $Models;
    59   public bool $SystemModule;
    6060
    6161  function __construct(Application $System)
     
    6464    $this->Database = &$System->Database;
    6565    $this->Installed = false;
     66    $this->InstalledVersion = '';
    6667    $this->Enabled = false;
    6768    $this->Running = false;
     
    7273    $this->Description = '';
    7374    $this->Dependencies = array();
    74     $this->Type = ModuleType::Normal;
     75    $this->Type = ModuleType::Library;
    7576    $this->Models = array();
    76     $this->SystemModule = false;
    7777  }
    7878
     
    8787    $List = array();
    8888    $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotInstalled));
    89     $this->Manager->Perform($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled));
     89    $this->Manager->PerformList($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled));
    9090    $this->DoBeforeInstall();
    9191    $this->InstallModels();
     
    104104    $List = array();
    105105    $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed));
    106     $this->Manager->Perform($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed));
     106    $this->Manager->PerformList($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed));
    107107    $this->DoUninstall();
    108108    $this->UninstallModels();
     
    116116    $List = array();
    117117    $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed));
    118     $this->Manager->Perform($List, array(ModuleAction::Upgrade), array(ModuleCondition::Installed));
     118    $this->Manager->PerformList($List, array(ModuleAction::Upgrade), array(ModuleCondition::Installed));
    119119    $this->DoUpgrade();
    120120  }
     
    133133    $List = array();
    134134    $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotRunning));
    135     $this->Manager->Perform($List, array(ModuleAction::Start), array(ModuleCondition::NotRunning));
     135    $this->Manager->PerformList($List, array(ModuleAction::Start), array(ModuleCondition::NotRunning));
    136136    $this->DoStart();
    137137    $this->Running = true;
     
    144144    $List = array();
    145145    $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Running));
    146     $this->Manager->Perform($List, array(ModuleAction::Stop), array(ModuleCondition::Running));
     146    $this->Manager->PerformList($List, array(ModuleAction::Stop), array(ModuleCondition::Running));
    147147    $this->DoStop();
    148148  }
     
    160160    $List = array();
    161161    $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotEnabled));
    162     $this->Manager->Perform($List, array(ModuleAction::Enable), array(ModuleCondition::NotEnabled));
     162    $this->Manager->PerformList($List, array(ModuleAction::Enable), array(ModuleCondition::NotEnabled));
    163163    $this->Enabled = true;
    164164  }
     
    171171    $List = array();
    172172    $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Enabled));
    173     $this->Manager->Perform($List, array(ModuleAction::Disable), array(ModuleCondition::Enabled));
     173    $this->Manager->PerformList($List, array(ModuleAction::Disable), array(ModuleCondition::Enabled));
    174174  }
    175175
     
    252252  }
    253253
    254   function Perform(array $List, array $Actions, array $Conditions = array(ModuleCondition::All)): void
     254  function Perform(array $Actions, array $Conditions = array(ModuleCondition::All)): void
     255  {
     256    $this->PerformList($this->Modules, $Actions, $Conditions);
     257  }
     258
     259  function PerformList(array $List, array $Actions, array $Conditions = array(ModuleCondition::All)): void
    255260  {
    256261    foreach ($List as $Module)
     
    263268        ($Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or
    264269        (!$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)))
     270        (($Module->Type == ModuleType::System) and in_array(ModuleCondition::System, $Conditions)) or
     271        (($Module->Type == ModuleType::Application) and in_array(ModuleCondition::Application, $Conditions)) or
     272        (($Module->Type == ModuleType::Library) and in_array(ModuleCondition::Library, $Conditions)))
    267273      {
    268274        foreach ($Actions as $Action)
     
    294300        ($DepModule->Installed and in_array(ModuleCondition::Installed, $Conditions)) or
    295301        (!$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)))
     302        (($Module->Type == ModuleType::System) and in_array(ModuleCondition::System, $Conditions)) or
     303        (($Module->Type == ModuleType::Application) and in_array(ModuleCondition::Application, $Conditions)) or
     304        (($Module->Type == ModuleType::Library) and in_array(ModuleCondition::Library, $Conditions)))
    298305      {
    299306        array_push($List, $DepModule);
     
    315322          ($RefModule->Installed and in_array(ModuleCondition::Installed, $Conditions)) or
    316323          (!$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))))
     324          (($Module->Type == ModuleType::System) and in_array(ModuleCondition::System, $Conditions)) or
     325          (($Module->Type == ModuleType::Application) and in_array(ModuleCondition::Application, $Conditions)) or
     326          (($Module->Type == ModuleType::Library) and in_array(ModuleCondition::Library, $Conditions))))
    319327        {
    320328        array_push($List, $RefModule);
     
    324332  }
    325333
    326   function Start(): void
    327   {
    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     }
    344   }
    345 
    346   function StartAll(): void
    347   {
    348     $this->Perform($this->Modules, array(ModuleAction::Start));
    349   }
    350 
    351   function StartEnabled(): void
    352   {
    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));
    359   }
    360 
    361   function StopAll(): void
    362   {
    363     $this->Perform($this->Modules, array(ModuleAction::Stop));
    364   }
    365 
    366   function InstallAll(): void
    367   {
    368     $this->Perform($this->Modules, array(ModuleAction::Install));
     334  function StartAll(array $Conditions = array(ModuleCondition::All)): void
     335  {
     336    $this->Perform(array(ModuleAction::Start), $Conditions);
     337  }
     338
     339  function StopAll(array $Conditions = array(ModuleCondition::All)): void
     340  {
     341    $this->Perform(array(ModuleAction::Stop), $Conditions);
     342  }
     343
     344  function InstallAll(array $Conditions = array(ModuleCondition::All)): void
     345  {
     346    $this->Perform(array(ModuleAction::Install), $Conditions);
    369347    $this->SaveState();
    370348  }
    371349
    372   function InstallSystem(): void
    373   {
    374     $this->Perform($this->Modules, array(ModuleAction::Install), array(ModuleCondition::System));
     350  function UninstallAll(array $Conditions = array(ModuleCondition::All)): void
     351  {
     352    $this->Perform(array(ModuleAction::Uninstall), $Conditions);
    375353    $this->SaveState();
    376354  }
    377355
    378   function UninstallAll(): void
    379   {
    380     $this->Perform($this->Modules, array(ModuleAction::Uninstall));
     356  function EnableAll(array $Conditions = array(ModuleCondition::All)): void
     357  {
     358    $this->Perform(array(ModuleAction::Enable), $Conditions);
    381359    $this->SaveState();
    382360  }
    383361
    384   function EnableAll(): void
    385   {
    386     $this->Perform($this->Modules, array(ModuleAction::Enable));
     362  function DisableAll(array $Conditions = array(ModuleCondition::All)): void
     363  {
     364    $this->Perform(array(ModuleAction::Disable), $Conditions);
    387365    $this->SaveState();
    388366  }
    389367
    390   function DisableAll(): void
    391   {
    392     $this->Perform($this->Modules, array(ModuleAction::Disable));
     368  function UpgradeAll(array $Conditions = array(ModuleCondition::All)): void
     369  {
     370    $this->Perform(array(ModuleAction::Upgrade), $Conditions);
    393371    $this->SaveState();
    394372  }
     
    426404  {
    427405    $ConfigModules = array();
    428     include($this->FileName);
     406    include $this->FileName;
    429407    foreach ($ConfigModules as $Mod)
    430408    {
    431       if (array_key_exists($Mod['Name'], $this->Modules))
    432       {
    433         $this->Modules[$Mod['Name']] = $this->Modules[$Mod['Name']];
    434         $this->Modules[$Mod['Name']]->Enabled = $Mod['Enabled'];
    435         $this->Modules[$Mod['Name']]->Installed = $Mod['Installed'];
    436         $this->Modules[$Mod['Name']]->InstalledVersion = $Mod['Version'];
     409      $ModuleName = $Mod['Name'];
     410      if (array_key_exists($ModuleName, $this->Modules))
     411      {
     412        if (array_key_exists('Enabled', $Mod))
     413        {
     414          $this->Modules[$ModuleName]->Enabled = $Mod['Enabled'];
     415        }
     416        if (array_key_exists('Installed', $Mod))
     417        {
     418          $this->Modules[$ModuleName]->Installed = $Mod['Installed'];
     419        }
     420        if (array_key_exists('InstalledVersion', $Mod))
     421        {
     422          $this->Modules[$ModuleName]->InstalledVersion = $Mod['InstalledVersion'];
     423        }
    437424      }
    438425    }
     
    447434        'Name' => $Module->Name,
    448435        'Enabled' => $Module->Enabled,
    449         'Version' => $Module->Version,
     436        'InstalledVersion' => $Module->InstalledVersion,
    450437        'Installed' => $Module->Installed
    451438      );
Note: See TracChangeset for help on using the changeset viewer.