source: trunk/includes/Update.php@ 816

Last change on this file since 816 was 816, checked in by chronos, 10 years ago
  • Modified: Tabs converted to spaces.
  • Modified: Remove spaces from end of lines.
  • Added: Code format script.
File size: 1.5 KB
Line 
1<?php
2
3class UpdateManager
4{
5 var $Revision;
6 var $Trace;
7 var $VersionTable;
8 var $Database;
9 var $InstallMethod;
10
11 function __construct()
12 {
13 $this->Revision = 0;
14 $this->Trace = array();
15 $this->VersionTable = 'DbVersion';
16 }
17
18 function GetDbVersion()
19 {
20 $DbResult = $this->Database->select('DbVersion', '*', 'Id=1');
21 $Version = $DbResult->fetch_assoc();
22 return($Version['Revision']);
23 }
24
25 function IsInstalled()
26 {
27 $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->VersionTable.'"');
28 return($DbResult->num_rows > 0);
29 }
30
31 function IsUpToDate()
32 {
33 return($this->Revision <= $this->GetDbVersion());
34 }
35
36 function Update()
37 {
38 $DbRevision = $this->GetDbVersion();
39 $Output = 'Počáteční revize databáze: '.$DbRevision.'<br/>';
40 while($this->Revision > $DbRevision)
41 {
42 $TraceItem = $this->Trace[$DbRevision];
43 $Output .= 'Aktualizace na verzi: '.$TraceItem['Revision'].'<br/>';
44 $RevUpdate = $TraceItem['Function'];
45 $RevUpdate($this);
46 $DbRevision = $TraceItem['Revision'];
47 $this->Database->query('UPDATE `DbVersion` SET `Revision`= '.$TraceItem['Revision'].' WHERE `Id`=1');
48 }
49 return($Output);
50 }
51
52 function Install()
53 {
54 $InstallMethod = $this->InstallMethod;
55 $InstallMethod($this);
56 $this->Update();
57 }
58
59 function Uninstall()
60 {
61
62 }
63
64 function Execute($Query)
65 {
66 echo($Query.'<br/>');
67 flush();
68 return($this->Database->query($Query));
69 }
70}
Note: See TracBrowser for help on using the repository browser.