Ignore:
Timestamp:
Nov 2, 2013, 7:56:09 PM (11 years ago)
Author:
chronos
Message:
  • Upraveno: Aplikačně závislé soubory přesunuty do adresáře Application.
  • Upraveno: Modul Setup nemůže vystupovat jako aplikační modul neboť připravuje prostředí pro instalaci těchto modulů.
  • Přidáno: Třída AppModuleRepository pro správu dostupných aplikačních balíků k instalaci. Ty se následně instalují do seznamu Modules v třídě AppModuleManager.
Location:
trunk/Common/Setup
Files:
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Common/Setup/Setup.php

    r590 r592  
    88class PageSetup extends Page
    99{
     10  var $UpdateManager;
     11  var $ConfigDefinition;
     12  var $Config;
     13  var $DatabaseRevision;
     14  var $Revision;
     15  var $Updates;
     16  var $ConfigDir;
     17 
    1018  function __construct($System)
    1119  {
     
    1422    $this->ShortTitle = 'Instalátor';
    1523    //$this->ParentClass = 'PagePortal';
    16   }
    17  
    18         function Show()
    19         {
     24    $this->ConfigDir = dirname(__FILE__).'/../..';
     25  }
     26 
     27  function LoginPanel()
     28  {
     29    $Output = '<h3>Přihlášení k instalaci</h3>'.
     30      '<form action="" method="post">'.
     31      '<table>'.
     32      '<tr><td>Systémové heslo:</td><td> <input type="password" name="SystemPassword" value=""/></td></tr>'.
     33      '</table>'.
     34      '<input type="submit" name="login" value="Přihlásit"/>'.
     35      '</form>';
     36    return($Output);
     37  }
     38 
     39  function ControlPanel()
     40  {
     41    $YesNo = array(false => 'Ne', true => 'Ano');
     42    $Output = '<form action="" method="post">';
     43 
     44    $Output .= 'Je připojení k databázi: '.$YesNo[$this->UpdateManager->Database->Connected()].'<br/>';
     45    if($this->UpdateManager->Database->Connected())
     46    {
     47      $Output .= 'Je instalováno: '.$YesNo[$this->UpdateManager->IsInstalled()].'<br/>';
     48      if($this->UpdateManager->IsInstalled())
     49        $Output .= 'Je aktuální: '.$YesNo[$this->UpdateManager->IsUpToDate()].'<br/>'.
     50        'Verze databáze: '.$this->UpdateManager->GetDbVersion().'<br/>';
     51      $Output .= 'Verze databáze kódu: '.$this->UpdateManager->Revision.'<br/>';
     52      if($this->UpdateManager->IsInstalled())
     53      {
     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>';
     65    return($Output);
     66  }
     67 
     68  function Show()
     69  {
    2070          global $ConfigDefinition, $DatabaseRevision, $Config, $Updates;
    2171         
    22           $UpdateInterface = new UpdateInterface();
    2372          $DefaultConfig = new DefaultConfig();
    24           $UpdateInterface->Database = $this->Database;
    25           $UpdateInterface->ConfigDefinition = $DefaultConfig->Get();
    26           $UpdateInterface->DatabaseRevision = $DatabaseRevision;
    27           $UpdateInterface->Config = &$Config;
     73          $this->ConfigDefinition = $DefaultConfig->Get();
     74          $this->DatabaseRevision = $DatabaseRevision;
     75          $this->Config = &$Config;
    2876          $Updates = new Updates();
    29           $UpdateInterface->Updates = $Updates->Get();
    30           return($UpdateInterface->Show());
    31         }
     77          $this->Updates = $Updates->Get();
     78
     79          $Output = '';
     80    if(isset($this->Config))
     81    {
     82      if(!array_key_exists('SystemPassword', $_SESSION)) $_SESSION['SystemPassword'] = '';
     83      if(array_key_exists('login', $_POST)) $_SESSION['SystemPassword'] = $_POST['SystemPassword'];
     84      if(sha1($_SESSION['SystemPassword']) != $this->Config['SystemPassword'])
     85      {
     86        $Output .= $this->LoginPanel();
     87      } else
     88      {
     89        $this->UpdateManager = new UpdateManager();
     90        $this->UpdateManager->Database = $this->Database;
     91        $this->UpdateManager->Revision = $this->DatabaseRevision;
     92        $this->UpdateManager->Trace = $this->Updates;
     93        $this->UpdateManager->InstallMethod = 'FullInstall';
     94 
     95        if(array_key_exists('logout', $_POST))
     96        {
     97          $_SESSION['SystemPassword'] = '';
     98          $Output .= 'Odhlášen';
     99          $Output .= $this->LoginPanel();
     100        } 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                    }
     138      }
     139    } else
     140    {
     141      if(array_key_exists('configure_save', $_POST))
     142      {
     143        $Output .= $this->ConfigSave(array());
     144        $Output .= 'Pokračujte k přihlášení <a href="">zde</a>';
     145      } else {
     146        $Output .= $this->PrepareConfig(array());
     147      }
     148    }
     149    return($Output);
     150  }
     151 
     152  function ShowList()
     153  {
     154    $Output = '';
     155    $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 = '&nbsp;';
     177      if($Module->Enabled == true) $Enabled = 'Ano';
     178        else $Enabled = 'Ne';
     179      $Actions = '<a href="?A=Uninstall&amp;Name='.$Module->Name.'">Odinstalovat</a>';
     180      if($Module->Enabled == true) $Actions .= ' <a href="?A=Disable&amp;Name='.$Module->Name.'">Zakázat</a>';
     181        else $Actions .= ' <a href="?A=Enable&amp;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 
     202    $Output .= $PageList['Output'];
     203    $Output .= '<table class="WideTable" style="font-size: small;">';
     204     
     205    $TableColumns = array(
     206        array('Name' => 'Name', 'Title' => 'Jméno'),
     207        array('Name' => 'Creator', 'Title' => 'Tvůrce'),
     208        array('Name' => 'Version', 'Title' => 'Verze'),
     209        array('Name' => 'License', 'Title' => 'Licence'),
     210        array('Name' => 'Installed', 'Title' => 'Instalováno'),
     211        array('Name' => 'Description', 'Title' => 'Popis'),
     212        array('Name' => 'Dependencies', 'Title' => 'Závislosti'),
     213        array('Name' => '', 'Title' => 'Akce'),
     214    );
     215    $Order = GetOrderTableHeader($TableColumns, 'Name', 0);
     216    $Output .= $Order['Output'];
     217 
     218    foreach($this->System->ModuleManager->Repository->Modules as $Module)
     219    {
     220      if(($Module->Dependencies) > 0) $Dependencies = implode(',', $Module->Dependencies);
     221      else $Dependencies = '&nbsp;';
     222      if($Module->Installed == true) $Installed = 'Ano';
     223      else $Installed = 'Ne';
     224      if($Module->Installed == true) $Actions = '<a href="?A=Uninstall&amp;Name='.$Module->Name.'">Odinstalovat</a>';
     225      else $Actions = '<a href="?A=Install&amp;Name='.$Module->Name.'">Instalovat</a>';
     226      $Output .= '<tr><td>'.$Module->Name.'</td>'.
     227          '<td>'.$Module->Creator.'</td>'.
     228          '<td>'.$Module->Version.'</td>'.
     229          '<td>'.$Module->License.'</td>'.
     230          '<td>'.$Installed.'</td>'.
     231          '<td>'.$Module->Description.'</td>'.
     232          '<td>'.$Dependencies.'</td>'.
     233          '<td>'.$Actions.'</td></tr>';
     234    }
     235    $Output .= '</table>';
     236    $Output .= $PageList['Output'];
     237    //$Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>';
     238    return($Output);
     239  }
     240 
     241  function PrepareConfig($Config)
     242  {
     243    $Output = '';
     244    if(!file_exists($this->ConfigDir.'/config.php') and !is_writable($this->ConfigDir))
     245      $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože složka není povolená pro zápis!';
     246    if(file_exists($this->ConfigDir.'/config.php') and !is_writable($this->ConfigDir.'/config.php'))
     247      $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože soubor config.php není povolen pro zápis!';
     248    $Output .= '<h3>Nastavení systému</h3>'.
     249        '<form action="" method="post">'.
     250        '<table>';
     251    foreach($this->ConfigDefinition as $Def)
     252    {
     253      $PathParts = explode('/', $Def['Name']);
     254      $TempConfig = &$Config;
     255      foreach($PathParts as $Part)
     256        if(array_key_exists($Part, $TempConfig))
     257        {
     258          $TempConfig = &$TempConfig[$Part];
     259        }
     260        if(!is_array($TempConfig)) $Value = $TempConfig;
     261        else $Value = $Def['Default'];
     262        $Output .= '<tr><td>'.$Def['Title'].'</td><td>';
     263        if($Def['Type'] == 'String') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>';
     264        if($Def['Type'] == 'Password') $Output .= '<input type="password" name="'.$Def['Name'].'"/>';
     265        if($Def['Type'] == 'PasswordEncoded') $Output .= '<input type="password" name="'.$Def['Name'].'"/>';
     266        if($Def['Type'] == 'Integer') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>';
     267        if($Def['Type'] == 'Float') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>';
     268        if($Def['Type'] == 'Boolean') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>';
     269    }
     270    $Output .= '</td></tr>'.
     271        '<tr><td colspan="2"><input type="submit" name="configure_save" value="Nastavit"/></td></tr>'.
     272        '</table>'.
     273        '</form>';
     274    return($Output);
     275  }
     276 
     277  function ConfigSave($DefaultConfig)
     278  {
     279    $Config = $DefaultConfig;
     280    foreach($this->ConfigDefinition as $Def)
     281    {
     282      $Value = null;
     283      if($Def['Type'] == 'String') if(array_key_exists($Def['Name'], $_POST))
     284        $Value = $_POST[$Def['Name']];
     285      if($Def['Type'] == 'Password') if(array_key_exists($Def['Name'], $_POST) and ($_POST[$Def['Name']] != ''))
     286        $Value = $_POST[$Def['Name']];
     287      if($Def['Type'] == 'PasswordEncoded') if(array_key_exists($Def['Name'], $_POST) and ($_POST[$Def['Name']] != ''))
     288        $Value = sha1($_POST[$Def['Name']]);
     289      if($Def['Type'] == 'Integer') if(array_key_exists($Def['Name'], $_POST))
     290        $Value = $_POST[$Def['Name']];
     291      if($Def['Type'] == 'Float') if(array_key_exists($Def['Name'], $_POST))
     292        $Value = $_POST[$Def['Name']];
     293      if($Def['Type'] == 'Boolean') if(array_key_exists($Def['Name'], $_POST))
     294        $Value = $_POST[$Def['Name']];
     295      if(!is_null($Value))
     296      {
     297        $PathParts = explode('/', $Def['Name']);
     298        $TempConfig = &$Config;
     299        foreach($PathParts as $Part)
     300        {
     301          $TempConfig = &$TempConfig[$Part];
     302        }
     303        if(!is_array($TempConfig)) $TempConfig = $Value;
     304        else $Value = $Def['Default'];
     305      }
     306    }
     307    $ConfigText = $this->CreateConfig($Config);
     308    file_put_contents($this->ConfigDir.'/config.php', $ConfigText);
     309    $Output .= 'Konfigurace nastavena<br/>';
     310    return($Output);
     311  }
     312 
     313  function CreateConfig($Config)
     314  {
     315 
     316    $Output = "<?php\n\n".
     317        "\$IsDeveloper = in_array(\$_SERVER['REMOTE_ADDR'], array('127.0.0.1'));\n\n";
     318 
     319    foreach($this->ConfigDefinition as $Def)
     320    {
     321      $PathParts = explode('/', $Def['Name']);
     322      $Output .= "\$Config";
     323      foreach($PathParts as $Part)
     324        $Output .= "['".$Part."']";
     325      $TempConfig = &$Config;
     326      foreach($PathParts as $Part)
     327        if(array_key_exists($Part, $TempConfig))
     328        {
     329          $TempConfig = &$TempConfig[$Part];
     330        }
     331        if(!is_array($TempConfig)) $Value = $TempConfig;
     332        else $Value = $Def['Default'];
     333        $Output .= " = '".$Value."';\n";
     334    }
     335    $Output .= "\n\n";
     336    return($Output);
     337  }
    32338}
    33339
     
    39345          if(!$this->Database->Connected()) $Output .= 'Nelze se připojit k databázi.<br>';
    40346          else {
    41             if(!$this->System->ModuleManager->Modules['Setup']->UpdateManager->IsInstalled())
     347            if(!$this->System->Setup->UpdateManager->IsInstalled())
    42348              $Output .= 'Systém vyžaduje instalaci databáze.<br>';
    43349            else
    44             if(!$this->System->ModuleManager->Modules['Setup']->UpdateManager->IsUpToDate())
     350            if(!$this->System->Setup->UpdateManager->IsUpToDate())
    45351              $Output .= 'Systém vyžaduje aktualizaci databáze.<br>';
    46352          }
     
    50356}
    51357
    52 class ModuleSetup extends AppModule
     358class Setup extends Model
    53359{
    54360  var $UpdateManager;
    55361 
    56   function __construct($System)
    57   {
    58     parent::__construct($System);
    59     $this->Name = 'Setup';
    60     $this->Version = '1.0';
    61     $this->Creator = 'Chronos';
    62     $this->License = 'GNU/GPL';
    63     $this->Description = 'Basic setup and application installation';
    64     $this->Dependencies = array();
    65   }
    66  
    67   function DoStart()
     362  function Start()
    68363  {
    69364    global $DatabaseRevision;
     
    78373  } 
    79374 
    80   function DoStop()
     375  function Stop()
    81376  {
    82377    unset($this->UpdateManager);
Note: See TracChangeset for help on using the changeset viewer.