Changeset 342 for trunk


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ů.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Error.php

    r341 r342  
    2828    $Backtrace[0]['function'] = '';
    2929    $Backtrace[0]['args'] = '';
    30     $Backtrace[0]['file'] = '';
    31     $Backtrace[0]['line'] = '';
     30    if(!array_key_exists('line', $Backtrace[0])) $Backtrace[0]['line'] = '';
     31    if(!array_key_exists('file', $Backtrace[0])) $Backtrace[0]['file'] = '';
    3232    //$First = array_shift($Backtrace);
    3333    //print_r($First);
     
    5757      //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error);
    5858          // Show error message
    59           if($Config['Web']['ShowPHPError'] == true)
    60           {
    61             echo('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n".
    62       '<meta http-equiv="Content-Language" content="cs">'."\n".
    63       '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"></head><body>'."\n".
    64       'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>');
    65           echo('<pre>'.$Error.'</pre><br/>');                   // V případě ladění chybu i zobraz
     59    if($Config['Web']['ShowPHPError'] == true)
     60    {
     61      echo('<?xml version="1.0" encoding="utf-8"?>'."\n".
     62      '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.
     63      '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">'.
     64      '<head>'.
     65      '<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />'.
     66      '</head><body>'.   
     67      'Došlo k vnitřní chybě!<br /> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br /><br />'."\n");
     68      echo('<pre>'.$Error.'</pre><br />');      // V případÄ› ladÄ›nĂ­ chybu i zobraz
    6669      echo('</body></html>');
    67           }
     70    }
    6871    if((E_ERROR | E_PARSE) & $Number) die();
    6972  }
  • trunk/Model.php

    r341 r342  
    1616  var $Properties;
    1717 
    18   function __construct()
     18  function __construct($Database)
    1919  {
     20    $this->Database = &$Database;
    2021    $this->AddPropertyDateTime('TimeCreate');
    2122    $this->AddPropertyOneToMany('UserCreate', 'User');
     
    6768      'Column' => $Column);
    6869  }
     70 
     71  function Install()
     72  {
     73    $Query = 'CREATE TABLE IF NOT EXISTS `'.$this->Name.'` ('.
     74      '`Id` int(11) NOT NULL AUTO_INCREMENT,';
     75    foreach($this->Properties as $Property)
     76    {
     77      if($Property['Type'] == PropertyDateTime)
     78        $Query .= '`'.$Property['Name'].'` DATETIME NOT NULL,';
     79      else if($Property['Type'] == PropertyString)
     80        $Query .= '`'.$Property['Name'].'` VARCHAR(255) COLLATE utf8_general_ci NOT NULL,';
     81      else if($Property['Type'] == PropertyText)
     82        $Query .= '`'.$Property['Name'].'` TEXT COLLATE utf8_general_ci NOT NULL,';
     83      else if($Property['Type'] == PropertyInteger)
     84        $Query .= '`'.$Property['Name'].'` INT(11) NOT NULL,';
     85      else if($Property['Type'] == PropertyFloat)
     86        $Query .= '`'.$Property['Name'].'` FLOAT NOT NULL,';
     87      else if($Property['Type'] == PropertyOneToMany)
     88        $Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'.
     89          'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),';
     90      else if($Property['Type'] == PropertyManyToOne)
     91        $Query .= '';
     92      else if($Property['Type'] == PropertyManyToMany) ;
     93        // Create many-to-many table
     94        //$Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'.
     95        //  'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),';
     96    }
     97    $Query .= 'PRIMARY KEY (`Id`)'.
     98      ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1 ;';         
     99    $this->Database->query($Query);
     100    foreach($this->Properties as $Property)
     101    {
     102      if($Property['Type'] == PropertyOneToMany)
     103        $this->Database->query('ALTER TABLE `'.$this->Name.'` ADD CONSTRAINT '.
     104          '`'.$this->Name.'_ibfk_'.$Property['Name'].'` FOREIGN KEY (`'.$Property['TargetModel'].'`) REFERENCES `'.$Property['TargetModel'].'` (`Id`);');
     105    }
     106  }
     107   
     108  function UnInstall()
     109  {
     110    foreach($Model->Properties as $Property)
     111    {
     112      if($Property['Type'] == PropertyManyToMany)
     113        ; // Delete many-to-many table
     114    }
     115    $this->Database->query('DROP TABLE IF EXISTS `'.$this->Name.'`');
     116  }
    69117}
    70118
  • 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  }
  • trunk/Modules/Project/Project.php

    r341 r342  
    1919class ProjectComment extends Model
    2020{
    21   function __construct()
     21  function __construct($Database)
    2222  {
    23     parent::__construct();
     23    parent::__construct($Database);
    2424    $this->Name = 'ProjectComment';
    2525    $this->AddPropertyOneToMany('Project', 'Project');
     
    4444  function Install()
    4545  {
     46    parent::Install();
    4647  }
    47  
    48   function Uninstall()
     48
     49  function UnInstall()
    4950  {
    50     $Query = 'DROP TABLE IF EXISTS `Project`;
    51        DROP TABLE IF EXISTS `ProjectComment`;';
    52  
    53   }
     51    parent::UnInstall();
     52  } 
    5453}
    5554
  • trunk/database.php

    r336 r342  
    4444      else $ConnectionString = '';
    4545    $this->PDO = new PDO($ConnectionString, $User, $Password);
     46    $this->PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    4647  }
    4748 
     
    5354  function query($Query)
    5455  {
    55     $this->LastQuery = $Query;
    56     if($this->ShowSQLQuery == true)
    57       echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.'</div>'."\n");
    58     $Result = new DatabaseResult();
    59     $Result->PDOStatement = $this->PDO->query($Query);
    60     if($Result->PDOStatement)
     56    try
    6157    {
    62       $Result->num_rows = $Result->PDOStatement->rowCount();
    63     } else
     58      $this->LastQuery = $Query;
     59      if($this->ShowSQLQuery == true)
     60        echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.'</div>'."\n");
     61      $Result = new DatabaseResult();
     62      $Result->PDOStatement = $this->PDO->query($Query);
     63      if($Result->PDOStatement)
     64        $Result->num_rows = $Result->PDOStatement->rowCount();
     65    } catch(PDOException $E)
    6466    {
    65       $this->Error = $this->PDO->errorInfo();
    66       $this->Error = $this->Error[2];
     67      $this->Error = $E->getMessage();
    6768      if(($this->Error != '') and ($this->ShowSQLError == true))
    6869        echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
     
    115116    foreach($Data as $Key => $Value)
    116117    {
    117             if(!in_array($Value, $this->Functions)) $Value = $this->PDO->quote($Value);
     118      if(!in_array($Value, $this->Functions)) $Value = $this->PDO->quote($Value);
    118119      $Name .= ',`'.$Key.'`';
    119120      $Values .= ','.$Value;
  • trunk/global.php

    r341 r342  
    2121include_once('Model.php');
    2222include_once('Modules/User/user.php');
    23 include_once('Modules/Project/Project.php');
    2423 
    2524$PrefixMultipliers = array
     
    225224 
    226225  $System->ModularSystem = new ModularSystem($Database);
    227   $System->ModularSystem->ReloadList();
     226  $System->ModularSystem->Install();
     227  //$System->ModularSystem->ReloadList();
     228  $System->ModularSystem->Init();
    228229}
    229230
Note: See TracChangeset for help on using the changeset viewer.