Changeset 590


Ignore:
Timestamp:
Nov 2, 2013, 12:10:42 AM (11 years ago)
Author:
chronos
Message:
  • Opraveno: Chování systému při čisté instalaci bez aktivních modulů.
  • Upraveno: Seznam celkových aktualiací se nyní uchovává jako metoda třídy namísto globální proměnné. Moduly se totiž vkládají ve funkci a proměnná nebyla tedy globální.
  • Přidáno: Implementace metod Install a Uninstall modulů.
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/AppModule.php

    r587 r590  
    6464  function Install()
    6565  {
     66    if($this->Installed) return;
     67    $List = array();
     68    $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotInstalled));
     69    $this->Manager->Perform($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled));
     70    $this->DoInstall();
    6671        $this->Installed = true;
    6772  }
     
    6974  function Uninstall()
    7075  {
    71         $this->Installed = false;
     76    if(!$this->Installed) return;
     77    $this->Stop();
     78    $this->Installed = false;
     79    $List = array();
     80    $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed));
     81    $this->Manager->Perform($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed));
     82    $this->DoUninstall();
     83  }
     84 
     85  function Reinstall()
     86  {
     87    $this->Uninstall();
     88    $this->Install();
    7289  }
    7390 
    7491  function Start()
    7592  {
    76     if($this->Running) return;
     93    if($this->Running) return;
     94    if(!$this->Installed) return;
    7795    $List = array();
    7896    $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotRunning));
     
    119137{
    120138  var $Modules;
     139  var $ModulesAvail;
    121140  var $System;
    122141  var $OnLoadModules;
  • trunk/Common/Database.php

    r589 r590  
    7777  function query($Query)
    7878  {
     79    if(!$this->Connected()) throw new Exception('Not connected to database');
    7980    $this->LastQuery = $Query;
    8081    if($this->ShowSQLQuery == true)
  • trunk/Common/Page.php

    r578 r590  
    1313  var $ShortTitle;
    1414  var $FullTitle;
     15  var $Encoding;
     16  var $Style;
    1517 
    1618  function __construct($System)
     
    1820    parent::__construct($System);
    1921   
    20     $this->FormatHTML = $this->System->Config['Web']['FormatHTML'];
    21     $this->ShowRuntimeInfo = $this->System->Config['Web']['ShowRuntimeInfo'];
     22    $this->FormatHTML = false;
     23    $this->ShowRuntimeInfo = false;
     24    $this->Encoding = 'utf-8';
     25    $this->Style = 'new';
     26   
     27    // TODO: Move to external code
     28    if(isset($this->System->Config['Web']['FormatHTML']))
     29      $this->FormatHTML = $this->System->Config['Web']['FormatHTML'];
     30    if(isset($this->System->Config['Web']['ShowRuntimeInfo']))
     31      $this->ShowRuntimeInfo = $this->System->Config['Web']['ShowRuntimeInfo'];
     32    if(isset($this->System->Config['Web']['Charset']))
     33      $this->Encoding = $this->System->Config['Web']['Charset'];
     34    if(isset($this->System->Config['Web']['Style']))
     35      $this->Style = $this->System->Config['Web']['Style'];
    2236  }
    2337 
     
    4862    {
    4963      $Navigation = ' &gt; <a href="'.$this->System->Link($ScriptName).'/">'.$Page->ShortTitle.'</a>'.$Navigation;
    50       
    51       if($Page->ParentClass != '')
     64     
     65      if(class_exists($Page->ParentClass))
    5266      {
    5367        $PageClass = $Page->ParentClass;
     
    6175    if(isset($this->Load)) $BodyParam .= ' onload="'.$this->Load.'"';
    6276    if(isset($this->Unload)) $BodyParam .= ' onunload="'.$this->Unload.'"';
    63     $Output = '<?xml version="1.0" encoding="'.$this->System->Config['Web']['Charset'].'"?>'."\n".
     77    $Output = '<?xml version="1.0" encoding="'.$this->Encoding.'"?>'."\n".
    6478    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.
    6579    '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">'.
    66     '<head><link rel="stylesheet" href="'.$this->System->Link('/style/').$this->System->Config['Web']['Style'].'/style.css" type="text/css" media="all" />'.
    67     '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->System->Config['Web']['Charset'].'" />'.
    68     '<script type="text/javascript" src="'.$this->System->Link('/style/').$this->System->Config['Web']['Style'].'/global.js"></script>'.
     80    '<head><link rel="stylesheet" href="'.$this->System->Link('/style/').$this->Style.'/style.css" type="text/css" media="all" />'.
     81    '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->Encoding.'" />'.
     82    '<script type="text/javascript" src="'.$this->System->Link('/style/').$this->Style.'/global.js"></script>'.
    6983    '<title>'.$this->System->Config['Web']['Title'].' - '.$Path.'</title>
    7084    </head><body'.$BodyParam.'>';
     
    7589      if($this->System->Config['Web']['UserSupport'] == 1)
    7690      {
    77         if($this->System->User->User['Id'] == null)
     91        if(isset($this->System->User) and ($this->System->User->User['Id'] == null))
    7892          $Output .= '<a href="'.$this->System->Link('/?Action=LoginForm').'">Přihlášení</a> '.
    7993            '<a href="'.$this->System->Link('/?Action=UserRegister').'">Registrace</a>';
  • trunk/Common/System.php

    r589 r590  
    2727    $this->ShowPage = true;
    2828    $this->ConfigManager = new Config();
     29    $this->RootURLFolder = $_SERVER['SCRIPT_NAME'];
     30    if(substr($this->RootURLFolder, -10, 10) == '/index.php')
     31      $this->RootURLFolder = substr($this->RootURLFolder, 0, -10);
    2932  } 
    3033 
     
    4245      $Page[$LastKey] = $Handler;
    4346    } else $this->Pages[$Path] = $Handler;
     47  }
     48 
     49  function UnregisterPage($Path)
     50  {
     51    unset($this->Pages[$Path]); 
    4452  }
    4553 
     
    129137      //$Output .= 'Nelze se připojit k databázi.';
    130138    }
    131     $this->RootURLFolder = $this->Config['Web']['RootFolder'];
    132     $this->FormManager->Root = $this->Config['Web']['RootFolder'];
     139    if(isset($this->Config['Web']['RootFolder']))
     140      $this->RootURLFolder = $this->Config['Web']['RootFolder'];
     141    $this->FormManager->Root = $this->RootURLFolder;
    133142 
    134143    $Database = $this->Database;
     
    138147    include_once(dirname(__FILE__).'/../Modules/Setup/Setup.php');
    139148    $this->ModuleManager->RegisterModule(new ModuleSetup($this));
     149    $this->ModuleManager->Modules['Setup']->Installed = true;
    140150    $this->ModuleManager->Modules['Setup']->Start();
    141151    if($this->ModuleManager->Modules['Setup']->CheckState())
    142152    {
    143153      $this->ModuleManager->LoadModules();
     154      $this->ModuleManager->Modules['Setup']->Installed = true;
    144155      $this->ModuleManager->Modules['Setup']->Start();
    145156      $this->ModuleManager->StartAll();
  • trunk/Modules/Setup/DefaultConfig.php

    r589 r590  
    88    return(array
    99    (
    10         array('Name' => 'SystemPassword', 'Type' => 'Password', 'Default' => '', 'Title' => 'Systémové heslo'),
     10        array('Name' => 'SystemPassword', 'Type' => 'PasswordEncoded', 'Default' => '', 'Title' => 'Systémové heslo'),
    1111        array('Name' => 'Database/Host', 'Type' => 'String', 'Default' => 'localhost', 'Title' => 'Server'),
    1212        array('Name' => 'Database/User', 'Type' => 'String', 'Default' => 'root', 'Title' => 'Uživatel'),
  • trunk/Modules/Setup/Setup.php

    r589 r590  
    2626          $UpdateInterface->DatabaseRevision = $DatabaseRevision;
    2727          $UpdateInterface->Config = &$Config;
    28           $UpdateInterface->Updates = &$Updates;
     28          $Updates = new Updates();
     29          $UpdateInterface->Updates = $Updates->Get();
    2930          return($UpdateInterface->Show());
    3031        }
     
    3536        function Show()
    3637        {
    37           echo('s');
    3838          $Output = '';
    3939          if(!$this->Database->Connected()) $Output .= 'Nelze se připojit k databázi.<br>';
    4040          else {
    41             if(!$this->System->ModuleManager->Modules['Setup']->UpdateManager->IsInstalled()) $Output .= 'Systém vyžaduje instalaci databáze.<br>';
    42             if(!$this->System->ModuleManager->Modules['Setup']->UpdateManager->IsUpToDate()) $Output .= 'Systém vyžaduje aktualizaci databáze.<br>';
     41            if(!$this->System->ModuleManager->Modules['Setup']->UpdateManager->IsInstalled())
     42              $Output .= 'Systém vyžaduje instalaci databáze.<br>';
     43            else
     44            if(!$this->System->ModuleManager->Modules['Setup']->UpdateManager->IsUpToDate())
     45              $Output .= 'Systém vyžaduje aktualizaci databáze.<br>';
    4346          }
    4447          $Output .= 'Pokračujte <a href="'.$this->System->Link('/setup/').'">zde</a>';
     
    7578  } 
    7679 
     80  function DoStop()
     81  {
     82    unset($this->UpdateManager);
     83    $this->System->UnregisterPage('');
     84    $this->System->UnregisterPage('setup');
     85  }
     86 
    7787  function CheckState()
    7888  {
    7989    return($this->Database->Connected() and $this->UpdateManager->IsInstalled() and
    80         $this->UpdateManager->IsUpToDate());
     90      $this->UpdateManager->IsUpToDate());
    8191  }
    8292}
  • trunk/Modules/Setup/Update.php

    r589 r590  
    4545    {
    4646            $TraceItem = $this->Trace[$DbRevision];
    47             $Output .= 'Aktualizace na verzi: '.$TraceItem['Revision'].'<br/>';     
     47            $Output .= 'Aktualizace na verzi: '.$TraceItem['Revision'].'<br/>';   
     48            echo($Output); 
    4849            $RevUpdate = $TraceItem['Function'];         
    4950            $RevUpdate($this);
     
    5859        $InstallMethod = $this->InstallMethod;
    5960        $InstallMethod($this);
     61        $this->Update();
    6062  }
    6163 
     
    8890  var $Updates;
    8991  var $Database;
     92  var $ConfigDir;
    9093 
    9194  function __construct()
    9295  {
     96    $this->ConfigDir = dirname(__FILE__).'/../..';
    9397  }
    9498 
     
    124128        $Output .= '<input type="submit" name="insert_sample_data" value="Vložit vzorová data"/> ';
    125129        $Output .= '<input type="submit" name="uninstall" value="Odinstalovat"/> ';
     130        //$Output .= $this->ShowList();
    126131      } else $Output .= '<input type="submit" name="install" value="Instalovat"/> ';
    127132    }
     
    214219  }
    215220 
     221  function ShowList()
     222  {
     223    $Output = '';
     224    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Module`');
     225    $DbRow = $DbResult->fetch_row();
     226    $PageList = GetPageList($DbRow[0]);
     227 
     228    $Output .= $PageList['Output'];
     229    $Output .= '<table class="WideTable" style="font-size: small;">';
     230     
     231    $TableColumns = array(
     232        array('Name' => 'Name', 'Title' => 'Jméno'),
     233        array('Name' => 'Creator', 'Title' => 'Tvůrce'),
     234        array('Name' => 'Version', 'Title' => 'Verze'),
     235        array('Name' => 'License', 'Title' => 'Licence'),
     236        array('Name' => 'Installed', 'Title' => 'Instalováno'),
     237        array('Name' => 'Description', 'Title' => 'Popis'),
     238        array('Name' => 'Dependencies', 'Title' => 'Závislosti'),
     239        array('Name' => '', 'Title' => 'Akce'),
     240    );
     241    $Order = GetOrderTableHeader($TableColumns, 'Name', 0);
     242    $Output .= $Order['Output'];
     243    $Query = 'SELECT *, (SELECT GROUP_CONCAT(`T1`.`Name` SEPARATOR ", ") FROM `SystemModuleDependency` '.
     244        'LEFT JOIN `SystemModule` AS `T1` ON `T1`.`Id` = `SystemModuleDependency`.`DependencyModule` '.
     245        'WHERE `SystemModuleDependency`.`Module` = `SystemModule`.`Id`) AS `Dependencies` '.
     246        'FROM `SystemModule` '.$Order['SQL'].$PageList['SQLLimit'];
     247 
     248    $DbResult = $this->Database->query($Query);
     249    while($Module = $DbResult->fetch_assoc())
     250    {
     251      if($Module['Dependencies'] != '') $Dependencies = $Module['Dependencies'];
     252      else $Dependencies = '&nbsp;';
     253      if($Module['Installed'] == 1) $Installed = 'Ano';
     254      else $Installed = 'Ne';
     255      if($Module['Installed'] == 1) $Actions = '<a href="?A=Uninstall&amp;Id='.$Module['Id'].'">Odinstalovat</a>';
     256      else $Actions = '<a href="?A=Install&amp;Id='.$Module['Id'].'">Instalovat</a>';
     257      $Output .= '<tr><td>'.$Module['Name'].'</td>'.
     258          '<td>'.$Module['Creator'].'</td>'.
     259          '<td>'.$Module['Version'].'</td>'.
     260          '<td>'.$Module['License'].'</td>'.
     261          '<td>'.$Installed.'</td>'.
     262          '<td>'.$Module['Description'].'</td>'.
     263          '<td>'.$Dependencies.'</td>'.
     264          '<td>'.$Actions.'</td></tr>';
     265    }
     266    $Output .= '</table>';
     267    $Output .= $PageList['Output'];
     268    $Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>';
     269    return($Output);
     270  }
     271 
    216272  function PrepareConfig($Config)
    217273  {
    218274    $Output = '';
    219     if(!file_exists('../config.php') and !is_writable('..'))
     275    if(!file_exists($this->ConfigDir.'/config.php') and !is_writable($this->ConfigDir))
    220276      $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože složka není povolená pro zápis!';
    221     if(file_exists('../config.php') and !is_writable('../config.php'))
     277    if(file_exists($this->ConfigDir.'/config.php') and !is_writable($this->ConfigDir.'/config.php'))
    222278      $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože soubor config.php není povolen pro zápis!';
    223279    $Output .= '<h3>Nastavení systému</h3>'.
     
    238294      if($Def['Type'] == 'String') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>';
    239295      if($Def['Type'] == 'Password') $Output .= '<input type="password" name="'.$Def['Name'].'"/>';
     296      if($Def['Type'] == 'PasswordEncoded') $Output .= '<input type="password" name="'.$Def['Name'].'"/>';
    240297      if($Def['Type'] == 'Integer') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>';
    241298      if($Def['Type'] == 'Float') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>';
     
    259316      if($Def['Type'] == 'Password') if(array_key_exists($Def['Name'], $_POST) and ($_POST[$Def['Name']] != ''))
    260317        $Value = $_POST[$Def['Name']];
     318      if($Def['Type'] == 'PasswordEncoded') if(array_key_exists($Def['Name'], $_POST) and ($_POST[$Def['Name']] != ''))
     319        $Value = sha1($_POST[$Def['Name']]);
    261320      if($Def['Type'] == 'Integer') if(array_key_exists($Def['Name'], $_POST))
    262321        $Value = $_POST[$Def['Name']];
     
    278337      }
    279338    $ConfigText = $this->CreateConfig($Config);
    280     file_put_contents('../config.php', $ConfigText);
     339    file_put_contents($this->ConfigDir.'/config.php', $ConfigText);
    281340    $Output .= 'Konfigurace nastavena<br/>';
    282341    return($Output);
  • trunk/Modules/Setup/Updates.php

    r589 r590  
    441441}
    442442
    443 
    444 $Updates = array(
     443class Updates
     444{
     445  function Get()
     446  {
     447    return($Updates = array(
    445448  491 => array('Revision' => 493, 'Function' => 'UpdateTo493'),
    446449  493 => array('Revision' => 494, 'Function' => 'UpdateTo494'),
     
    465468  571 => array('Revision' => 574, 'Function' => 'UpdateTo574'),
    466469  574 => array('Revision' => 584, 'Function' => 'UpdateTo584'),
    467 );
     470));
     471    }
     472}
Note: See TracChangeset for help on using the changeset viewer.