Changeset 897 for trunk


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.
Location:
trunk
Files:
2 added
12 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Application/Core.php

    r896 r897  
    140140    RegisterFormClasses($this->FormManager);
    141141
    142     $this->ModuleManager->Start();
     142    $this->StartModules();
     143  }
     144
     145  function StartModules(): void
     146  {
     147    $ModuleSetup = $this->ModuleManager->LoadModule(dirname(__FILE__).'/Modules/Setup.php');
     148    $ModuleSetup->Install();
     149    $ModuleSetup->Start();
     150    $this->ModuleManager->LoadModules();
     151    $this->ModuleManager->LoadModule(dirname(__FILE__).'/Modules/ModuleManager.php');
     152    if (file_exists($this->ModuleManager->FileName)) $this->ModuleManager->LoadState();
     153    $this->ModuleManager->StartAll(array(ModuleCondition::Enabled));
    143154  }
    144155
  • trunk/Application/DefaultConfig.php

    r887 r897  
    1212        array('Name' => 'Database/User', 'Type' => 'String', 'Default' => 'root', 'Title' => 'Uživatel'),
    1313        array('Name' => 'Database/Password', 'Type' => 'Password', 'Default' => '', 'Title' => 'Heslo'),
    14         array('Name' => 'Database/Database', 'Type' => 'String', 'Default' => 'centrala', 'Title' => 'Databáze'),
     14        array('Name' => 'Database/Database', 'Type' => 'String', 'Default' => 'dbhost', 'Title' => 'Databáze'),
    1515        array('Name' => 'Database/Prefix', 'Type' => 'String', 'Default' => '', 'Title' => 'Prefix'),
    1616        array('Name' => 'Database/Charset', 'Type' => 'String', 'Default' => 'utf8', 'Title' => 'Znaková sada'),
  • trunk/Common/Form/Form.php

    r887 r897  
    450450    if (!array_key_exists('SQL', $Class) and ($Class['Table'] != ''))
    451451    {
    452       $DbResult = $this->Database->query('SELECT * FROM information_schema.tables  WHERE table_schema = "centrala_big"
    453           AND table_name = "'.$Class['Table'].'" LIMIT 1');
    454       if ($DbResult->num_rows == 0) continue;
     452      if (!$this->Database->TableExists($Class['Table'])) continue;
    455453
    456454      echo($Class['Table'].'<br>');
  • trunk/Modules/Config/Config.php

    r895 r897  
    1313    $this->Dependencies = array('System');
    1414    $this->Revision = 1;
    15     $this->SystemModule = true;
     15    $this->Type = ModuleType::System;
    1616  }
    1717
  • trunk/Modules/NetworkConfigLinux/Generators/DNS.php

    r887 r897  
    160160    $TTL = 86400;
    161161    $BaseDir = '/var/cache/bind';
    162     //$BaseDir = '/home/chronos/Projekty/centrala/trunk/var/named';
    163162    if (!file_exists($BaseDir)) die('Base directory "'.$BaseDir.'" not exists.');
    164163    $MailServer = 'centrala';
  • trunk/Modules/Subject/Subject.php

    r895 r897  
    127127      'Filter' => '1',
    128128    ));
    129     ModuleIS::Cast($this->System->GetModule('IS'))->RegisterDashboardItem('Subject',
     129    ModuleIS::Cast(Core::Cast($this->System)->GetModule('IS'))->RegisterDashboardItem('Subject',
    130130      array($this, 'ShowDashboardItem'));
    131131  }
  • trunk/Modules/System/System.php

    r896 r897  
    22
    33include_once(dirname(__FILE__).'/SystemModels.php');
    4 
    5 class PageModules extends Page
    6 {
    7   function __construct(System $System)
    8   {
    9     parent::__construct($System);
    10     $this->FullTitle = 'Správa modulů';
    11     $this->ShortTitle = 'Moduly';
    12     $this->ParentClass = 'PagePortal';
    13   }
    14 
    15   function ShowList(): string
    16   {
    17     $Output = '';
    18     $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Module`');
    19     $DbRow = $DbResult->fetch_row();
    20     $PageList = GetPageList('Modules', $DbRow[0]);
    21 
    22     $Output .= $PageList['Output'];
    23     $Output .= '<table class="WideTable" style="font-size: small;">';
    24 
    25     $TableColumns = array(
    26       array('Name' => 'Name', 'Title' => 'Jméno'),
    27       array('Name' => 'Creator', 'Title' => 'Tvůrce'),
    28       array('Name' => 'Version', 'Title' => 'Verze'),
    29       array('Name' => 'License', 'Title' => 'Licence'),
    30       array('Name' => 'Installed', 'Title' => 'Instalováno'),
    31       array('Name' => 'Description', 'Title' => 'Popis'),
    32       array('Name' => 'Dependencies', 'Title' => 'Závislosti'),
    33       array('Name' => '', 'Title' => 'Akce'),
    34     );
    35     $Order = GetOrderTableHeader('Modules', $TableColumns, 'Name', 0);
    36     $Output .= $Order['Output'];
    37     $Query = 'SELECT *, (SELECT GROUP_CONCAT(`T1`.`Name` SEPARATOR ", ") FROM `ModuleLink` '.
    38         'LEFT JOIN `Module` AS `T1` ON `T1`.`Id` = `ModuleLink`.`LinkedModule` '.
    39         'WHERE `ModuleLink`.`Module` = `Module`.`Id`) AS `Dependencies` '.
    40         'FROM `Module` '.$Order['SQL'].$PageList['SQLLimit'];
    41 
    42     $DbResult = $this->Database->query($Query);
    43     while ($Module = $DbResult->fetch_assoc())
    44     {
    45       if ($Module['Dependencies'] != '') $Dependencies = $Module['Dependencies'];
    46       else $Dependencies = '&nbsp;';
    47       if ($Module['Installed'] == 1) $Installed = 'Ano';
    48       else $Installed = 'Ne';
    49       if ($Module['Installed'] == 1) $Actions = '<a href="?A=Uninstall&amp;Id='.$Module['Id'].'">Odinstalovat</a>';
    50       else $Actions = '<a href="?A=Install&amp;Id='.$Module['Id'].'">Instalovat</a>';
    51       $Output .= '<tr><td>'.$Module['Name'].'</td>'.
    52           '<td>'.$Module['Creator'].'</td>'.
    53           '<td>'.$Module['Version'].'</td>'.
    54           '<td>'.$Module['License'].'</td>'.
    55           '<td>'.$Installed.'</td>'.
    56           '<td>'.$Module['Description'].'</td>'.
    57           '<td>'.$Dependencies.'</td>'.
    58           '<td>'.$Actions.'</td></tr>';
    59     }
    60     $Output .= '</table>';
    61     $Output .= $PageList['Output'];
    62     $Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>';
    63     return $Output;
    64   }
    65 
    66   function Show(): string
    67   {
    68     $Output = '';
    69     if (array_key_exists('A', $_GET))
    70     {
    71       if ($_GET['A'] == 'SaveToDb')
    72       {
    73         $Output .= ModuleSystem::Cast($this->System->GetModule('System'))->SaveToDatabase();
    74         $Output .= $this->SystemMessage('Načtení modulů', 'Seznam modulů v databázi zaktualizován');
    75       } else
    76       if ($_GET['A'] == 'Install')
    77       {
    78         $this->System->ModuleManager->LoadModules(false);
    79         $ModuleName = $this->System->ModuleManager->SearchModuleById($_GET['Id']);
    80         if ($ModuleName != '')
    81         {
    82           $this->System->ModuleManager->GetModule($ModuleName)->Install();
    83         } else $Output .= 'Modul id '.$_GET['Id'].' nenalezen';
    84 
    85       } else
    86       if ($_GET['A'] == 'Uninstall')
    87       {
    88         $ModuleName = $this->System->ModuleManager->SearchModuleById($_GET['Id']);
    89         if ($ModuleName != '')
    90         {
    91           $this->System->ModuleManager->GetModule($ModuleName)->UnInstall();
    92         } else $Output .= 'Modul id '.$_GET['Id'].' nenalezen';
    93       } else $Output .= 'Neplatná akce';
    94     }
    95     $Output .= $this->ShowList();
    96     return $Output;
    97   }
    98 }
    994
    1005class ModuleSystem extends AppModule
     
    11116    $this->Description = 'Base system module';
    11217    $this->Dependencies = array();
    113     $this->SystemModule = true;
     18    $this->Type = ModuleType::System;
    11419  }
    11520
     
    12025  }
    12126
    122   function DoBeforeInstall(): void
    123   {
    124     $this->Manager->OnInstallModel = array($this, 'InstallModel');
    125     $this->Manager->OnUninstallModel = array($this, 'UninstallModel');
    126   }
    127 
    128   function DoAfterUninstall(): void
    129   {
    130     $this->Manager->OnInstallModel = null;
    131     $this->Manager->OnUninstallModel = null;
    132   }
    133 
    134   function DoInstall(): void
    135   {
    136     $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemVersion` (
    137   `Id` int(11) NOT NULL AUTO_INCREMENT,
    138   `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    139   `Description` datetime NOT NULL,
    140   PRIMARY KEY (`Id`)
    141 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    142     $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModule` (
    143   `Id` int(11) NOT NULL AUTO_INCREMENT,
    144   `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    145   `Creator` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    146   `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    147   `License` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    148   `Installed` int(11) NOT NULL,
    149   `Description` text COLLATE utf8_czech_ci NOT NULL,
    150   PRIMARY KEY (`Id`)
    151 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    152 
    153     $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModuleDependency` (
    154   `Id` int(11) NOT NULL AUTO_INCREMENT,
    155   `Module` int(11) NOT NULL,
    156   `DependencyModule` int(11) NOT NULL,
    157   PRIMARY KEY (`Id`),
    158   KEY (`Module`),
    159   KEY (`DependencyModule`),
    160   UNIQUE (`Module` , `DependencyModule`)
    161 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    162     $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
    163     $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_2` FOREIGN KEY ( `DependencyModule` ) REFERENCES `SystemModule` (`Id`)');
    164 
    165     $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModel` (
    166   `Id` int(11) NOT NULL AUTO_INCREMENT,
    167   `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    168   `Module` int(11) NOT NULL,
    169   KEY (`Module`),
    170   PRIMARY KEY (`Id`)
    171 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    172     $this->Database->query('ALTER TABLE `SystemModel` ADD CONSTRAINT `SystemModel_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
    173 
    174     $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModelProperty` (
    175   `Id` int(11) NOT NULL AUTO_INCREMENT,
    176   `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    177   `Type` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    178   `Model` int(11) NOT NULL,
    179   KEY (`Model`),
    180   PRIMARY KEY (`Id`)
    181 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    182     $this->Database->query('ALTER TABLE `SystemModelProperty` ADD CONSTRAINT `SystemModelProperty_ibfk_1` FOREIGN KEY ( `Model` ) REFERENCES `SystemModel` (`Id`)');
    183   }
    184 
    185   function DoUnInstall(): void
    186   {
    187     // Delete tables with reverse order
    188     $this->Database->query('ALTER TABLE `SystemModelProperty` DROP FOREIGN KEY `SystemModelProperty_ibfk_1`');
    189     $this->Database->query('DROP TABLE IF EXISTS `SystemModelProperty`');
    190     $this->Database->query('ALTER TABLE `SystemModel` DROP FOREIGN KEY `SystemModel_ibfk_1`');
    191     $this->Database->query('DROP TABLE IF EXISTS `SystemModel`');
    192     $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_1`');
    193     $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_2`');
    194     $this->Database->query('DROP TABLE IF EXISTS `SystemModuleDependency`');
    195     $this->Database->query('DROP TABLE IF EXISTS `SystemModule`');
    196     $this->Database->query('DROP TABLE IF EXISTS `SystemVersion`');
    197   }
    198 
    19927  function DoStart(): void
    20028  {
    201     $this->Manager->OnInstallModel = array($this, 'InstallModel');
    202     $this->Manager->OnUninstallModel = array($this, 'UninstallModel');
    203 
    204     Core::Cast($this->System)->RegisterPage(['module'], 'PageModules');
    20529    $this->System->FormManager->RegisterClass('Action', array(
    20630      'Title' => 'Akce',
     
    23963        'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
    24064        'Items' => array('Type' => 'TActionListType', 'Caption' => 'Položky', 'Default' => ''),
    241       ),
    242     ));
    243     $this->System->FormManager->RegisterClass('Module', array(
    244       'Title' => 'Moduly',
    245       'Table' => 'Module',
    246       'Items' => array(
    247         'Name' => array('Type' => 'String', 'Caption' => 'Systémové jméno', 'Default' => ''),
    248         'Title' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
    249         'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''),
    250         'Version' => array('Type' => 'String', 'Caption' => 'Verze', 'Default' => ''),
    251         'License' => array('Type' => 'String', 'Caption' => 'Licence', 'Default' => ''),
    252         'Creator' => array('Type' => 'String', 'Caption' => 'Tvůrce', 'Default' => ''),
    253         'HomePage' => array('Type' => 'Hyperlink', 'Caption' => 'Domovské stránky', 'Default' => ''),
    254         'Installed' => array('Type' => 'Boolean', 'Caption' => 'Instalováno', 'Default' => '', 'ReadOnly' => true),
    255         'Models' => array('Type' => 'TModelListModule', 'Caption' => 'Modely', 'Default' => ''),
    256         'Links' => array('Type' => 'TModuleLinkListModule', 'Caption' => 'Vazby', 'Default' => ''),
    257       ),
    258       'Actions' => array(
    259         array('Caption' => 'Aktualizovat z disku', 'URL' => '/module/?A=SaveToDb'),
    260       ),
    261     ));
    262     $this->System->FormManager->RegisterFormType('TModule', array(
    263       'Type' => 'Reference',
    264       'Table' => 'Module',
    265       'Id' => 'Id',
    266       'Name' => 'Title',
    267       'Filter' => '1',
    268     ));
    269     $this->System->FormManager->RegisterFormType('TModelListModule', array(
    270       'Type' => 'ManyToOne',
    271       'Table' => 'Model',
    272       'Id' => 'Id',
    273       'Ref' => 'Module',
    274       'Filter' => '1',
    275     ));
    276     $this->System->FormManager->RegisterClass('Model', array(
    277       'Title' => 'Modely',
    278       'Table' => 'Model',
    279       'Items' => array(
    280         'Name' => array('Type' => 'String', 'Caption' => 'Systémové jméno', 'Default' => ''),
    281         'Title' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
    282         'Module' => array('Type' => 'TModule', 'Caption' => 'Module', 'Default' => ''),
    283         'Query' => array('Type' => 'String', 'Caption' => 'SQL dotaz', 'Default' => ''),
    284         'DefaultSortColumn' => array('Type' => 'String', 'Caption' => 'Výchozí sloupce řazení', 'Default' => ''),
    285         'DefaultSortOrder' => array('Type' => 'Text', 'Caption' => 'Výchozí směr řazení', 'Default' => ''),
    286         'Fields' => array('Type' => 'TModelFieldListModel', 'Caption' => 'Pole', 'Default' => ''),
    287       ),
    288     ));
    289     $this->System->FormManager->RegisterFormType('TModel', array(
    290       'Type' => 'Reference',
    291       'Table' => 'Model',
    292       'Id' => 'Id',
    293       'Name' => 'Title',
    294       'Filter' => '1',
    295     ));
    296     $this->System->FormManager->RegisterFormType('TModelFieldListModel', array(
    297       'Type' => 'ManyToOne',
    298       'Table' => 'ModelField',
    299       'Id' => 'Id',
    300       'Ref' => 'Model',
    301       'Filter' => '1',
    302     ));
    303     $this->System->FormManager->RegisterClass('ModelField', array(
    304       'Title' => 'Pole modelu',
    305       'Table' => 'ModelField',
    306       'Items' => array(
    307         'Name' => array('Type' => 'String', 'Caption' => 'Systémové jméno', 'Default' => ''),
    308         'Title' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
    309         'Model' => array('Type' => 'TModel', 'Caption' => 'Model', 'Default' => ''),
    310         'Query' => array('Type' => 'String', 'Caption' => 'SQL dotaz', 'Default' => ''),
    311         'Type' => array('Type' => 'String', 'Caption' => 'Typ', 'Default' => ''),
    312         'DefaultValue' => array('Type' => 'String', 'Caption' => 'Výchozí hodnota', 'Default' => ''),
    313         'IsNull' => array('Type' => 'Boolean', 'Caption' => 'Také nulová hodnota', 'Default' => ''),
    314         'Suffix' => array('Type' => 'String', 'Caption' => 'Text za', 'Default' => ''),
    315       ),
    316     ));
    317     $this->System->FormManager->RegisterFormType('TModuleLink', array(
    318       'Type' => 'Reference',
    319       'Table' => 'ModuleLink',
    320       'Id' => 'Id',
    321       'Name' => 'Module',
    322       'Filter' => '1',
    323     ));
    324     $this->System->FormManager->RegisterFormType('TModuleLinkListModule', array(
    325       'Type' => 'ManyToOne',
    326       'Table' => 'ModuleLink',
    327       'Id' => 'Id',
    328       'Ref' => 'Module',
    329       'Filter' => '1',
    330     ));
    331     $this->System->FormManager->RegisterClass('ModuleLink', array(
    332       'Title' => 'Vazby modulu',
    333       'Table' => 'ModuleLink',
    334       'Items' => array(
    335         'Module' => array('Type' => 'TModule', 'Caption' => 'Modul', 'Default' => ''),
    336         'LinkedModule' => array('Type' => 'TModule', 'Caption' => 'Vázaný modul', 'Default' => ''),
    337         'Type' => array('Type' => 'String', 'Caption' => 'Typ vazby', 'Default' => ''),
    33865      ),
    33966    ));
     
    412139      'Filter' => '1',
    413140    ));
    414     $this->System->FormManager->RegisterFormType('TModule', array(
    415       'Type' => 'Reference',
    416       'Table' => 'Module',
    417       'Id' => 'Id',
    418       'Name' => 'Name',
    419       'Filter' => '1',
    420     ));
    421 
    422     //$this->Manager->OnModuleChange = array($this, 'ModuleChange');
    423     //$this->LoadFromDatabase();
    424   }
    425 
    426   function InstallModel(ModelDesc $ModelDesc)
    427   {
    428     $Query = "CREATE TABLE IF NOT EXISTS `".$ModelDesc->Name."` (\n";
    429     $Query .= '  `'.$ModelDesc->PrimaryKey.'` int(11) NOT NULL AUTO_INCREMENT,'."\n";
    430     foreach ($ModelDesc->Columns as $Column)
    431     {
    432       $Query .= "  `".$Column->Name."` ";
    433       if ($Column->Type == ModelColumnType::Integer) $Query .= 'int(11)';
    434       else if ($Column->Type == ModelColumnType::String) $Query .= 'varchar(255)';
    435       else if ($Column->Type == ModelColumnType::Float) $Query .= 'varchar(255)';
    436       else if ($Column->Type == ModelColumnType::Text) $Query .= 'text';
    437       else if ($Column->Type == ModelColumnType::DateTime) $Query .= 'datetime';
    438       else if ($Column->Type == ModelColumnType::Reference) $Query .= 'int(11)';
    439       else if ($Column->Type == ModelColumnType::Boolean) $Query .= 'tinyint(1)';
    440       else if ($Column->Type == ModelColumnType::Date) $Query .= 'date';
    441       else if ($Column->Type == ModelColumnType::BigInt) $Query .= 'bigint(20)';
    442       else if ($Column->Type == ModelColumnType::Enum)
    443       {
    444         $Query .= 'enum("'.implode('", "', $Column->States).'")';
    445       }
    446 
    447       if ($Column->Nullable) $Query .= '';
    448         else $Query .= ' NOT NULL';
    449 
    450       $Query .= ' COLLATE utf8_general_ci';
    451 
    452       if ($Column->HasDefault)
    453       {
    454         if ($Column->Default == null)
    455           $Query .= ' DEFAULT NULL';
    456         else $Query .= ' DEFAULT '.$Column->GetDefault();
    457       }
    458       $Query .= ",\n";
    459     }
    460     $Query .= '  PRIMARY KEY (`'.$ModelDesc->PrimaryKey.'`)';
    461     foreach ($ModelDesc->Columns as $Column)
    462     {
    463       if ($Column->Type == ModelColumnType::Reference)
    464         $Query .= ','."\n".'  KEY `'.$Column->Name.'` (`'.$Column->Name.'`)';
    465       else if ($Column->Unique)
    466         $Query .= ','."\n".'  UNIQUE KEY `'.$Column->Name.'` (`'.$Column->Name.'`)';
    467     }
    468     $Query .= "\n";
    469 
    470     if ($ModelDesc->Memory) $Engine = 'MEMORY';
    471       else $Engine = 'InnoDB';
    472     $Query .= ') ENGINE='.$Engine.' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;';
    473     $I = 1;
    474     foreach ($ModelDesc->Columns as $Column)
    475     {
    476       if ($Column->Type == ModelColumnType::Reference)
    477         $Query .= "ALTER TABLE `".$ModelDesc->Name."` ".
    478         "ADD CONSTRAINT `".$ModelDesc->Name."_ibfk_".$I."` FOREIGN KEY (`".$Column->Name."`) REFERENCES `".$Column->RefTable."` (`Id`);";
    479       $I++;
    480     }
    481     $this->Database->query($Query);
    482   }
    483 
    484   function UninstallModel(ModelDesc $ModelDesc)
    485   {
    486     $this->Database->query('DROP TABLE IF EXISTS `'.$ModelDesc->Name.'`');
    487   }
    488 
    489   function IsInstalled(): bool
    490   {
    491     if ($this->InstalledChecked == false)
    492     {
    493       $DbResult = $this->Database->query('SELECT table_name FROM information_schema.tables
    494 WHERE table_schema = "'.$this->Database->Database.'" AND table_name = "SystemVersion";');
    495       if ($DbResult->num_rows > 0) $this->Installed = true;
    496         else $this->Installed = false;
    497       $this->InstalledChecked = true;
    498     }
    499     return $this->Installed;
    500   }
    501 
    502   function ModuleChange($Module): void
    503   {
    504     //if ($this->IsInstalled())
    505     {
    506 
    507       if ($Module->IsInstalled()) $Installed = 1;
    508         else $Installed = 0;
    509       $this->Database->query('UPDATE `Module` SET `Installed`=1 WHERE `Name`="'.$Module->Name.'"');
    510     }
    511   }
    512 
    513   function LoadFromDatabase(): void
    514   {
    515     //DebugLog('Loading modules...');
    516     $this->Modules = array();
    517     $Query = 'SELECT `Id`, `Name`,`Installed` FROM `Module`';
    518     $DbResult = $this->Database->query($Query);
    519     while ($Module = $DbResult->fetch_array())
    520     {
    521       //echo($Module['Name'].',');
    522       include_once('Modules/'.$Module['Name'].'/'.$Module['Name'].'.php');
    523       $ModuleClassName = 'Module'.$Module['Name'];
    524       $NewModule = new $ModuleClassName($this->Database, $this->Manager);
    525       $NewModule->Id = $Module['Id'];
    526       $NewModule->Installed = $Module['Installed'];
    527       $this->Manager->RegisterModule($NewModule);
    528     }
    529   }
    530 
    531   function SaveToDatabase(): string
    532   {
    533     $Output = '';
    534     $Modules = array();
    535     $DbResult = $this->Database->query('SELECT * FROM `Module`');
    536     while ($DbRow = $DbResult->fetch_assoc())
    537     {
    538       $Modules[$DbRow['Name']] = $DbRow;
    539       if ($this->System->ModuleManager->ModulePresent($DbRow['Name']))
    540         $this->System->ModuleManager->GetModule($DbRow['Name'])->Id = $DbRow['Id'];
    541     }
    542 
    543     // Add missing
    544     foreach ($this->System->ModuleManager->Modules as $Module)
    545     {
    546       if (!array_key_exists($Module->Name, $Modules))
    547       {
    548         $this->Database->insert('Module', array('Name' => $Module->Name,
    549           'Version' => $Module->Version, 'Creator' => $Module->Creator,
    550           'HomePage' => $Module->HomePage, 'Title' => $Module->Title,
    551           'Description' => $Module->Description, 'License' => $Module->License,
    552           'Installed' => $Module->Installed));
    553         $this->System->ModuleManager->GetModule($Module->Name)->Id = $this->Database->insert_id;
    554       }
    555       else $this->Database->update('Module', 'Name = "'.$Module->Name.'"', array(
    556         'Version' => $Module->Version, 'Creator' => $Module->Creator,
    557         'HomePage' => $Module->HomePage, 'Title' => $Module->Title,
    558         'Description' => $Module->Description, 'License' => $Module->License,
    559         'Installed' => $Module->Installed));
    560     }
    561 
    562     // Remove exceeding
    563     foreach ($Modules as $Module)
    564     if (!$this->System->ModuleManager->ModulePresent($Module['Name']))
    565     {
    566       $Output .= 'Removing module '.$Module['Name'].' from list</br/>';
    567       $this->Database->query('DELETE FROM `ModuleLink` WHERE `Module` = '.$Module['Id']);
    568       $this->Database->query('DELETE FROM `ModuleLink` WHERE `LinkedModule` = '.$Module['Id']);
    569       $DbResult = $this->Database->query('SELECT Id FROM `PermissionOperation` WHERE `Module` = '.$Module['Id']);
    570       while ($DbRow = $DbResult->fetch_assoc())
    571       {
    572         $this->Database->query('DELETE FROM `PermissionGroupAssignment` WHERE `AssignedOperation` = '.$DbRow['Id']);
    573         $this->Database->query('DELETE FROM `PermissionUserAssignment` WHERE `AssignedOperation` = '.$DbRow['Id']);
    574       }
    575       $this->Database->query('DELETE FROM `PermissionOperation` WHERE `Module` = '.$Module['Id']);
    576       $this->Database->query('DELETE FROM `Model` WHERE `Module` = '.$Module['Id']);
    577       $DbResult = $this->Database->query('SELECT Id FROM `Model` WHERE `Module` = '.$Module['Id']);
    578       while ($DbRow = $DbResult->fetch_assoc())
    579         $this->Database->query('DELETE FROM `ModelField` WHERE `Model` = '.$DbRow['Id']);
    580       $this->Database->query('DELETE FROM `Module` WHERE `Id` = '.$Module['Id']);
    581     }
    582 
    583     // Reload dependencies
    584     $DbDependency = array();
    585     $DbResult = $this->Database->query('SELECT * FROM `ModuleLink`');
    586     while ($DbRow = $DbResult->fetch_assoc())
    587       $DbDependency[$DbRow['Module']][] = $DbRow['LinkedModule'];
    588 
    589     foreach ($this->System->ModuleManager->Modules as $Module)
    590     {
    591       // Add missing
    592       foreach ($Module->Dependencies as $Dependency)
    593       {
    594         if (!array_key_exists($Module->Id, $DbDependency) or
    595         !in_array($this->System->ModuleManager->GetModule($Dependency)->Id, $DbDependency[$Module->Id]))
    596         {
    597           if ($this->System->ModuleManager->ModulePresent($Dependency))
    598             $DependencyId = $this->System->ModuleManager->GetModule($Dependency)->Id;
    599             else throw new Exception('Dependent module '.$Dependency.' not found');
    600           $this->Database->insert('ModuleLink', array('Module' => $Module->Id,
    601             'LinkedModule' => $DependencyId, 'Type' => 'DependOn'));
    602         }
    603       }
    604 
    605       // Remove exceeding
    606       if (array_key_exists($Module->Id, $DbDependency))
    607       foreach ($DbDependency[$Module->Id] as $Dep)
    608       {
    609         $DepModName = $this->System->ModuleManager->SearchModuleById($Dep);
    610         if (!in_array($DepModName, $Module->Dependencies))
    611         $this->Database->query('DELETE FROM `ModuleLink` WHERE `Module` = '.
    612           $Module->Id.' AND LinkedModule='.$Dep);
    613       }
    614     }
    615     return $Output;
    616141  }
    617142
  • trunk/Modules/User/UserModel.php

    r895 r897  
    6262    $this->OnlineStateTimeout = 600; // in seconds
    6363    $this->PasswordHash = new PasswordHash();
    64     $this->User = array('Id' => null, 'Member' => null);
     64    $this->User = array('Id' => null);
    6565  }
    6666
     
    130130    {
    131131      $Query = $this->Database->select('User', '*', 'Id IS NULL');
    132       $this->User = array('Id' => null, 'Member' => null);
     132      $this->User = array('Id' => null);
    133133      $Result = USER_NOT_LOGGED;
    134134    }
  • trunk/Modules/Wiki/Wiki.php

    r895 r897  
    3030    while ($DbRow = $DbResult->fetch_assoc())
    3131    {
    32       $this->System->RegisterPage([$DbRow['NormalizedName']], 'PageWiki');
    33       $this->System->RegisterMenuItem(array(
     32      Core::Cast($this->System)->RegisterPage([$DbRow['NormalizedName']], 'PageWiki');
     33      Core::Cast($this->System)->RegisterMenuItem(array(
    3434        'Title' => $DbRow['Name'],
    3535        'Hint' => '',
    36         'Link' => $this->System->Link('/'.$DbRow['NormalizedName'].'/'),
     36        'Link' => Core::Cast($this->System)->Link('/'.$DbRow['NormalizedName'].'/'),
    3737        'Permission' => LICENCE_ANONYMOUS,
    3838        'Icon' => '',
  • 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      );
  • trunk/Packages/Common/Common.php

    r887 r897  
    1717include_once(dirname(__FILE__).'/Locale.php');
    1818include_once(dirname(__FILE__).'/Update.php');
    19 include_once(dirname(__FILE__).'/Setup.php');
    2019include_once(dirname(__FILE__).'/Table.php');
    2120include_once(dirname(__FILE__).'/Process.php');
     
    2322include_once(dirname(__FILE__).'/BigInt.php');
    2423include_once(dirname(__FILE__).'/Int128.php');
     24include_once(dirname(__FILE__).'/Modules/Setup.php');
     25include_once(dirname(__FILE__).'/Modules/ModuleManager.php');
    2526
    2627class PackageCommon
  • trunk/Packages/Common/Database.php

    r890 r897  
    4444  public bool $LogSQLQuery;
    4545  public string $LogFile;
     46  public string $Database;
    4647
    4748  function __construct()
     
    5657    $this->LogSQLQuery = false;
    5758    $this->LogFile = dirname(__FILE__).'/../../Query.log';
     59    $this->Database = '';
    5860  }
    5961
     
    6365      else if ($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host;
    6466      else $ConnectionString = '';
     67    $this->Database = $Database;
    6568    try {
    6669      $this->PDO = new PDO($ConnectionString, $User, $Password);
    67 
    6870    } catch (Exception $E)
    6971    {
     
    235237    $this->PDO->commit();
    236238  }
     239
     240  public function TableExists(string $Name): bool
     241  {
     242    $DbResult = $this->query('SELECT * FROM information_schema.tables  WHERE table_schema = "'.$this->Database.
     243    '" AND table_name = "'.$Name.'" LIMIT 1');
     244    return $DbResult->num_rows != 0;
     245  }
    237246}
    238247
  • trunk/Packages/Common/Modules/Setup.php

    r896 r897  
    11<?php
    2 
    3 class PageSetupModules extends Page
    4 {
    5   public array $YesNo;
    6 
    7   function __construct(System $System)
    8   {
    9     parent::__construct($System);
    10     $this->FullTitle = T('Modules');
    11     $this->ShortTitle = T('Modules');
    12     $this->ParentClass = 'PageSetup';
    13     $this->YesNo = array(false => T('No'), true => T('Yes'));
    14   }
    15 
    16   function Show(): string
    17   {
    18     $Output = '';
    19     if (array_key_exists('op', $_GET)) $Operation = $_GET['op'];
    20       else $Operation = '';
    21     if ($Operation == 'install')
    22     {
    23       $this->System->ModuleManager->GetModule($_GET['name'])->Install();
    24       $this->System->ModuleManager->SaveState();
    25       $Output .= 'Modul '.$_GET['name'].' instalován<br/>';
    26     } else
    27     if ($Operation == 'uninstall')
    28     {
    29       $this->System->ModuleManager->GetModule($_GET['name'])->Uninstall();
    30       $this->System->ModuleManager->SaveState();
    31       $Output .= 'Modul '.$_GET['name'].' odinstalován<br/>';
    32     } else
    33     if ($Operation == 'enable')
    34     {
    35       $this->System->ModuleManager->GetModule($_GET['name'])->Enable();
    36       $this->System->ModuleManager->SaveState();
    37       $Output .= 'Modul '.$_GET['name'].' povolen<br/>';
    38     } else
    39     if ($Operation == 'disable')
    40     {
    41       $this->System->ModuleManager->GetModule($_GET['name'])->Disable();
    42       $this->System->ModuleManager->SaveState();
    43       $Output .= 'Modul '.$_GET['name'].' zakázán<br/>';
    44     } else
    45     if ($Operation == 'upgrade')
    46     {
    47       $this->System->ModuleManager->GetModule($_GET['name'])->Upgrade();
    48       $this->System->ModuleManager->SaveState();
    49       $Output .= 'Modul '.$_GET['name'].' povýšen<br/>';
    50     }
    51     $Output .= '<h3>Správa modulů</h3>';
    52     $Output .= $this->ShowList();
    53     return $Output;
    54   }
    55 
    56   function ShowList(): string
    57   {
    58     $Output = '';
    59 
    60     $Pageing = new Paging();
    61     $Pageing->TotalCount = count($this->System->ModuleManager->Modules);
    62     $Table = new VisualTable();
    63     $Table->SetColumns(array(
    64       array('Name' => 'Name', 'Title' => 'Jméno'),
    65       array('Name' => 'Creator', 'Title' => 'Tvůrce'),
    66       array('Name' => 'Version', 'Title' => 'Verze'),
    67       array('Name' => 'License', 'Title' => 'Licence'),
    68       array('Name' => 'Installed', 'Title' => 'Instalováno'),
    69       array('Name' => 'Enabled', 'Title' => 'Povoleno'),
    70       array('Name' => 'Description', 'Title' => 'Popis'),
    71       array('Name' => 'Dependencies', 'Title' => 'Závislosti'),
    72       array('Name' => '', 'Title' => 'Akce'),
    73     ));
    74     foreach ($this->System->ModuleManager->Modules as $Module)
    75     {
    76       if (($Module->Dependencies) > 0) $Dependencies = implode(',', $Module->Dependencies);
    77        else $Dependencies = '&nbsp;';
    78       $Actions = '';
    79       if ($Module->Installed == true)
    80       {
    81         $Actions .= ' <a href="?action=modules&amp;op=uninstall&amp;name='.$Module->Name.'">Odinstalovat</a>';
    82         if ($Module->Enabled == true) $Actions .= ' <a href="?action=modules&amp;op=disable&amp;name='.$Module->Name.'">Zakázat</a>';
    83         else $Actions .= ' <a href="?action=modules&amp;op=enable&amp;name='.$Module->Name.'">Povolit</a>';
    84         if ($Module->InstalledVersion != $Module->Version) $Actions .= ' <a href="?action=modules&amp;op=upgrade&amp;name='.$Module->Name.'">Povýšit</a>';
    85       } else $Actions .= ' <a href="?action=modules&amp;op=install&amp;name='.$Module->Name.'">Instalovat</a>';
    86 
    87       $Table->Table->Cells[] = array($Module->Name,
    88         $Module->Creator, $Module->Version,
    89         $Module->License,  $this->YesNo[$Module->Installed],
    90         $this->YesNo[$Module->Enabled], $Module->Description,
    91         $Dependencies, $Actions);
    92     }
    93     $Output .= $Pageing->Show();
    94     $Output .= $Table->Show();
    95     $Output .= $Pageing->Show();
    96     //$Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>';
    97     return $Output;
    98   }
    99 }
    1002
    1013class PageSetup extends Page
     
    14850          $Output .= '<a href="?action=upgrade">'.T('Upgrade').'</a> ';
    14951        $Output .= '<a href="?action=insert_sample_data">Vložit vzorová data</a> ';
    150         $Output .= '<a href="?action=reload_modules">Obnovit seznam modulů</a> ';
     52        $Output .= '<a href="?action=reload-modules">Obnovit seznam modulů</a> ';
    15153        $Output .= '<a href="?action=uninstall">Odinstalovat</a> ';
    152         $Output .= '<a href="'.$this->System->Link('/setup/modules/').'">Správa modulů</a> ';
     54        $Output .= '<a href="'.$this->System->Link('/modules/').'">Správa modulů</a> ';
    15355        $Output .= '<a href="?action=models">Přegenerovat modely</a> ';
    15456      } else $Output .= '<a href="?action=install">Instalovat</a> ';
     
    198100          try
    199101          {
    200             $Output .= ModuleSetup::Cast($this->System->GetModule('Setup'))->Upgrade();
     102            $this->System->ModuleManager->UpgradeAll(array(ModuleCondition::System));
    201103          } catch (Exception $E)
    202104          {
     
    208110        else if ($Action == 'install')
    209111        {
    210           $Output .= '<h3>Instalace</h3>';
    211           ModuleSetup::Cast($this->System->GetModule('Setup'))->Install();
     112          $Output .= '<h3>Instalace systém</h3>';
     113          $this->System->ModuleManager->InstallAll(array(ModuleCondition::System));
    212114          $this->System->ModuleManager->LoadModules();
    213115          $this->System->ModuleManager->SaveState();
     
    217119        else if ($Action == 'uninstall')
    218120        {
    219           $Output .= '<h3>Odinstalace</h3>';
    220           ModuleSetup::Cast($this->System->GetModule('Setup'))->Uninstall();
    221           $Output .= $this->ControlPanel();
    222         }
    223         else if ($Action == 'reload_modules')
     121          $Output .= '<h3>Odinstalace vše</h3>';
     122          $this->System->ModuleManager->UninstallAll(array(ModuleCondition::System));
     123          $Output .= $this->ControlPanel();
     124        }
     125        else if ($Action == 'reload-modules')
    224126        {
    225127          $Output .= '<h3>Znovunačtení seznamu modulů</h3>';
     
    376278  {
    377279    $Output = '';
    378     if (!$this->Database->Connected()) $Output .= T('Can\'t connect to database').'<br>';
    379     else {
     280    if (!$this->Database->Connected())
     281    {
     282      $Output .= T('Can\'t connect to database.').'<br>';
     283    } else
     284    {
    380285      if (!ModuleSetup::Cast($this->System->GetModule('Setup'))->UpdateManager->IsInstalled())
    381         $Output .= T('System requires database initialization').'<br>';
    382       else
     286      {
     287        $Output .= T('System requires database initialization.').'<br>';
     288      } else
    383289      if (!ModuleSetup::Cast($this->System->GetModule('Setup'))->UpdateManager->IsUpToDate())
    384         $Output .= T('System requires database upgrade').'<br>';
    385     }
    386     $Output .= sprintf(T('Front page was not configured. Continue to %s'), '<a href="'.$this->System->Link('/setup/').'">'.T('setup').'</a>');
     290      {
     291        $Output .= T('System requires database upgrade.').'<br>';
     292      }
     293    }
     294    $Output .= sprintf(T('Front page was not configured. Continue to %s.'), '<a href="'.$this->System->Link('/setup/').'">'.T('setup').'</a>');
    387295    return $Output;
    388296  }
     
    405313    $this->Dependencies = array();
    406314    $this->Revision = 1;
    407     $this->SystemModule = true;
     315    $this->Type = ModuleType::System;
    408316
    409317    // Check database persistence structure
     
    427335    Core::Cast($this->System)->RegisterPage([''], 'PageSetupRedirect');
    428336    Core::Cast($this->System)->RegisterPage(['setup'], 'PageSetup');
    429     Core::Cast($this->System)->RegisterPage(['setup', 'modules'], 'PageSetupModules');
    430337  }
    431338
     
    435342    Core::Cast($this->System)->UnregisterPage(['']);
    436343    Core::Cast($this->System)->UnregisterPage(['setup']);
    437     Core::Cast($this->System)->UnregisterPage(['setup', 'modules']);
    438344  }
    439345
     
    442348    return $this->Database->Connected() and $this->UpdateManager->IsInstalled() and
    443349      $this->UpdateManager->IsUpToDate();
    444   }
    445 
    446   function DoInstall(): void
    447   {
    448     global $DatabaseRevision;
    449 
    450     $this->Database->query('CREATE TABLE IF NOT EXISTS `'.$this->UpdateManager->VersionTable.'` (
    451       `Id` int(11) NOT NULL AUTO_INCREMENT,
    452       `Revision` int(11) NOT NULL,
    453       PRIMARY KEY (`Id`)
    454     ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;');
    455     $this->Database->query("INSERT INTO `".$this->UpdateManager->VersionTable."` (`Id`, `Revision`) VALUES
    456       (1, ".$DatabaseRevision.");");
    457     $this->Database->query("CREATE TABLE IF NOT EXISTS `Module` (
    458       `Id` int(11) NOT NULL AUTO_INCREMENT,
    459       `Name` varchar(255) NOT NULL,
    460       `Title` varchar(255) NOT NULL,
    461       PRIMARY KEY (`Id`)
    462     ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
    463     $this->Database->query("CREATE TABLE IF NOT EXISTS `ModuleModel` (
    464       `Id` int(11) NOT NULL AUTO_INCREMENT,
    465       `Name` varchar(255) NOT NULL,
    466       `Module` int(11) NOT NULL,
    467       PRIMARY KEY (`Id`)
    468     ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
    469     $this->Database->query('ALTER TABLE `ModuleModel`
    470       ADD CONSTRAINT `ModuleModel_ibfk_1` FOREIGN KEY (`Module`) REFERENCES `Module` (`Id`);');
    471     $this->Database->query("CREATE TABLE IF NOT EXISTS `ModuleModelProperty` (
    472       `Id` int(11) NOT NULL AUTO_INCREMENT,
    473       `Name` varchar(255) NOT NULL,
    474       `Model` int(11) NOT NULL,
    475       `Type` int(11) NOT NULL,
    476       `Nullable` tinyint(1) NOT NULL,
    477       PRIMARY KEY (`Id`)
    478     ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
    479     $this->Database->query('ALTER TABLE `ModuleModelProperty`
    480       ADD CONSTRAINT `ModuleModelProperty_ibfk_1` FOREIGN KEY (`Model`) REFERENCES `ModuleModel` (`Id`);');
    481   }
    482 
    483   function DoUninstall(): void
    484   {
    485     $this->System->ModuleManager->UninstallAll();
    486     $this->Database->query('DROP TABLE `ModuleModelProperty`');
    487     $this->Database->query('DROP TABLE `ModuleModel`');
    488     $this->Database->query('DROP TABLE `Module`');
    489     $this->Database->query('DROP TABLE `'.$this->UpdateManager->VersionTable.'`');
    490   }
    491 
    492   function IsInstalled(): bool
    493   {
    494     $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->UpdateManager->VersionTable.'"');
    495     return $DbResult->num_rows > 0;
    496350  }
    497351
     
    503357    return $Output;
    504358  }
    505 
    506   function InsertSampleData(): void
    507   {
    508   }
    509359}
Note: See TracChangeset for help on using the changeset viewer.