Changeset 890 for trunk


Ignore:
Timestamp:
Dec 29, 2020, 11:11:12 PM (4 years ago)
Author:
chronos
Message:
  • Fixed: Modules dependencies evaluation.
  • Modified: Better installation/uninstallation of models in more modules.
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UpdateTrace.php

    r887 r890  
    21332133{
    21342134  $Manager->Execute('ALTER TABLE `FinanceOperation` CHANGE `Value` `Value` FLOAT NOT NULL DEFAULT "0";');
     2135  $Manager->Execute('ALTER TABLE `NetworkInterface` CHANGE `OnlineNotify` `OnlineNotify` INT(11) NOT NULL DEFAULT "0";');
    21352136}
    21362137
  • trunk/Modules/API/API.php

    r889 r890  
    2525    $this->License = 'GNU/GPL';
    2626    $this->Description = 'Remote API for support of other clients';
    27     $this->Dependencies = array();
     27    $this->Dependencies = array('User');
    2828  }
    2929
  • trunk/Modules/Customer/Customer.php

    r887 r890  
    1111    $this->License = 'GNU/GPL';
    1212    $this->Description = 'Customer management';
    13     $this->Dependencies = array('User');
     13    $this->Dependencies = array('User', 'Finance');
    1414  }
    1515
     
    191191  }
    192192
     193  function DoInstall(): void
     194  {
     195    $this->InstallModel(Member::GetDesc());
     196    $this->InstallModel(MemberPayment::GetDesc());
     197    $this->InstallModel(SupportActivity::GetDesc());
     198    $this->InstallModel(ServiceCategory::GetDesc());
     199    $this->InstallModel(Service::GetDesc());
     200    $this->InstallModel(ServiceCustomerRel::GetDesc());
     201  }
     202
     203  function Uninstall(): void
     204  {
     205    $this->UninstallModel(ServiceCustomerRel::GetDesc());
     206    $this->UninstallModel(Service::GetDesc());
     207    $this->UninstallModel(ServiceCategory::GetDesc());
     208    $this->UninstallModel(SupportActivity::GetDesc());
     209    $this->UninstallModel(MemberPayment::GetDesc());
     210    $this->UninstallModel(Member::GetDesc());
     211  }
     212
    193213  function ShowDashboardItem(): string
    194214  {
     
    203223    return $Output;
    204224  }
    205 
    206 }
     225}
     226
     227class Member extends Model
     228{
     229  static function GetDesc(): ModelDesc
     230  {
     231    $Desc = new ModelDesc('Member');
     232    $Desc->AddString('Name');
     233    $Desc->AddReference('Subject', 'Subject');
     234    $Desc->AddReference('ResponsibleUser', 'User');
     235    $Desc->AddInteger('FamilyMemberCount');
     236    $Desc->AddDate('MembershipDate');
     237    $Desc->AddInteger('MemberState');
     238    $Desc->AddInteger('GPS');
     239    $Desc->AddReference('BillingPeriod', 'FinanceBillingPerios');
     240    $Desc->AddDate('BillingPeriodLastDate');
     241    $Desc->AddBoolean('Blocked');
     242    $Desc->AddInteger('PayDay');
     243    $Desc->AddChangeAction();
     244    return $Desc;
     245  }
     246}
     247
     248class MemberPayment extends Model
     249{
     250  static function GetDesc(): ModelDesc
     251  {
     252    $Desc = new ModelDesc('MemberPayment');
     253    $Desc->AddReference('Member', 'Member');
     254    $Desc->AddFloat('MonthlyTotal');
     255    $Desc->AddFloat('MonthlyInternet');
     256    $Desc->AddFloat('MonthlyConsumption');
     257    $Desc->AddFloat('MonthlyPlus');
     258    $Desc->AddFloat('Cash');
     259    return $Desc;
     260  }
     261}
     262
     263class Service extends Model
     264{
     265  static function GetDesc(): ModelDesc
     266  {
     267    $Desc = new ModelDesc('Service');
     268    $Desc->AddString('Name');
     269    $Desc->AddReference('Category', 'ServiceCategory');
     270    $Desc->AddInteger('Price');
     271    $Desc->AddInteger('VAT');
     272    $Desc->AddChangeAction();
     273    $Desc->AddBoolean('Public');
     274    $Desc->AddInteger('InternetSpeedMax');
     275    $Desc->AddInteger('InternetSpeedMin');
     276    $Desc->AddInteger('InternetUploadAsymmetry');
     277    $Desc->AddInteger('Memory');
     278    $Desc->AddInteger('MemorySwap');
     279    $Desc->AddInteger('Storage');
     280    $Desc->AddInteger('CPUCount');
     281    return $Desc;
     282  }
     283}
     284
     285class ServiceCategory extends Model
     286{
     287  static function GetDesc(): ModelDesc
     288  {
     289    $Desc = new ModelDesc('ServiceCategory');
     290    $Desc->AddString('Name');
     291    return $Desc;
     292  }
     293}
     294
     295class SupportActivity extends Model
     296{
     297  static function GetDesc(): ModelDesc
     298  {
     299    $Desc = new ModelDesc('SupportActivity');
     300    $Desc->AddDateTime('Time');
     301    $Desc->AddString('Description');
     302    $Desc->AddReference('Customer', 'Member');
     303    $Desc->AddReference('User', 'User');
     304    return $Desc;
     305  }
     306}
     307
     308class ServiceCustomerRel extends Model
     309{
     310  static function GetDesc(): ModelDesc
     311  {
     312    $Desc = new ModelDesc('ServiceCustomerRel');
     313    $Desc->AddReference('Service', 'Service');
     314    $Desc->AddReference('Customer', 'Member');
     315    $Desc->AddChangeAction();
     316    $Desc->AddInteger('SpeedLimit');
     317    return $Desc;
     318  }
     319}
  • trunk/Modules/File/File.php

    r887 r890  
    1111    parent::__construct($System);
    1212    $this->FilesDir = '';
     13  }
     14
     15  static function GetDesc(): ModelDesc
     16  {
     17    $Desc = new ModelDesc('File');
     18    $Desc->AddString('Name');
     19    $Desc->AddInteger('Size');
     20    $Column = $Desc->AddReference('Directory', 'FileDirectory');
     21    $Column->Nullable = true;
     22    $Desc->AddDateTime('Time');   
     23    return $Desc;
    1324  }
    1425
     
    104115}
    105116
     117class FileDirectory extends Model
     118{
     119  static function GetDesc(): ModelDesc
     120  {
     121    $Desc = new ModelDesc('FileDirectory');
     122    $Desc->AddString('Name');
     123    $Column = $Desc->AddReference('Parent', 'FileDirectory');
     124    $Column->Nullable = true;
     125    return $Desc;
     126  }
     127}
     128
    106129class PageFileCheck extends Page
    107130{
     
    173196  function DoInstall(): void
    174197  {
     198    $this->InstallModel(FileDirectory::GetDesc());
     199    $this->InstallModel(File::GetDesc());
    175200  }
    176201
    177202  function DoUninstall(): void
    178203  {
     204    $this->UninstallModel(File::GetDesc());
     205    $this->UninstallModel(FileDirectory::GetDesc());
    179206  }
    180207
  • trunk/Modules/Finance/Finance.php

    r888 r890  
    277277        'Treasury' => array('Type' => 'TFinanceTreasury', 'Caption' => 'Pokladna', 'Default' => '', 'Null' => true),
    278278        'Generate' => array('Type' => 'Boolean', 'Caption' => 'Generovat', 'Default' => ''),
     279        'Balance' => array('Type' => 'Integer', 'Caption' => 'Zůstatek', 'Default' => '',
     280          'ReadOnly' => true, 'SQL' => '(SELECT SUM(`FinanceOperation2`.`Value`) FROM `FinanceOperation` AS `FinanceOperation2` WHERE `FinanceOperation2`.`Time`<`Time`)'),
    279281        'InvoiceRel' => array('Type' => 'TFinanceInvoiceOperationRelListOperation', 'Caption' => 'Zaplacené faktury', 'Default' => ''),
    280282        'InvoiceRelCount' => array('Type' => 'Integer', 'Caption' => 'Faktur',
     
    289291      ),
    290292    ));
    291 
     293   
    292294    $this->System->FormManager->RegisterClass('FinanceTreasuryIn', $this->System->FormManager->Classes['FinanceOperation']);
    293295    $this->System->FormManager->Classes['FinanceTreasuryIn']['Title'] = 'Pokladní příjmy';
     
    543545      ),
    544546    ));
     547    $this->System->FormManager->RegisterClass('FinanceBankAccountReport', array(
     548      'Title' => 'Roční výkaz operací',
     549      'Table' => 'FinanceBankAccountReport',
     550      'SQL' => 'SELECT Id, DateEnd, DateStart FROM FinanceYear',
     551      'DefaultSortColumn' => 'Id',
     552      'Items' => array(
     553        'Id' => array('Type' => 'TFinanceYear', 'Caption' => 'Rok', 'Default' => '',
     554          'ReadOnly' => true),
     555        //'Account' => array('Type' => 'TFinanceBankAccount', 'Caption' => 'Bankovní účet', 'Default' => '',
     556        //  'ReadOnly' => true),
     557        'StartBalance' => array('Type' => 'Integer', 'Caption' => 'Starý zůstatek', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     558          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     559          'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     560          'WHERE (`FinanceOperation`.`Time` <= `DateStart`) AND (`FinanceOperation`.`BankAccount` = 2))'),
     561        'EndBalance' => array('Type' => 'Integer', 'Caption' => 'Nový zůstatek', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     562          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     563          'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     564          'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) AND (`FinanceOperation`.`BankAccount` = 2))'),
     565        'Change' => array('Type' => 'Integer', 'Caption' => 'Změna', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
     566          'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
     567          'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
     568          'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
     569          'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`BankAccount` = 2))'),
     570      ),
     571      //'AfterInsert' => array($this, 'AfterInsertFinanceYear'),
     572    ));
    545573    $this->System->FormManager->RegisterFormType('TFinanceBankAccount', array(
    546574      'Type' => 'Reference',
  • trunk/Modules/User/User.php

    r887 r890  
    2525  function DoInstall(): void
    2626  {
    27     $this->Database->query("CREATE TABLE IF NOT EXISTS `User` (
    28   `Id` int(11) NOT NULL AUTO_INCREMENT,
    29   `Login` varchar(64) NOT NULL,
    30   `Name` varchar(128) NOT NULL,
    31   `Password` varchar(255) NOT NULL,
    32   `Salt` varchar(255) NOT NULL,
    33   `Email` varchar(128) NOT NULL DEFAULT '',
    34   `LastIpAddress` varchar(16) NOT NULL DEFAULT '',
    35   `LastLoginTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
    36   `RegistrationTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
    37   `Locked` tinyint(1) NOT NULL DEFAULT '0',
    38   `InitPassword` varchar(255) NOT NULL,
    39   PRIMARY KEY (`Id`),
    40   UNIQUE KEY `Name` (`Login`),
    41   UNIQUE KEY `Nick` (`Name`)
    42 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
    43     $this->Database->query("CREATE TABLE IF NOT EXISTS `UserOnline` (
    44   `Id` int(11) NOT NULL AUTO_INCREMENT,
    45   `User` int(11) DEFAULT NULL COMMENT 'User.Id',
    46   `ActivityTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
    47   `LoginTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
    48   `SessionId` varchar(255) NOT NULL DEFAULT '',
    49   `IpAddress` varchar(16) NOT NULL DEFAULT '',
    50   `HostName` varchar(255) NOT NULL DEFAULT '',
    51   `ScriptName` varchar(255) NOT NULL,
    52   `StayLogged` INT NOT NULL,
    53   `StayLoggedHash` VARCHAR(40) NOT NULL,
    54   PRIMARY KEY (`Id`),
    55   KEY `User` (`User`)
    56 ) ENGINE=MEMORY  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
    57     $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionGroup` (
    58         `Id` int(11) NOT NULL AUTO_INCREMENT,
    59         `Description` varchar(255) NOT NULL DEFAULT '',
    60         PRIMARY KEY (`Id`)
    61     ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
    62 
    63     $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionGroupAssignment` (
    64         `Id` int(11) NOT NULL AUTO_INCREMENT,
    65         `Group` int(11) NOT NULL DEFAULT '0',
    66         `AssignedGroup` int(11) DEFAULT NULL,
    67         `AssignedOperation` int(11) DEFAULT NULL,
    68         PRIMARY KEY (`Id`),
    69         KEY `Group` (`Group`),
    70         KEY `AssignedGroup` (`AssignedGroup`),
    71         KEY `AssignedOperation` (`AssignedOperation`)
    72         ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
    73 
    74     $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionOperation` (
    75             `Id` int(11) NOT NULL AUTO_INCREMENT,
    76         `Module` int(11) NOT NULL,
    77             `Operation` varchar(128) NOT NULL DEFAULT '',
    78             `Item` varchar(64) NOT NULL DEFAULT '',
    79                 `ItemId` int(11) NOT NULL DEFAULT '0',
    80                 PRIMARY KEY (`Id`),
    81                     KEY `Module` (`Module`),
    82                     KEY `Operation` (`Operation`),
    83                     KEY `Item` (`Item`),
    84                     KEY `ItemId` (`ItemId`)
    85                     ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
    86 
    87     $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionUserAssignment` (
    88                     `Id` int(11) NOT NULL AUTO_INCREMENT,
    89                     `User` int(11) DEFAULT NULL,
    90                     `AssignedGroup` int(11) DEFAULT NULL,
    91                     `AssignedOperation` int(11) DEFAULT NULL,
    92                     PRIMARY KEY (`Id`),
    93                         KEY `User` (`User`),
    94                         KEY `AssignedGroup` (`AssignedGroup`),
    95                             KEY `AssignedOperation` (`AssignedOperation`)
    96                     ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
    97 
    98     $this->Database->query("ALTER TABLE `PermissionGroupAssignment`
    99       ADD CONSTRAINT `PermissionGroupAssignment_ibfk_1` FOREIGN KEY (`Group`) REFERENCES `PermissionGroup` (`Id`),
    100       ADD CONSTRAINT `PermissionGroupAssignment_ibfk_2` FOREIGN KEY (`AssignedGroup`) REFERENCES `PermissionGroup` (`Id`),
    101       ADD CONSTRAINT `PermissionGroupAssignment_ibfk_3` FOREIGN KEY (`AssignedOperation`) REFERENCES `PermissionOperation` (`Id`);");
    102 
    103     $this->Database->query("ALTER TABLE `PermissionOperation`
    104       ADD CONSTRAINT `PermissionOperation_ibfk_1` FOREIGN KEY (`Module`) REFERENCES `Module` (`Id`);");
    105 
    106     $this->Database->query("ALTER TABLE `PermissionUserAssignment`
    107       ADD CONSTRAINT `PermissionUserAssignment_ibfk_2` FOREIGN KEY (`AssignedGroup`) REFERENCES `PermissionGroup` (`Id`),
    108       ADD CONSTRAINT `PermissionUserAssignment_ibfk_3` FOREIGN KEY (`AssignedOperation`) REFERENCES `PermissionOperation` (`Id`),
    109       ADD CONSTRAINT `PermissionUserAssignment_ibfk_4` FOREIGN KEY (`User`) REFERENCES `User` (`Id`);");
     27    $this->InstallModel(User::GetDesc());
     28    $this->InstallModel(UserOnline::GetDesc());
     29    $this->InstallModel(PermissionGroup::GetDesc());
     30    $this->InstallModel(PermissionOperation::GetDesc());
     31    $this->InstallModel(PermissionGroupAssignment::GetDesc());
     32    $this->InstallModel(PermissionUserAssignment::GetDesc());
    11033  }
    11134
    11235  function DoUninstall(): void
    11336  {
    114     $this->Database->query('DROP TABLE `PermissionUserAssignment`');
    115     $this->Database->query('DROP TABLE `PermissionGroupAssignment`');
    116     $this->Database->query('DROP TABLE `PermissionGroup`');
    117     $this->Database->query('DROP TABLE `PermissionOperation`');
    118     $this->Database->query('DROP TABLE `UserOnline`');
    119     $this->Database->query('DROP TABLE `User`');
    120   }
    121 
    122   function DoUpgrade(): void
    123   {
    124     /*
    125 
    126      if ($this->InstalledVersion == '1.0') {
    127       $this->System->Database->Query('SELECT * FROM User WHERE Id=1');
    128       $this->InstalledVersion = '1.1';
    129     }
    130     */
     37    $this->UninstallModel(PermissionUserAssignment::GetDesc());   
     38    $this->UninstallModel(PermissionGroupAssignment::GetDesc());
     39    $this->UninstallModel(PermissionOperation::GetDesc());
     40    $this->UninstallModel(PermissionGroup::GetDesc());
     41    $this->UninstallModel(UserOnline::GetDesc());       
     42    $this->UninstallModel(User::GetDesc());
    13143  }
    13244
  • trunk/Modules/User/UserModel.php

    r887 r890  
    6565  }
    6666
     67  static function GetDesc(): ModelDesc
     68  {
     69    $Desc = new ModelDesc('User');
     70    $Column = $Desc->AddString('Login');
     71    $Column->Unique = true;
     72    $Column = $Desc->AddString('Name');
     73    $Column->Unique = true;
     74    $Desc->AddString('Password');
     75    $Desc->AddString('Salt');
     76    $Desc->AddString('Email');
     77    $Desc->AddString('LastIpAddress');
     78    $Desc->AddString('LastLoginTime');
     79    $Desc->AddDateTime('RegistrationTime');
     80    $Desc->AddBoolean('Locked');
     81    $Desc->AddString('InitPassword');
     82    return $Desc;
     83  }
     84
    6785  function Check(): void
    6886  {
     
    435453  }
    436454}
     455
     456class UserOnline extends Model
     457{
     458  static function GetDesc(): ModelDesc
     459  {
     460    $Desc = new ModelDesc('UserOnline');
     461    $Desc->Memory = true;
     462    $Column = $Desc->AddReference('User', 'User');
     463    $Column->Nullable = true;   
     464    $Desc->AddDateTime('ActivityTime');
     465    $Desc->AddDateTime('LoginTime');
     466    $Desc->AddString('SessionId');
     467    $Desc->AddString('IpAddress');
     468    $Desc->AddString('HostName');
     469    $Desc->AddString('ScriptName');
     470    $Desc->AddBoolean('StayLogged');
     471    $Desc->AddString('StayLoggedHash');
     472    return $Desc;
     473  }
     474}
     475
     476class PermissionGroup extends Model
     477{
     478  static function GetDesc(): ModelDesc
     479  {
     480    $Desc = new ModelDesc('PermissionGroup');
     481    $Desc->AddString('Description');
     482    return $Desc;
     483  }
     484}
     485
     486class PermissionGroupAssignment extends Model
     487{
     488  static function GetDesc(): ModelDesc
     489  {
     490    $Desc = new ModelDesc('PermissionGroupAssignment');
     491    $Desc->AddReference('Group', 'PermissionGroup');
     492    $Column = $Desc->AddReference('AssignedGroup', 'PermissionGroup');
     493    $Column->Nullable = true;
     494    $Column = $Desc->AddReference('AssignedOperation', 'PermissionOperation');
     495    $Column->Nullable = true;
     496    return $Desc;
     497  }
     498}
     499
     500class PermissionOperation extends Model
     501{
     502  static function GetDesc(): ModelDesc
     503  {
     504    $Desc = new ModelDesc('PermissionOperation');
     505    $Desc->AddReference('Module', 'Module');
     506    $Desc->AddString('Operation');
     507    $Desc->AddString('Item');
     508    $Desc->AddInteger('ItemId');
     509    $Desc->Indices = array('Operation', 'Item', 'ItemId');
     510    return $Desc;
     511  }
     512}
     513
     514class PermissionUserAssignment extends Model
     515{
     516  static function GetDesc(): ModelDesc
     517  {
     518    $Desc = new ModelDesc('PermissionUserAssignment');
     519    $Desc->AddReference('User', 'User');
     520    $Column = $Desc->AddReference('AssignedGroup', 'PermissionGroup');
     521    $Column->Nullable = true;
     522    $Column = $Desc->AddReference('AssignedOperation', 'PermissionOperation');
     523    $Column->Nullable = true;
     524    return $Desc;
     525  }
     526}
  • trunk/Packages/Common/AppModule.php

    r889 r890  
    9090    $this->Stop();
    9191    $this->Installed = false;
    92     $List = array();
     92    $List = array();   
    9393    $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed));
    9494    $this->Manager->Perform($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed));
     
    187187  function InstallModel(ModelDesc $ModelDesc)
    188188  {
    189     $Query = 'CREATE TABLE IF NOT EXISTS `'.$ModelDesc->Name.'` ('."\n";
    190     $Query = '  `'.$ModelDesc->PrimaryKey.'` int(11) NOT NULL AUTO_INCREMENT,'."\n";
     189    $Query = "CREATE TABLE IF NOT EXISTS `".$ModelDesc->Name."` (\n";
     190    $Query .= '  `'.$ModelDesc->PrimaryKey.'` int(11) NOT NULL AUTO_INCREMENT,'."\n";
    191191    foreach ($ModelDesc->Columns as $Column)
    192192    {
     
    198198      else if ($Column->Type == ModelColumnType::DateTime) $Query .= 'datetime';
    199199      else if ($Column->Type == ModelColumnType::Reference) $Query .= 'int(11)';
     200      else if ($Column->Type == ModelColumnType::Boolean) $Query .= 'tinyint(1)';
     201      else if ($Column->Type == ModelColumnType::Date) $Query .= 'date';
     202      else if ($Column->Type == ModelColumnType::Enum)
     203      {
     204        $Query .= 'enum("'.implode('", "', $Column->States).'")';
     205      }
    200206
    201207      if ($Column->Nullable) $Query .= '';
     
    212218      $Query .= ",\n";
    213219    }
    214     $Query .= '  PRIMARY KEY (`'.$ModelDesc->PrimaryKey.'`),';
     220    $Query .= '  PRIMARY KEY (`'.$ModelDesc->PrimaryKey.'`)';
    215221    foreach ($ModelDesc->Columns as $Column)
    216222    {
    217223      if ($Column->Type == ModelColumnType::Reference)
    218         $Query .= '  KEY `'.$Column->Name.'` (`'.$Column->Name.'`)'."\n";
     224        $Query .= ','."\n".'  KEY `'.$Column->Name.'` (`'.$Column->Name.'`)';
    219225      else if ($Column->Unique)
    220         $Query .= '  UNIQUE KEY `'.$Column->Name.'` (`'.$Column->Name.'`)'."\n";
    221     }
    222 
    223     $Query .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
     226        $Query .= ','."\n".'  UNIQUE KEY `'.$Column->Name.'` (`'.$Column->Name.'`)';
     227    }
     228    $Query .= "\n";
     229
     230    if ($ModelDesc->Memory) $Engine = 'MEMORY';
     231      else $Engine = 'InnoDB';
     232    $Query .= ') ENGINE='.$Engine.' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;';
    224233    $I = 1;
    225234    foreach ($ModelDesc->Columns as $Column)
     
    229238        "ADD CONSTRAINT `".$ModelDesc->Name."_ibfk_".$I."` FOREIGN KEY (`".$Column->Name."`) REFERENCES `".$Column->RefTable."` (`Id`);";
    230239    }
     240    echo($Query);
    231241    $this->Database->query($Query);
    232242  }
     
    234244  function UninstallModel(ModelDesc $ModelDesc)
    235245  {
    236     $this->Database->query('DROP TABLE `'.$ModelDesc->Name.'`');
     246    $this->Database->query('DROP TABLE IF EXISTS `'.$ModelDesc->Name.'`');
    237247  }
    238248}
     
    289299      $DepModule = $this->Modules[$Dependency];
    290300      if (in_array(ModuleCondition::All, $Conditions) or
    291         ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or
    292         (!$Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or
    293         ($Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or
    294         (!$Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or
    295         ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or
    296         (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)))
     301        ($DepModule->Running and in_array(ModuleCondition::Running, $Conditions)) or
     302        (!$DepModule->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or
     303        ($DepModule->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or
     304        (!$DepModule->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or
     305        ($DepModule->Installed and in_array(ModuleCondition::Installed, $Conditions)) or
     306        (!$DepModule->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)))
    297307      {
    298308        array_push($List, $DepModule);
     
    308318      if (in_array($Module->Name, $RefModule->Dependencies) and
    309319          (in_array(ModuleCondition::All, $Conditions) or
    310           ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or
    311           (!$Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or
    312           ($Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or
    313           (!$Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or
    314           ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or
    315           (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions))))
     320          ($RefModule->Running and in_array(ModuleCondition::Running, $Conditions)) or
     321          (!$RefModule->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or
     322          ($RefModule->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or
     323          (!$RefModule->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or
     324          ($RefModule->Installed and in_array(ModuleCondition::Installed, $Conditions)) or
     325          (!$RefModule->Installed and in_array(ModuleCondition::NotInstalled, $Conditions))))
    316326      {
    317327        array_push($List, $RefModule);
  • trunk/Packages/Common/Base.php

    r889 r890  
    3838{
    3939  public string $Name;
    40   public bool $Nullable;
    4140  public array $Columns;
    4241  public array $Indices;
    4342  public string $PrimaryKey;
    44   public bool $Unique;
    45   public bool $HasDefault;
    46 
    47   function __construct(string $Name, bool $Nullable = false, bool $Unique = false)
     43  public bool $Memory;
     44
     45  function __construct(string $Name)
    4846  {
    4947    $this->Name = $Name;
    5048    $this->Columns = array();
    51     $this->Nullable = $Nullable;
     49    $this->Indices = array();
    5250    $this->PrimaryKey = 'Id';
    53     $this->Unique = $Unique;
     51    $this->Memory = false;
    5452  }
    5553
     
    6159  }
    6260
     61  function AddFloat(string $Name): ModelColumnFloat
     62  {
     63    $Result = new ModelColumnFloat($Name);
     64    $this->Columns[] = $Result;
     65    return $Result;
     66  }
     67
    6368  function AddInteger(string $Name): ModelColumnInteger
    6469  {
     
    7580  }
    7681
     82  function AddDate(string $Name): ModelColumnDate
     83  {
     84    $Result = new ModelColumnDate($Name);
     85    $this->Columns[] = $Result;
     86    return $Result;
     87  }
     88
     89  function AddBoolean(string $Name): ModelColumnBoolean
     90  {
     91    $Result = new ModelColumnBoolean($Name);
     92    $this->Columns[] = $Result;
     93    return $Result;
     94  }
     95
    7796  function AddReference(string $Name, string $RefTable): ModelColumnReference
    7897  {
     
    8099    $this->Columns[] = $Result;
    81100    return $Result;
     101  }
     102
     103  function AddEnum(string $Name, array $States): ModelColumnEnum
     104  {
     105    $Result = new ModelColumnEnum($Name, $States);
     106    $this->Columns[] = $Result;
     107    return $Result;
     108  }
     109
     110  function AddChangeAction(): void
     111  {
     112    $Column = $this->AddEnum('ChangeAction', array('add', 'modify', 'remove'));
     113    $Column->Nullable = true;
     114    $Column = $this->AddDateTime('ChangeTime');
     115    $Column->Nullable = true;
     116    $this->AddInteger('ChangeReplaceId');   
    82117  }
    83118}
     
    91126  const DateTime = 4;
    92127  const Reference = 5;
     128  const Boolean = 6;
     129  const Date = 7;
     130  const Enum = 8;
    93131}
    94132
     
    96134{
    97135  public string $Name;
    98   public ModelColumnType $Type;
    99   public
    100 
    101   function __construct(string $Name, int $Type)
     136  public int $Type; // ModelColumnType
     137  public bool $Nullable;
     138  public bool $Unique;
     139  public bool $HasDefault;
     140
     141  function __construct(string $Name, int $Type, bool $Nullable = false, bool $Unique = false)
    102142  {
    103143    $this->Name = $Name;
    104144    $this->Type = $Type;
     145    $this->Nullable = $Nullable;
     146    $this->Unique = $Unique;
     147    $this->HasDefault = false;
    105148  }
    106149
     
    128171}
    129172
     173class ModelColumnFloat extends ModelColumn
     174{
     175  public ?float $Default;
     176
     177  function __construct(string $Name)
     178  {
     179    parent::__construct($Name, ModelColumnType::Float);
     180    $this->HasDefault = false;
     181    $this->Default = null;
     182  }
     183
     184  function GetDefault(): ?string
     185  {
     186    return '"'.$this->Default.'"';
     187  }
     188}
     189
    130190class ModelColumnText extends ModelColumn
    131191{
     
    169229  {
    170230    parent::__construct($Name, ModelColumnType::DateTime);
     231    $this->HasDefault = false;
     232    $this->Default = null;
     233  }
     234
     235  function GetDefault(): ?string
     236  {
     237    return '"'.$this->Default.'"';
     238  }
     239}
     240
     241class ModelColumnDate extends ModelColumn
     242{
     243  public ?DateTime $Default;
     244
     245  function __construct(string $Name)
     246  {
     247    parent::__construct($Name, ModelColumnType::Date);
    171248    $this->HasDefault = false;
    172249    $this->Default = null;
     
    189266  }
    190267}
     268
     269class ModelColumnBoolean extends ModelColumn
     270{
     271  public ?bool $Default;
     272
     273  function __construct(string $Name)
     274  {
     275    parent::__construct($Name, ModelColumnType::Boolean);
     276    $this->HasDefault = false;
     277    $this->Default = null;
     278  }
     279
     280  function GetDefault(): ?string
     281  {
     282    return $this->Default;
     283  }
     284}
     285
     286class ModelColumnEnum extends ModelColumn
     287{
     288  public ?bool $Default;
     289  public array $States;
     290
     291  function __construct(string $Name, array $States)
     292  {
     293    parent::__construct($Name, ModelColumnType::Enum);
     294    $this->HasDefault = false;
     295    $this->Default = null;
     296    $this->States = $States;
     297  }
     298
     299  function GetDefault(): ?string
     300  {
     301    return $this->Default;
     302  }
     303}
  • trunk/Packages/Common/Database.php

    r888 r890  
    105105      'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n");
    106106    $Result = new DatabaseResult();
    107     $Result->PDOStatement = $this->PDO->query($Query);
    108     if ($Result->PDOStatement)
    109     {
    110       $Result->num_rows = $Result->PDOStatement->rowCount();
     107    $Statement = $this->PDO->query($Query);
     108    if ($Statement)
     109    {
     110      $Result->PDOStatement = $Statement;
     111      $Result->num_rows = $Statement->rowCount();
    111112      $this->insert_id = $this->PDO->lastInsertId();
    112113    } else
  • trunk/Packages/Common/Update.php

    r888 r890  
    1818  }
    1919
    20   function GetDbVersion(): string
     20  function GetDbVersion(): ?int
    2121  {
    2222    $DbResult = $this->Database->select($this->VersionTable, '*', 'Id=1');
Note: See TracChangeset for help on using the changeset viewer.