Changeset 377 for trunk/Common


Ignore:
Timestamp:
Jan 20, 2012, 3:05:24 PM (14 years ago)
Author:
chronos
Message:
  • Upraveno: Testována instalace čisté databáze na základě definic modulů a jejich modelů.
  • Opraveno: Doplněny definice modelů pro FinanceMonthlyOverall a FinanceCharge.
  • Přidáno: Podpora pro nastavitelnost NULL hodnoty u vlastností modelů.
  • Opraveno: Řešení správného kaskádového načítání závislostí modulů.
Location:
trunk/Common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Global.php

    r373 r377  
    6161  $System = new System($Database);
    6262  $System->Config = &$Config;
     63  $System->Install();
    6364  $System->ReloadList();
    6465  $System->Install();
     
    375376}
    376377
    377 GlobalInit();
     378function ProcessURL()
     379{
     380  if(array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
     381    $PathString = $_SERVER['REDIRECT_QUERY_STRING'];
     382    else $PathString = '';
     383  if(substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
     384  //echo('"'.$QueryString.'"');
     385  $PathItems = explode('/', $PathString);
     386  if(strpos($_SERVER['REQUEST_URI'], '?') !== false)
     387    $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
     388    else $_SERVER['QUERY_STRING'] = '';   
     389  parse_str($_SERVER['QUERY_STRING'], $_GET);
     390  return($PathItems);
     391}
    378392
    379393?>
  • trunk/Common/Model.php

    r373 r377  
    3131  var $Properties;
    3232  var $System;
     33  var $Module;
     34  var $Installed;
    3335 
    3436  function __construct($Database, $System)
     
    3638    $this->Database = &$Database;
    3739    $this->System = &$System;
    38     $this->AddPropertyDateTime('TimeCreate');
    39     $this->AddPropertyOneToMany('UserCreate', 'User');
    40     $this->AddPropertyDateTime('TimeModify');
    41     $this->AddPropertyOneToMany('UserModify', 'User');
    42     $this->AddPropertyOneToMany('Module', 'Module');
    43   }
    44  
    45   function AddPropertyDateTime($Name)
    46   {
    47     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyDateTime);
    48   }
    49  
    50   function AddPropertyDate($Name)
    51   {
    52     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyDate);
    53   }
    54  
    55   function AddPropertyTime($Name)
    56   {
    57     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyTime);
    58   }
    59  
    60   function AddPropertyOneToMany($Name, $TargetModel)
    61   {     
    62     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyOneToMany, 'TargetModel' => $TargetModel);
    63   }
    64  
    65   function AddPropertyText($Name)
    66   {     
    67     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyText);
    68   }
    69 
    70   function AddPropertyText8($Name)
    71   {     
    72     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyText8);
    73   }
    74 
    75   function AddPropertyText16($Name)
    76   {     
    77     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyText16);
    78   }
    79 
    80   function AddPropertyText24($Name)
    81   {     
    82     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyText24);
    83   }
    84 
    85   function AddPropertyText32($Name)
    86   {     
    87     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyText32);
    88   }
    89 
    90   function AddPropertyString($Name)
    91   {     
    92     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyString);
    93   }
    94 
    95   function AddPropertyInteger($Name)
    96   {     
    97     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger);
    98   }
    99 
    100   function AddPropertyInteger8($Name)
    101   {     
    102     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger8);
    103   }
    104 
    105   function AddPropertyInteger16($Name)
    106   {     
    107     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger16);
    108   }
    109 
    110   function AddPropertyInteger24($Name)
    111   {     
    112     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger24);
    113   }
    114 
    115   function AddPropertyInteger32($Name)
    116   {     
    117     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger32);
    118   }
    119 
    120   function AddPropertyInteger64($Name)
    121   {     
    122     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger64);
    123   }
    124 
    125   function AddPropertyFloat($Name)
    126   {     
    127     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyFloat);
    128   }
    129 
    130   function AddPropertyDouble($Name)
    131   {     
    132     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyDouble);
    133   }
    134 
    135   function AddPropertyBoolean($Name)
    136   {
    137     $this->Properties[] = array('Name' => $Name, 'Type' => PropertyBoolean);
     40    $this->AddPropertyOneToMany('ItemOwnerModule', 'SystemModule', true);
     41    $this->AddPropertyDateTime('ItemTimeCreate', true);
     42    $this->AddPropertyOneToMany('ItemUserCreate', 'User', true);
     43    $this->AddPropertyDateTime('ItemTimeModify', true);
     44    $this->AddPropertyOneToMany('ItemUserModify', 'User', true);   
     45  }
     46 
     47  function AddPropertyDateTime($Name, $Null = false)
     48  {
     49    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyDateTime,
     50      'Null' => $Null);
     51  }
     52 
     53  function AddPropertyDate($Name, $Null = false)
     54  {
     55    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyDate,
     56      'Null' => $Null);
     57  }
     58 
     59  function AddPropertyTime($Name, $Null = false)
     60  {
     61    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyTime,
     62      'Null' => $Null);
     63  }
     64 
     65  function AddPropertyOneToMany($Name, $TargetModel, $Null = false)
     66  {     
     67    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyOneToMany,
     68      'TargetModel' => $TargetModel, 'Null' => $Null);
     69  }
     70 
     71  function AddPropertyText($Name, $Null = false)
     72  {     
     73    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyText,
     74      'Null' => $Null);
     75  }
     76
     77  function AddPropertyText8($Name, $Null = false)
     78  {     
     79    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyText8,
     80      'Null' => $Null);
     81  }
     82
     83  function AddPropertyText16($Name, $Null = false)
     84  {     
     85    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyText16,
     86      'Null' => $Null);
     87  }
     88
     89  function AddPropertyText24($Name, $Null = false)
     90  {     
     91    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyText24,
     92      'Null' => $Null);
     93  }
     94
     95  function AddPropertyText32($Name, $Null = false)
     96  {     
     97    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyText32,
     98      'Null' => $Null);
     99  }
     100
     101  function AddPropertyString($Name, $Null = false)
     102  {     
     103    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyString,
     104      'Null' => $Null);
     105  }
     106
     107  function AddPropertyInteger($Name, $Null = false)
     108  {     
     109    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger,
     110      'Null' => $Null);
     111  }
     112
     113  function AddPropertyInteger8($Name, $Null = false)
     114  {     
     115    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger8,
     116      'Null' => $Null);
     117  }
     118
     119  function AddPropertyInteger16($Name, $Null = false)
     120  {     
     121    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger16,
     122      'Null' => $Null);
     123  }
     124
     125  function AddPropertyInteger24($Name, $Null = false)
     126  {     
     127    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger24,
     128      'Null' => $Null);
     129  }
     130
     131  function AddPropertyInteger32($Name, $Null = false)
     132  {     
     133    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger32,
     134      'Null' => $Null);
     135  }
     136
     137  function AddPropertyInteger64($Name, $Null = false)
     138  {     
     139    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyInteger64,
     140      'Null' => $Null);
     141  }
     142
     143  function AddPropertyFloat($Name, $Null = false)
     144  {     
     145    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyFloat,
     146      'Null' => $Null);
     147  }
     148
     149  function AddPropertyDouble($Name, $Null = false)
     150  {     
     151    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyDouble,
     152      'Null' => $Null);
     153  }
     154
     155  function AddPropertyBoolean($Name, $Null = false)
     156  {
     157    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyBoolean,
     158      'Null' => $Null);
    138159  }
    139160 
    140   function AddPropertyManyToMany($TargetModel, $Relation, $ColumOwn, $ColumnTarget)
     161  function AddPropertyManyToMany($TargetModel, $Relation, $ColumnOwn, $ColumnTarget, $Null = false)
    141162  {     
    142163    $this->Properties[] = array('Type' => PropertyManyToMany,
    143       'TargetModel' => $TargetModel, 'Relation' => $Relation, 'ColumnOwn' => $ColumnOwn,
    144       'ColumnTarget' => $ColumnTarget);
     164      'TargetModel' => $TargetModel, 'Name' => $Relation, 'ColumnOwn' => $ColumnOwn,
     165      'ColumnTarget' => $ColumnTarget, 'Null' => $Null);
    145166  }
    146167 
    147168  function Install()
    148169  {
     170    if($this->Installed) return;
     171    $this->Installed = true;
    149172    $this->Database->insert('SystemModel', array('Name' => $this->Name, 'Module' => $this->Module->Id));
    150173    $this->Id = $this->Database->insert_id;
     
    156179      $this->Database->insert('SystemModelProperty', array('Name' => $Property['Name'],
    157180        'Model' => $this->Id, 'Type' => $Property['Type']));
     181      if($Property['Null']) $Null = 'NULL';
     182        else $Null = 'NOT NULL';
    158183      if($Property['Type'] == PropertyDateTime)
    159         $Query .= '`'.$Property['Name'].'` DATETIME NOT NULL,';
     184        $Query .= '`'.$Property['Name'].'` DATETIME '.$Null.',';
    160185      else if($Property['Type'] == PropertyDate)
    161         $Query .= '`'.$Property['Name'].'` DATE NOT NULL,';
     186        $Query .= '`'.$Property['Name'].'` DATE '.$Null.',';
    162187      else if($Property['Type'] == PropertyTime)
    163         $Query .= '`'.$Property['Name'].'` TIME NOT NULL,';
     188        $Query .= '`'.$Property['Name'].'` TIME '.$Null.',';
    164189      else if($Property['Type'] == PropertyString)
    165         $Query .= '`'.$Property['Name'].'` VARCHAR(255) COLLATE utf8_general_ci NOT NULL,';
     190        $Query .= '`'.$Property['Name'].'` VARCHAR(255) COLLATE utf8_general_ci '.$Null.',';
    166191      else if($Property['Type'] == PropertyText8)
    167         $Query .= '`'.$Property['Name'].'` TINYTEXT COLLATE utf8_general_ci NOT NULL,';
     192        $Query .= '`'.$Property['Name'].'` TINYTEXT COLLATE utf8_general_ci '.$Null.',';
    168193      else if($Property['Type'] == PropertyText16)
    169         $Query .= '`'.$Property['Name'].'` TEXT COLLATE utf8_general_ci NOT NULL,';
     194        $Query .= '`'.$Property['Name'].'` TEXT COLLATE utf8_general_ci '.$Null.',';
    170195      else if($Property['Type'] == PropertyText24)
    171         $Query .= '`'.$Property['Name'].'` MEDIUMTEXT COLLATE utf8_general_ci NOT NULL,';
     196        $Query .= '`'.$Property['Name'].'` MEDIUMTEXT COLLATE utf8_general_ci '.$Null.',';
    172197      else if($Property['Type'] == PropertyText32)
    173         $Query .= '`'.$Property['Name'].'` LONGTEXT COLLATE utf8_general_ci NOT NULL,';
     198        $Query .= '`'.$Property['Name'].'` LONGTEXT COLLATE utf8_general_ci '.$Null.',';
    174199      else if($Property['Type'] == PropertyInteger8)
    175         $Query .= '`'.$Property['Name'].'` TINYINT(4) NOT NULL,';
     200        $Query .= '`'.$Property['Name'].'` TINYINT(4) '.$Null.',';
    176201      else if($Property['Type'] == PropertyInteger16)
    177         $Query .= '`'.$Property['Name'].'` SMALLINT(6) NOT NULL,';
     202        $Query .= '`'.$Property['Name'].'` SMALLINT(6) '.$Null.',';
    178203      else if($Property['Type'] == PropertyInteger24)
    179         $Query .= '`'.$Property['Name'].'` MEDIUMINT(9) NOT NULL,';
     204        $Query .= '`'.$Property['Name'].'` MEDIUMINT(9) '.$Null.',';
    180205      else if($Property['Type'] == PropertyInteger32)
    181         $Query .= '`'.$Property['Name'].'` INT(11) NOT NULL,';
     206        $Query .= '`'.$Property['Name'].'` INT(11) '.$Null.',';
    182207      else if($Property['Type'] == PropertyInteger64)
    183         $Query .= '`'.$Property['Name'].'` BIGINT(20) NOT NULL,';
     208        $Query .= '`'.$Property['Name'].'` BIGINT(20) '.$Null.',';
    184209      else if($Property['Type'] == PropertyBoolean)
    185         $Query .= '`'.$Property['Name'].'` BOOLEAN NOT NULL,';
     210        $Query .= '`'.$Property['Name'].'` BOOLEAN '.$Null.',';
    186211      else if($Property['Type'] == PropertyFloat)
    187         $Query .= '`'.$Property['Name'].'` FLOAT NOT NULL,';
     212        $Query .= '`'.$Property['Name'].'` FLOAT '.$Null.',';
    188213      else if($Property['Type'] == PropertyDouble)
    189         $Query .= '`'.$Property['Name'].'` DOUBLE NOT NULL,';
     214        $Query .= '`'.$Property['Name'].'` DOUBLE '.$Null.',';
    190215      else if($Property['Type'] == PropertyOneToMany)
    191         $Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'.
     216        $Query .= '`'.$Property['Name'].'` INT(255)'.$Null.','.
    192217          'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),';
    193218      else if($Property['Type'] == PropertyManyToMany) ;
     
    195220        //$Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'.
    196221        //  'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),';
     222     
    197223    }
    198224    $Query .= 'PRIMARY KEY (`Id`)'.
     
    202228    {
    203229      if($Property['Type'] == PropertyOneToMany)
    204         $this->Database->query('ALTER TABLE `'.$this->Name.'` ADD CONSTRAINT '.
    205           '`'.$this->Name.'_ibfk_'.$Property['Name'].'` FOREIGN KEY (`'.$Property['TargetModel'].'`) REFERENCES `'.$Property['TargetModel'].'` (`Id`);');
     230      {
     231        if(!$this->Module->Models[$Property['TargetModel']]->Installed)
     232          $this->Module->Models[$Property['TargetModel']]->Install();
     233        $this->Database->query('ALTER TABLE `'.$this->Name.'` ADD FOREIGN KEY (`'.$Property['Name'].'`) REFERENCES `'.$Property['TargetModel'].'` (`Id`);');
     234      }
    206235    }
    207236  }
  • trunk/Common/Module.php

    r374 r377  
    2727  function Install()
    2828  {
     29    if($this->Installed) return;
    2930    DebugLog('Installing module '.$this->Name.'...');
     31    $this->Installed = true;
     32    foreach($this->Dependencies as $Dependency) 
     33      $this->System->Modules[$Dependency]->Install();
     34    $this->LoadModels();
    3035    foreach($this->Models as $ModelName)
    3136    {
    32       $Model = new $ModelName($this->Database, $this->System);
    33       $Model->Module = &$this;
    34       $Model->Install();
    35       unset($Model);
     37      $this->System->Models[$ModelName]->Install();
    3638    }
    3739    $this->Database->query('UPDATE SystemModule SET Installed=1 WHERE Name="'.$this->Name.'"');
     
    5254  function Init()
    5355  {
     56    if($this->Initialized) return;
    5457    $this->Initialized = true;
    5558    foreach($this->Dependencies as $Dependency) 
    56       if(!$this->System->Modules[$Dependency]->Initialized)
    57         $this->System->Modules[$Dependency]->Init();
     59      $this->System->Modules[$Dependency]->Init();
     60  }
     61 
     62  function LoadModels()
     63  {
     64    foreach($this->Models as $ModelName)
     65    {
     66      $this->System->Models[$ModelName] = new $ModelName($this->Database, $this->System);
     67      $this->System->Models[$ModelName]->Module = &$this;
     68    }       
    5869  }
    5970}
     
    7586  }
    7687
    77   function Init($Installed = true)
     88  function LoadModules($Installed = true)
    7889  {
    7990    $Query = 'SELECT `Id`, `Name` FROM `SystemModule`';
     
    8899      $this->Modules[$Module['Name']]->Id = $Module['Id'];
    89100    }     
     101  }
     102 
     103  function Init()
     104  {
    90105    foreach($this->Modules as $Index => $Module)
    91106      $this->Modules[$Index]->Init();
     
    103118  `Installed` int(11) NOT NULL,
    104119  `Description` text COLLATE utf8_czech_ci NOT NULL,
    105   `Dependecies` varchar(255) COLLATE utf8_czech_ci NOT NULL,
     120  `Dependencies` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    106121  PRIMARY KEY (`Id`)
    107122) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
     
    122137) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    123138    $this->ReloadList();
    124     $this->Init(false);
     139    $this->LoadModules(false);
    125140    foreach($this->Modules as $Index => $Module)
    126141    {
Note: See TracChangeset for help on using the changeset viewer.