Changeset 893


Ignore:
Timestamp:
Jan 4, 2021, 9:55:40 PM (3 years ago)
Author:
chronos
Message:
  • Modified: More work on modules models initialization.
Location:
trunk
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/API/API.php

    r890 r893  
    3333  }
    3434
    35   function DoInstall(): void
     35  function GetModels(): array
    3636  {
    37     $this->InstallModel(APIToken::GetDesc());
    38   }
    39 
    40   function DoUninstall(): void
    41   {
    42     $this->UninstallModel(APIToken::GetDesc());
     37    return array('APIToken');
    4338  }
    4439}
  • trunk/Modules/Customer/Customer.php

    r891 r893  
    191191  }
    192192
    193   static function GetModels(): array
    194   {
    195     return array(
    196       'Member',
    197       'MemberPayment',
    198       'SupportActivity',
    199       'ServiceCategory',
    200       'Service',
    201       'ServiceCustomerRel',
    202     );
     193  function GetModels(): array
     194  {
     195    return array('Member', 'MemberPayment', 'SupportActivity', 'ServiceCategory', 'Service', 'ServiceCustomerRel');
    203196  }
    204197
  • trunk/Modules/Document/Document.php

    r891 r893  
    6363      ),
    6464      //'AfterInsert' => array($this, 'AfterInsertFinanceYear'),
    65     ));   
     65    ));
    6666    $this->System->FormManager->RegisterFormType('TDocumentLine', array(
    6767      'Type' => 'Reference',
     
    7777      'Name' => 'Name',
    7878      'Filter' => '1',
    79     ));   
     79    ));
    8080  }
    8181
    82   function DoInstall(): void
     82  function GetModels(): array
    8383  {
    84     $this->InstallModel(FinanceYear::GetDesc());   
    85     $this->InstallModel(DocumentLineCode::GetDesc());
    86     $this->InstallModel(DocumentLine::GetDesc());
    87     $this->InstallModel(DocumentLineSequence::GetDesc());
    88   }
    89 
    90   function DoUninstall(): void
    91   {
    92     $this->UninstallModel(DocumentLineSequence::GetDesc());
    93     $this->UninstallModel(DocumentLine::GetDesc());
    94     $this->UninstallModel(DocumentLineCode::GetDesc());
    95     $this->UninstallModel(FinanceYear::GetDesc());   
     84    return array('FinanceYear', 'DocumentLineCode', 'DocumentLine', 'DocumentLineSequence');
    9685  }
    9786}
  • trunk/Modules/EmailQueue/EmailQueue.php

    r888 r893  
    1919}
    2020
     21class EmailQueue extends Model
     22{
     23  static function GetDesc(): ModelDesc
     24  {
     25    $Desc = new ModelDesc('EmailQueue');
     26    $Desc->AddDateTime('Time');
     27    $Desc->AddString('To');
     28    $Desc->AddString('Subject');
     29    $Desc->AddText('Content');
     30    $Desc->AddString('Headers');
     31    $Desc->AddBoolean('Archive');
     32    $Desc->AddString('From');
     33    $Desc->AddReference('AttachmentFile', 'File');
     34    return $Desc;
     35  }
     36}
     37
    2138class ModuleEmailQueue extends AppModule
    2239{
     
    3249  }
    3350
    34   function DoInstall(): void
     51  function GetModels(): array
    3552  {
    36   }
    37 
    38   function DoUninstall(): void
    39   {
     53    return array('EmailQueue');
    4054  }
    4155
     
    7286        ),
    7387    ));
    74   }
    75 
    76   function DoStop(): void
    77   {
    7888  }
    7989
  • trunk/Modules/Employee/Employee.php

    r887 r893  
    11<?php
     2
     3class Employee extends Model
     4{
     5  static function GetDesc(): ModelDesc
     6  {
     7    $Desc = new ModelDesc('Employee');
     8    $Desc->AddDateTime('Time');
     9    $Desc->AddString('To');
     10    $Desc->AddString('Subject');
     11    $Desc->AddText('Content');
     12    $Desc->AddString('Headers');
     13    $Desc->AddBoolean('Archive');
     14    $Desc->AddString('From');
     15    $Desc->AddReference('AttachmentFile', 'File');
     16    return $Desc;
     17  }
     18}
     19
     20class EmployeeSalary extends Model
     21{
     22  static function GetDesc(): ModelDesc
     23  {
     24    $Desc = new ModelDesc('EmployeeSalary');
     25    $Desc->AddDate('Date');
     26    $Desc->AddReference('Employee', 'Employee');
     27    $Desc->AddInteger('Amount');
     28    $Desc->AddReference('Contract', 'Contract');
     29    return $Desc;
     30  }
     31}
    232
    333class ModuleEmployee extends AppModule
     
    1141    $this->License = 'GNU/GPL';
    1242    $this->Description = 'Employee wages management';
    13     $this->Dependencies = array('User');
     43    $this->Dependencies = array('User', 'Finance');
     44  }
     45
     46  function GetModels(): array
     47  {
     48    return array('Employee', 'EmployeeSalary');
    1449  }
    1550
  • trunk/Modules/Error/Error.php

    r887 r893  
    1818    $this->ErrorHandler = new ErrorHandler();
    1919    $this->Encoding = 'utf-8';
    20   }
    21 
    22   function DoInstall(): void
    23   {
    24   }
    25 
    26   function DoUnInstall(): void
    27   {
    2820  }
    2921
  • trunk/Modules/File/File.php

    r891 r893  
    1919    $Desc->AddInteger('Size');
    2020    $Desc->AddReference('Directory', 'FileDirectory', true);
    21     $Desc->AddDateTime('Time');   
     21    $Desc->AddDateTime('Time');
    2222    return $Desc;
    2323  }
     
    192192  }
    193193
    194   function DoInstall(): void
    195   {
    196     $this->InstallModel(FileDirectory::GetDesc());
    197     $this->InstallModel(File::GetDesc());
    198   }
    199 
    200   function DoUninstall(): void
    201   {
    202     $this->UninstallModel(File::GetDesc());
    203     $this->UninstallModel(FileDirectory::GetDesc());
     194  function GetModels(): array
     195  {
     196    return array('FileDirectory', 'File');
    204197  }
    205198
  • trunk/Modules/Finance/Finance.php

    r891 r893  
    483483  }
    484484
    485   static function GetModels(): array
     485  function GetModels(): array
    486486  {
    487487    return array(
     
    503503      'Contract'
    504504    );
    505   }
    506 
    507   function DoInstall(): void
    508   {
    509     foreach (self::GetModels() as $Model)
    510     {
    511       $this->InstallModel($Model::GetDesc());
    512     }
    513   }
    514 
    515   function DoUninstall(): void
    516   {
    517     foreach (array_reverse(self::GetModels()) as $Model)
    518     {
    519       $this->UninstallModel($Model::GetDesc());
    520     }
    521505  }
    522506
  • trunk/Modules/FinanceBankAPI/FinanceBankAPI.php

    r887 r893  
    55include_once(dirname(__FILE__).'/ImportFio.php');
    66include_once(dirname(__FILE__).'/../Scheduler/Scheduler.php');
     7
     8class FinanceBankImport extends Model
     9{
     10  static function GetDesc(): ModelDesc
     11  {
     12    $Desc = new ModelDesc('FinanceBankImport');
     13    $Desc->AddReference('BankAccount', 'BankAccount');
     14    $Desc->AddDate('Time');
     15    $Desc->AddString('Identification');
     16    $Desc->AddString('AccountNumber');
     17    $Desc->AddString('BankCode');
     18    $Desc->AddString('VariableSymbol');
     19    $Desc->AddString('ConstantSymbol');
     20    $Desc->AddString('SpecificSymbol');
     21    $Desc->AddFloat('Value');
     22    $Desc->AddReference('Currency', 'Currency');
     23    $Desc->AddString('OffsetAccountName');
     24    $Desc->AddReference('FinanceOperation', 'FinanceOperation');
     25    return $Desc;
     26  }
     27}
    728
    829class ModuleFinanceBankAPI extends AppModule
     
    1940  }
    2041
    21   function DoInstall(): void
     42  function GetModels(): array
    2243  {
    23   }
    24 
    25   function DoUninstall(): void
    26   {
     44    return array('FinanceBankImport');
    2745  }
    2846
     
    6583    ModuleIS::Cast($this->System->GetModule('IS'))->RegisterDashboardItem('FinanceBankAPI',
    6684      array($this, 'ShowDashboardItem'));
    67   }
    68 
    69   function DoStop(): void
    70   {
    7185  }
    7286
  • trunk/Modules/IS/IS.php

    r888 r893  
    843843}
    844844
     845class Menu extends Model
     846{
     847  static function GetDesc(): ModelDesc
     848  {
     849    $Desc = new ModelDesc('Menu');
     850    $Desc->AddString('Name');
     851    return $Desc;
     852  }
     853}
     854
     855class MenuItem extends Model
     856{
     857  static function GetDesc(): ModelDesc
     858  {
     859    $Desc = new ModelDesc('MenuItem');
     860    $Desc->AddString('Name');
     861    $Desc->AddReference('Parent', 'MenuItem');
     862    $Desc->AddReference('Action', 'Action');
     863    $Desc->AddReference('Menu', 'Menu');
     864    return $Desc;
     865  }
     866}
     867
     868class MenuItemFavorite extends Model
     869{
     870  static function GetDesc(): ModelDesc
     871  {
     872    $Desc = new ModelDesc('MenuItemFavorite');
     873    $Desc->AddReference('User', 'User');
     874    $Desc->AddReference('MenuItem', 'MenuItem');
     875    return $Desc;
     876  }
     877}
     878
    845879class ModuleIS extends AppModule
    846880{
     
    861895  }
    862896
    863   function DoInstall(): void
    864   {
    865   }
    866 
    867   function DoUninstall(): void
    868   {
     897  function GetModels(): array
     898  {
     899    return array('Menu', 'MenuItem', 'MenuItemFavorite');
    869900  }
    870901
     
    915946  }
    916947
    917   function DoStop(): void
    918   {
    919   }
    920 
    921948  function RegisterDashboardItem(string $Name, callable $Callback): void
    922949  {
  • trunk/Modules/News/News.php

    r891 r893  
    2828  }
    2929
    30   static function GetModels(): array
    31   {
    32     return array(
    33       'NewsCategory',
    34       'News',
    35     );
     30  function GetModels(): array
     31  {
     32    return array('NewsCategory', 'News');
    3633  }
    3734
  • trunk/Modules/Notify/Notify.php

    r891 r893  
    128128  }
    129129
    130   static function GetModels(): array
    131   {
    132     return array(
    133       'NotifyCategory',
    134       'NotifyUser',
    135     );
     130  function GetModels(): array
     131  {
     132    return array('NotifyCategory', 'NotifyUser');
    136133  }
    137134
    138135  function DoInstall(): void
    139136  {
    140     foreach (self::GetModels() as $Model)
    141     {
    142       $this->InstallModel($Model::GetDesc());
    143     }
    144 
    145137    $this->Database->query("INSERT INTO `NotifyCategory` (`Id`, `Name`, `SysName`) VALUES
    146138    (1, 'Dostupnost zařízení (ping)', 'NetworkReachability'),
     
    152144  }
    153145
    154   function DoUninstall(): void
    155   {
    156     foreach (array_reverse(self::GetModels()) as $Model)
    157     {
    158       $this->UninstallModel($Model::GetDesc());
    159     }
    160   }
    161 
    162146  function ShowLogRSS(): string
    163147  {
  • trunk/Modules/Portal/Portal.php

    r887 r893  
    1414    $this->Description = 'Community portal.';
    1515    $this->Dependencies = array('News', 'User');
    16   }
    17 
    18   function DoInstall(): void
    19   {
    20   }
    21 
    22   function DoUninstall(): void
    23   {
    2416  }
    2517
     
    4335    ));
    4436    ModuleUser::Cast($this->System->GetModule('User'))->UserPanel[] = array('PagePortal', 'UserPanel');
    45   }
    46 
    47   function DoStop(): void
    48   {
    4937  }
    5038}
  • trunk/Modules/Scheduler/Scheduler.php

    r887 r893  
    5050    $this->System->RegisterCommandLine('run-scheduler', 'Runs scheduled tasks',
    5151      array(ModuleScheduler::Cast($this->System->GetModule('Scheduler')), 'Run'));
    52   }
    53 
    54   function DoInstall(): void
    55   {
    56   }
    57 
    58   function DoUnInstall(): void
    59   {
    6052  }
    6153
  • trunk/Modules/Stock/Stock.php

    r887 r893  
    1212    $this->Description = 'Stock and products';
    1313    $this->Dependencies = array('User', 'Customer', 'Network');
     14  }
     15
     16  function GetModels(): array
     17  {
     18    return array('Product', 'StockSerialNumber', 'Stock', 'StockMoveGroup', 'StockMove', 'StockMoveItem',
     19      'StockItemHistory', 'StockMoveItemSerialRel');
    1420  }
    1521
     
    256262  }
    257263}
     264
     265class Product extends Model
     266{
     267  static function GetDesc(): ModelDesc
     268  {
     269    $Desc = new ModelDesc('Product');
     270    $Desc->AddReference('Manufacturer', 'Subject');
     271    $Desc->AddString('Code');
     272    $Desc->AddString('Name');
     273    $Desc->AddInteger('SellPrice');
     274    $Desc->AddInteger('BuyPrice');
     275    $Desc->AddInteger('VAT');
     276    $Desc->AddInteger('Consumption');
     277    $Desc->AddReference('Supplier', 'Subject');
     278    $Desc->AddReference('UnitOfMeasure', 'UnitOfMeasure');
     279    $Desc->AddInteger('StockMinCount');
     280    return $Desc;
     281  }
     282}
     283
     284class StockSerialNumber extends Model
     285{
     286  static function GetDesc(): ModelDesc
     287  {
     288    $Desc = new ModelDesc('StockSerialNumber');
     289    $Desc->AddReference('Stock', 'Stock');
     290    $Desc->AddReference('Product', 'Product');
     291    $Desc->AddDate('TimeEnlistment');
     292    $Desc->AddDate('TimeElimination');
     293    $Desc->AddInteger('SellPrice');
     294    $Desc->AddInteger('BuyPrice');
     295    $Desc->AddInteger('Amount');
     296    $Desc->AddString('SerialNumber');
     297    $Desc->AddString('RegNumber');
     298    $Desc->AddReference('Location', 'Member');
     299    $Desc->AddReference('Esemble', 'StockSerialNumber');
     300    return $Desc;
     301  }
     302}
     303
     304class Stock extends Model
     305{
     306  static function GetDesc(): ModelDesc
     307  {
     308    $Desc = new ModelDesc('Stock');
     309    $Desc->AddReference('Location', 'Member');
     310    return $Desc;
     311  }
     312}
     313
     314class StockMove extends Model
     315{
     316  static function GetDesc(): ModelDesc
     317  {
     318    $Desc = new ModelDesc('StockMove');
     319    $Desc->AddReference('Group', 'StockMoveGroup');
     320    $Desc->AddDateTime('Time');
     321    $Desc->AddReference('Stock', 'Stock');
     322    $Desc->AddReference('File', 'File');
     323    return $Desc;
     324  }
     325}
     326
     327class StockMoveItem extends Model
     328{
     329  static function GetDesc(): ModelDesc
     330  {
     331    $Desc = new ModelDesc('StockMoveItem');
     332    $Desc->AddReference('StockMove', 'StockMove');
     333    $Desc->AddReference('Product', 'Product');
     334    $Desc->AddInteger('UnitPrice');
     335    $Desc->AddInteger('Amount');
     336    return $Desc;
     337  }
     338}
     339
     340class StockMoveGroup extends Model
     341{
     342  static function GetDesc(): ModelDesc
     343  {
     344    $Desc = new ModelDesc('StockMoveGroup');
     345    $Desc->AddString('Name');
     346    $Desc->AddReference('DocumentLine', 'DocumentLine');
     347    $Desc->AddInteger('ValueSign');
     348    $Desc->AddInteger('Direction');
     349    return $Desc;
     350  }
     351}
     352
     353class StockItemHistory extends Model
     354{
     355  static function GetDesc(): ModelDesc
     356  {
     357    $Desc = new ModelDesc('StockItemHistory');
     358    $Desc->AddDateTime('Time');
     359    $Desc->AddReference('StockSerialNumber', 'StockSerialNumber');
     360    $Desc->AddText('Text');
     361    return $Desc;
     362  }
     363}
     364
     365class StockMoveItemSerialRel extends Model
     366{
     367  static function GetDesc(): ModelDesc
     368  {
     369    $Desc = new ModelDesc('StockMoveItemSerialRel');
     370    $Desc->AddReference('StockMoveItem', 'StockMoveItem');
     371    $Desc->AddReference('StockSerialNumber', 'StockSerialNumber');
     372    return $Desc;
     373  }
     374}
  • trunk/Modules/Subject/Subject.php

    r891 r893  
    131131  }
    132132
    133   function DoInstall(): void
    134   {
    135     $this->InstallModel(Country::GetDesc());
    136     $this->InstallModel(Subject::GetDesc());
    137     $this->InstallModel(ContactCategory::GetDesc());
    138     $this->InstallModel(Contact::GetDesc());
    139   }
    140 
    141   function DoUninstall(): void
    142   {
    143     $this->UninstallModel(Contact::GetDesc());
    144     $this->UninstallModel(ContactCategory::GetDesc());
    145     $this->UninstallModel(Subject::GetDesc());
    146     $this->UninstallModel(Country::GetDesc());
     133  function GetModels(): array
     134  {
     135    return array('Country', 'Subject', 'ContactCategory', 'Contact');
    147136  }
    148137
  • trunk/Modules/System/System.php

    r887 r893  
    400400  }
    401401
    402   function DoStop(): void
    403   {
    404   }
    405 
    406402  function IsInstalled(): bool
    407403  {
  • trunk/Modules/TV/TV.php

    r887 r893  
    112112  }
    113113
    114   function DoInstall(): void
     114  function GetModels(): array
    115115  {
    116   }
    117 
    118   function DoUninstall(): void
    119   {
     116    return array('TVGroup', 'TV');
    120117  }
    121118
     
    165162    ));
    166163  }
     164}
    167165
    168   function DoStop(): void
     166class TVGroup extends Model
     167{
     168  static function GetDesc(): ModelDesc
    169169  {
     170    $Desc = new ModelDesc('TVGroup');
     171    $Desc->AddString('Name');
     172    return $Desc;
    170173  }
    171174}
     175
     176class TV extends Model
     177{
     178  static function GetDesc(): ModelDesc
     179  {
     180    $Desc = new ModelDesc('TV');
     181    $Desc->AddString('Name');
     182    $Desc->AddInteger('Frequency');
     183    $Desc->AddString('Norm');
     184    $Desc->AddString('Homepage');
     185    $Desc->AddReference('Language', 'Language');
     186    $Desc->AddString('ShortName');
     187    $Desc->AddString('Stream');
     188    $Desc->AddString('StreamWeb');
     189    $Desc->AddString('SourceType');
     190    $Desc->AddReference('Category', 'TVGroup');
     191    return $Desc;
     192  }
     193}
  • trunk/Modules/Task/Task.php

    r887 r893  
    1212    $this->Description = 'Work and task management';
    1313    $this->Dependencies = array('User');
     14  }
     15
     16  function GetModels(): array
     17  {
     18    return array('TaskGroup', 'Task', 'Work');
    1419  }
    1520
     
    9398  }
    9499
    95   function DoInstall(): void
    96   {
    97   }
    98 
    99100  function ShowDashboardItem(): string
    100101  {
     
    105106  }
    106107}
     108
     109class Task extends Model
     110{
     111  static function GetDesc(): ModelDesc
     112  {
     113    $Desc = new ModelDesc('Task');
     114    $Desc->AddString('Name');
     115    $Desc->AddDate('TimeCreate');
     116    $Desc->AddDate('TimeDue');
     117    $Desc->AddDate('TimeClose');
     118    $Desc->AddEnum('Priority', array('Nízká', 'Střední', 'Vysoká'));
     119    $Desc->AddBoolean('Public');
     120    $Desc->AddInteger('Progress');
     121    $Desc->AddReference('Group', 'TaskGroup');
     122    $Desc->AddString('Description');
     123    $Desc->AddText('Conclusion');
     124    $Desc->AddReference('AssignedTo', 'User');
     125    return $Desc;
     126  }
     127}
     128
     129class TaskGroup extends Model
     130{
     131  static function GetDesc(): ModelDesc
     132  {
     133    $Desc = new ModelDesc('TaskGroup');
     134    $Desc->AddString('Name');
     135    $Desc->AddText('Description');
     136    $Desc->AddReference('Parent', 'TaskGroup');
     137    return $Desc;
     138  }
     139}
     140
     141class Work extends Model
     142{
     143  static function GetDesc(): ModelDesc
     144  {
     145    $Desc = new ModelDesc('Work');
     146    $Desc->AddString('Name');
     147    $Desc->AddText('Description');
     148    $Desc->AddDateTime('TimeStart');
     149    $Desc->AddFloat('Duration');
     150    $Desc->AddReference('User', 'User');
     151    $Desc->AddReference('Task', 'Task');
     152    return $Desc;
     153  }
     154}
  • trunk/Modules/TimeMeasure/Measure.php

    r888 r893  
    1111  public int $DivisionCount = 500;
    1212  public array $ValueTypes = array('Min', 'Avg', 'Max');
     13
     14  static function GetDesc(): ModelDesc
     15  {
     16    $Desc = new ModelDesc('Measure');
     17    $Desc->AddString('Name');
     18    $Desc->AddString('Title');
     19    $Desc->AddString('Description');
     20    $Desc->AddString('Unit');
     21    $Desc->AddBoolean('Continuity');
     22    $Desc->AddInteger('Period');
     23    $Desc->AddString('PermissionAdd');
     24    $Desc->AddString('PermissionView');
     25    $Desc->AddBoolean('Enabled');
     26    $Desc->AddString('DataType');
     27    $Desc->AddString('DataTable');
     28    return $Desc;
     29  }
    1330
    1431  function Load(int $Id): void
  • trunk/Modules/TimeMeasure/TimeMeasure.php

    r887 r893  
    1818  }
    1919
    20   function DoInstall(): void
     20  function GetModels(): array
    2121  {
    22   }
    23 
    24   function DoUnInstall(): void
    25   {
     22    return array('Measure');
    2623  }
    2724
     
    4946    ));
    5047  }
    51 
    52   function DoStop(): void
    53   {
    54   }
    5548}
  • trunk/Modules/User/User.php

    r890 r893  
    2323  }
    2424
    25   function DoInstall(): void
    26   {
    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());
    33   }
    34 
    35   function DoUninstall(): void
    36   {
    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());
     25  function GetModels(): array
     26  {
     27    return array('User', 'UserOnline', 'PermissionGroup', 'PermissionOperation', 'PermissionGroupAssignment', 'PermissionUserAssignment');
    4328  }
    4429
  • trunk/Modules/Wiki/Wiki.php

    r887 r893  
    1515  }
    1616
    17   function DoInstall(): void
    18   {
    19     parent::Install();
    20     $this->Database->Query('CREATE TABLE IF NOT EXISTS `WikiPage` (
    21     `Id` int(11) NOT NULL AUTO_INCREMENT,
    22     `Name` varchar(255) NOT NULL,
    23     `NormalizedName` varchar(255) NOT NULL,
    24     `VisibleInMenu` int(11) NOT NULL,
    25     PRIMARY KEY (`Id`),
    26     UNIQUE KEY `Name` (`Name`),
    27     KEY `VisibleInMenu` (`VisibleInMenu`)
    28 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1');
    29     $this->Database->Query('CREATE TABLE IF NOT EXISTS `WikiPageContent` (
    30     `Id` int(11) NOT NULL AUTO_INCREMENT,
    31     `Page` int(11) NOT NULL,
    32     `Time` datetime NOT NULL,
    33     `Content` text NOT NULL,
    34     `User` int(11) NOT NULL,
    35     PRIMARY KEY (`Id`),
    36     KEY `User` (`User`),
    37     KEY `Page` (`Page`)
    38 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1');
    39     $this->Database->Query('ALTER TABLE `WikiPageContent`
    40 ADD CONSTRAINT `WikiPageContent_ibfk_2` FOREIGN KEY (`Page`) REFERENCES `WikiPage` (`Id`),
    41 ADD CONSTRAINT `WikiPageContent_ibfk_1` FOREIGN KEY (`User`) REFERENCES `User` (`ID`)');
    42   }
    43 
    44   function DoUnInstall(): void
    45   {
    46     $this->Database->query('DELETE TABLE `WikiPageContent`');
    47     $this->Database->query('DELETE TABLE `WikiPage`;');
     17  function GetModels(): array
     18  {
     19    return array('WikiPage', 'WikiPageContent');
    4820  }
    4921
     
    5123  {
    5224    $this->LoadPages();
    53   }
    54 
    55   function DoStop(): void
    56   {
    5725  }
    5826
     
    7139      ), 2);
    7240    }
     41  }
     42}
     43
     44class WikiPage extends Model
     45{
     46  static function GetDesc(): ModelDesc
     47  {
     48    $Desc = new ModelDesc('WikiPage');
     49    $Desc->AddString('Name');
     50    $Desc->AddString('NormalizedName');
     51    $Desc->AddBoolean('VisibleInMenu');
     52    return $Desc;
     53  }
     54}
     55
     56class WikiPageContent extends Model
     57{
     58  static function GetDesc(): ModelDesc
     59  {
     60    $Desc = new ModelDesc('WikiPageContent');
     61    $Desc->AddReference('Page', 'Page');
     62    $Desc->AddDateTime('Time');
     63    $Desc->AddText('Content');
     64    $Desc->AddReference('User', 'User');
     65    return $Desc;
    7366  }
    7467}
  • trunk/Packages/Common/AppModule.php

    r891 r893  
    7373  }
    7474
    75   static function GetModels(): array
     75  function GetModels(): array
    7676  {
    7777    return array();
     
    8484    $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotInstalled));
    8585    $this->Manager->Perform($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled));
     86    $this->InstallModels();
    8687    $this->DoInstall();
    8788    $this->Installed = true;
     
    99100    $this->Manager->Perform($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed));
    100101    $this->DoUninstall();
     102    $this->UninstallModels();
    101103  }
    102104
     
    188190  {
    189191    $this->Models[get_class($Model)] = $Model;
     192  }
     193
     194  function InstallModels(): void
     195  {
     196    foreach ($this->GetModels() as $Model)
     197    {
     198      $this->InstallModel($Model::GetDesc());
     199    }
     200  }
     201
     202  function UninstallModels(): void
     203  {
     204    foreach (array_reverse($this->GetModels()) as $Model)
     205    {
     206      $this->UninstallModel($Model::GetDesc());
     207    }
    190208  }
    191209
     
    242260        $Query .= "ALTER TABLE `".$ModelDesc->Name."` ".
    243261        "ADD CONSTRAINT `".$ModelDesc->Name."_ibfk_".$I."` FOREIGN KEY (`".$Column->Name."`) REFERENCES `".$Column->RefTable."` (`Id`);";
     262      $I++;
    244263    }
    245264    $this->Database->query($Query);
Note: See TracChangeset for help on using the changeset viewer.