Ignore:
Timestamp:
Jan 17, 2012, 10:37:59 AM (13 years ago)
Author:
chronos
Message:
  • Upraveno: Databáze nyní hlásí chyby dotazů přes výjimky.
  • Opraveno: Inicializace modulů.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Module.php

    r341 r342  
    1111  var $Description;
    1212  var $Dependencies;
    13   var $Models;
     13  var $Models = array();
    1414  var $Database;
    1515  var $Installed;
     
    2323  {
    2424    DebugLog('Installing module '.$this->Name.'...');
    25     parent::Install();
    2625    foreach($this->Models as $ModelName)
    2726    {
    28       $Model = new $ModelName();
    29       $Query = 'CREATE TABLE IF NOT EXISTS `'.$ModelName.'` (
    30   `Id` int(11) NOT NULL AUTO_INCREMENT,';
    31       foreach($Model->Properties as $Property)
    32       {
    33         if($Property['Type'] == PropertyDateTime)
    34           $Query .= '`'.$Property['Name'].'` DATETIME NOT NULL,';
    35         else if($Property['Type'] == PropertyString)
    36           $Query .= '`'.$Property['Name'].'` VARCHAR(255) COLLATE utf8_general_ci NOT NULL,';
    37         else if($Property['Type'] == PropertyText)
    38           $Query .= '`'.$Property['Name'].'` TEXT COLLATE utf8_general_ci NOT NULL,';
    39         else if($Property['Type'] == PropertyInteger)
    40           $Query .= '`'.$Property['Name'].'` INT(11) NOT NULL,';
    41         else if($Property['Type'] == PropertyFloat)
    42           $Query .= '`'.$Property['Name'].'` FLOAT NOT NULL,';
    43         else if($Property['Type'] == PropertyOneToMany)
    44           $Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'.
    45             'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),';
    46         else if($Property['Type'] == PropertyManyToOne)
    47           $Query .= '';
    48         else if($Property['Type'] == PropertyManyToMany)
    49           ; // Create many-to-many table
    50           //$Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'.
    51           //  'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),';
    52       }
    53       $Query .= 'PRIMARY KEY (`Id`),'.
    54         ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1 ;';         
    55       $this->Database->query($Query);
     27      $Model = new $ModelName($this->Database);
     28      $Model->Install();
     29      unset($Model);
    5630    }
    57     unset($Model);
     31    $this->Database->query('UPDATE Module SET Installed=1 WHERE Name="'.$this->Name.'"');
    5832  }
    5933 
     
    6135  {
    6236    DebugLog('Uninstalling module '.$this->Name.'...');
    63     parent::UnInstall();
    6437    foreach($this->Models as $ModelName)
    6538    {
    66       $Model = new $ModelName();
    67       if($Model['Type'] == PropertyManyToMany)
    68         ; // Delete many-to-many table
    69       $this->Database->query('DROP TABLE IF EXISTS `'.$ModelName.'`');
     39      $Model = new $ModelName($this->Database);
     40      $Model->UnInstall();
    7041      unset($Model);
    7142    }
     43    $this->Database->query('UPDATE Module SET Installed=0 WHERE Name="'.$this->Name.'"');
    7244  }
    7345}
     
    8153  {
    8254    $this->Database = &$Database;
    83     $DbResult = $this->Database->query('SELECT * FROM Module WHERE Installed=1');
     55  }
     56 
     57  function Init($Installed = true)
     58  {
     59    $Query = 'SELECT * FROM `Module`';
     60    if($Installed) $Query .= ' WHERE `Installed`=1';
     61      else $Query .= ' WHERE `Installed`=0';
     62    $DbResult = $this->Database->query($Query);
    8463    while($Module = $DbResult->fetch_array())
    8564    {
    86       include_once('Modules/'.$File.'/'.$File.'.php');
    87       $this->Modules[] = new $Module['Name']($this->Database);
    88     }
     65      include_once('Modules/'.$Module['Name'].'/'.$Module['Name'].'.php');
     66      $ModuleClassName = 'Module'.$Module['Name'];
     67      $this->Modules[$Module['Name']] = new $ModuleClassName($this->Database);
     68    }     
    8969  }
    9070 
     
    9979  `License` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    10080  `Installed` int(11) NOT NULL,
     81  `Description` text COLLATE utf8_czech_ci NOT NULL,
    10182  PRIMARY KEY (`Id`)
    102 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;');
    103     foreach($this->Modules as $Module)
     83) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
     84    $this->ReloadList();
     85    $this->Init(false);
     86    foreach($this->Modules as $Index => $Module)
    10487    {
    105       $Module->Install();
     88      $this->Modules[$Index]->Install();
    10689    }
    10790  }
     
    11093  {
    11194    DebugLog('Uninstalling modular system core...');
    112     foreach($this->Modules as $Module)
    113       $Module->UnInstall();
     95    foreach($this->Modules as $Index => $Module)
     96      $this->Modules[$Index]->UnInstall();
    11497    $this->Database->query('DROP TABLE IF EXISTS `Module`');
    11598  }
     
    119102    // Load list of modules from database
    120103    $Modules = array();
    121     $DbResult = $this->Database->query('SELECT * FROM Module');
     104    $DbResult = $this->Database->query('SELECT * FROM `Module`');
    122105    while($DbRow = $DbResult->fetch_assoc())
    123106      $Modules[$DbRow['Name']] = $DbRow;
     
    129112    if(is_dir('Modules/'.$File) and ($File != '.') and ($File != '..'))
    130113    {
    131       DebugLog($File.',');       
    132114      $ModulesOnDisk[] = $File;
    133115    }   
     
    153135    // Remove missing
    154136    foreach($Modules as $Module)
    155     if($Module['Installed'] == 0)
     137    if(($Module['Installed'] == 0) and !in_array($Module['Name'], $ModulesOnDisk))
    156138    {
    157       DebugLog('Removing module '.$ModuleName.' from list');
    158       $this->Database->query('DELETE FROM Module WHERE Id = '.$Module['Id']);
     139      DebugLog('Removing module '.$Module['Name'].' from list');
     140      $this->Database->query('DELETE FROM `Module` WHERE `Id` = '.$Module['Id']);
    159141    }
    160142  }
Note: See TracChangeset for help on using the changeset viewer.