Changeset 738 for trunk/Common/Setup/Update.php
- Timestamp:
- Apr 14, 2015, 10:20:16 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Setup/Update.php
r725 r738 9 9 var $Database; 10 10 var $InstallMethod; 11 11 12 12 function __construct() 13 13 { 14 15 16 17 18 14 $this->Revision = 0; 15 $this->Trace = array(); 16 $this->VersionTable = 'SystemVersion'; 17 $this->InstallMethod = 'FullInstall'; 18 $this->InsertSampleDataMethod = 'InsertSampleData'; 19 19 } 20 20 21 21 function GetDbVersion() 22 22 { 23 24 $Version = $DbResult->fetch_assoc(); 23 $DbResult = $this->Database->select($this->VersionTable, '*', 'Id=1'); 24 $Version = $DbResult->fetch_assoc(); 25 25 return($Version['Revision']); 26 26 } 27 27 28 28 function IsInstalled() 29 { 29 { 30 30 debug_backtrace(); 31 32 return($DbResult->num_rows > 0); 31 $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->VersionTable.'"'); 32 return($DbResult->num_rows > 0); 33 33 } 34 34 35 35 function IsUpToDate() 36 36 { 37 37 return($this->Revision <= $this->GetDbVersion()); 38 38 } 39 39 40 40 function Upgrade() 41 41 { 42 43 $Output = 'Počáteční revize databáze: '.$DbRevision.'<br/>';44 42 $DbRevision = $this->GetDbVersion(); 43 $Output = 'Počáteční revize databáze: '.$DbRevision.'<br/>'; 44 while($this->Revision > $DbRevision) 45 45 { 46 47 48 // Show applied SQL queries immediatelly 49 50 51 46 $TraceItem = $this->Trace[$DbRevision]; 47 $Output .= 'Aktualizace na verzi '.$TraceItem['Revision'].':<br/>'; 48 // Show applied SQL queries immediatelly 49 echo($Output); 50 $Output = ''; 51 $RevUpdate = $TraceItem['Function']; 52 52 $RevUpdate($this); 53 54 55 56 57 return($Output); 53 $DbRevision = $TraceItem['Revision']; 54 $this->Database->query('UPDATE `'.$this->VersionTable.'` SET `Revision`= '. 55 $TraceItem['Revision'].' WHERE `Id`=1'); 56 } 57 return($Output); 58 58 } 59 59 60 60 function Install() 61 { 62 $InstallMethod = $this->InstallMethod;63 64 61 { 62 $InstallMethod = $this->InstallMethod; 63 $InstallMethod($this); 64 $this->Update(); 65 65 } 66 66 67 67 function Uninstall() 68 68 { 69 69 70 70 } 71 71 72 72 function InsertSampleData() 73 { 74 $InstallMethod = $this->InsertSampleDataMethod;75 73 { 74 $InstallMethod = $this->InsertSampleDataMethod; 75 $InstallMethod($this); 76 76 } 77 77 78 78 function Execute($Query) 79 79 { 80 81 82 80 echo($Query.';<br/>'); 81 flush(); 82 return($this->Database->query($Query)); 83 83 } 84 84 }
Note:
See TracChangeset
for help on using the changeset viewer.