Changeset 342
- Timestamp:
- Jan 17, 2012, 10:37:59 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Error.php
r341 r342 28 28 $Backtrace[0]['function'] = ''; 29 29 $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'] = ''; 32 32 //$First = array_shift($Backtrace); 33 33 //print_r($First); … … 57 57 //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error); 58 58 // 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 66 69 echo('</body></html>'); 67 70 } 68 71 if((E_ERROR | E_PARSE) & $Number) die(); 69 72 } -
trunk/Model.php
r341 r342 16 16 var $Properties; 17 17 18 function __construct( )18 function __construct($Database) 19 19 { 20 $this->Database = &$Database; 20 21 $this->AddPropertyDateTime('TimeCreate'); 21 22 $this->AddPropertyOneToMany('UserCreate', 'User'); … … 67 68 'Column' => $Column); 68 69 } 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 } 69 117 } 70 118 -
trunk/Modules/Module.php
r341 r342 11 11 var $Description; 12 12 var $Dependencies; 13 var $Models ;13 var $Models = array(); 14 14 var $Database; 15 15 var $Installed; … … 23 23 { 24 24 DebugLog('Installing module '.$this->Name.'...'); 25 parent::Install();26 25 foreach($this->Models as $ModelName) 27 26 { 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); 56 30 } 57 unset($Model);31 $this->Database->query('UPDATE Module SET Installed=1 WHERE Name="'.$this->Name.'"'); 58 32 } 59 33 … … 61 35 { 62 36 DebugLog('Uninstalling module '.$this->Name.'...'); 63 parent::UnInstall();64 37 foreach($this->Models as $ModelName) 65 38 { 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(); 70 41 unset($Model); 71 42 } 43 $this->Database->query('UPDATE Module SET Installed=0 WHERE Name="'.$this->Name.'"'); 72 44 } 73 45 } … … 81 53 { 82 54 $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); 84 63 while($Module = $DbResult->fetch_array()) 85 64 { 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 } 89 69 } 90 70 … … 99 79 `License` varchar(255) COLLATE utf8_czech_ci NOT NULL, 100 80 `Installed` int(11) NOT NULL, 81 `Description` text COLLATE utf8_czech_ci NOT NULL, 101 82 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) 104 87 { 105 $ Module->Install();88 $this->Modules[$Index]->Install(); 106 89 } 107 90 } … … 110 93 { 111 94 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(); 114 97 $this->Database->query('DROP TABLE IF EXISTS `Module`'); 115 98 } … … 119 102 // Load list of modules from database 120 103 $Modules = array(); 121 $DbResult = $this->Database->query('SELECT * FROM Module');104 $DbResult = $this->Database->query('SELECT * FROM `Module`'); 122 105 while($DbRow = $DbResult->fetch_assoc()) 123 106 $Modules[$DbRow['Name']] = $DbRow; … … 129 112 if(is_dir('Modules/'.$File) and ($File != '.') and ($File != '..')) 130 113 { 131 DebugLog($File.',');132 114 $ModulesOnDisk[] = $File; 133 115 } … … 153 135 // Remove missing 154 136 foreach($Modules as $Module) 155 if( $Module['Installed'] == 0)137 if(($Module['Installed'] == 0) and !in_array($Module['Name'], $ModulesOnDisk)) 156 138 { 157 DebugLog('Removing module '.$Module Name.' 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']); 159 141 } 160 142 } -
trunk/Modules/Project/Project.php
r341 r342 19 19 class ProjectComment extends Model 20 20 { 21 function __construct( )21 function __construct($Database) 22 22 { 23 parent::__construct( );23 parent::__construct($Database); 24 24 $this->Name = 'ProjectComment'; 25 25 $this->AddPropertyOneToMany('Project', 'Project'); … … 44 44 function Install() 45 45 { 46 parent::Install(); 46 47 } 47 48 function Un install()48 49 function UnInstall() 49 50 { 50 $Query = 'DROP TABLE IF EXISTS `Project`; 51 DROP TABLE IF EXISTS `ProjectComment`;'; 52 53 } 51 parent::UnInstall(); 52 } 54 53 } 55 54 -
trunk/database.php
r336 r342 44 44 else $ConnectionString = ''; 45 45 $this->PDO = new PDO($ConnectionString, $User, $Password); 46 $this->PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 46 47 } 47 48 … … 53 54 function query($Query) 54 55 { 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 61 57 { 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) 64 66 { 65 $this->Error = $this->PDO->errorInfo(); 66 $this->Error = $this->Error[2]; 67 $this->Error = $E->getMessage(); 67 68 if(($this->Error != '') and ($this->ShowSQLError == true)) 68 69 echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>'); … … 115 116 foreach($Data as $Key => $Value) 116 117 { 117 118 if(!in_array($Value, $this->Functions)) $Value = $this->PDO->quote($Value); 118 119 $Name .= ',`'.$Key.'`'; 119 120 $Values .= ','.$Value; -
trunk/global.php
r341 r342 21 21 include_once('Model.php'); 22 22 include_once('Modules/User/user.php'); 23 include_once('Modules/Project/Project.php');24 23 25 24 $PrefixMultipliers = array … … 225 224 226 225 $System->ModularSystem = new ModularSystem($Database); 227 $System->ModularSystem->ReloadList(); 226 $System->ModularSystem->Install(); 227 //$System->ModularSystem->ReloadList(); 228 $System->ModularSystem->Init(); 228 229 } 229 230
Note:
See TracChangeset
for help on using the changeset viewer.