Last change
on this file was 17, checked in by chronos, 8 years ago |
- Modified: Old database class replaced by newer from Common package to fix compatibility with PHP7.
|
File size:
1.8 KB
|
Line | |
---|
1 | <?php
|
---|
2 |
|
---|
3 | class UpdateManager
|
---|
4 | {
|
---|
5 | var $Revision;
|
---|
6 | var $Trace;
|
---|
7 | var $VersionTable;
|
---|
8 | /* @var Database */
|
---|
9 | var $Database;
|
---|
10 | var $InstallMethod;
|
---|
11 |
|
---|
12 | function __construct()
|
---|
13 | {
|
---|
14 | $this->Revision = 0;
|
---|
15 | $this->Trace = array();
|
---|
16 | $this->VersionTable = 'SystemVersion';
|
---|
17 | $this->InstallMethod = 'FullInstall';
|
---|
18 | $this->InsertSampleDataMethod = 'InsertSampleData';
|
---|
19 | }
|
---|
20 |
|
---|
21 | function GetDbVersion()
|
---|
22 | {
|
---|
23 | $DbResult = $this->Database->select($this->VersionTable, '*', 'Id=1');
|
---|
24 | $Version = $DbResult->fetch_assoc();
|
---|
25 | return($Version['Revision']);
|
---|
26 | }
|
---|
27 |
|
---|
28 | function IsInstalled()
|
---|
29 | {
|
---|
30 | $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->VersionTable.'"');
|
---|
31 | return($DbResult->num_rows > 0);
|
---|
32 | }
|
---|
33 |
|
---|
34 | function IsUpToDate()
|
---|
35 | {
|
---|
36 | return($this->Revision <= $this->GetDbVersion());
|
---|
37 | }
|
---|
38 |
|
---|
39 | function Upgrade()
|
---|
40 | {
|
---|
41 | $DbRevision = $this->GetDbVersion();
|
---|
42 | $Output = 'Počátečnà revize databáze: '.$DbRevision.'<br/>';
|
---|
43 | while($this->Revision > $DbRevision)
|
---|
44 | {
|
---|
45 | $TraceItem = $this->Trace[$DbRevision];
|
---|
46 | $Output .= 'Aktualizace na verzi '.$TraceItem['Revision'].':<br/>';
|
---|
47 | // Show applied SQL queries immediatelly
|
---|
48 | echo($Output);
|
---|
49 | $Output = '';
|
---|
50 | $RevUpdate = $TraceItem['Function'];
|
---|
51 | $RevUpdate($this);
|
---|
52 | $DbRevision = $TraceItem['Revision'];
|
---|
53 | $this->Database->query('UPDATE `'.$this->VersionTable.'` SET `Revision`= '.
|
---|
54 | $TraceItem['Revision'].' WHERE `Id`=1');
|
---|
55 | }
|
---|
56 | return($Output);
|
---|
57 | }
|
---|
58 |
|
---|
59 | function Install()
|
---|
60 | {
|
---|
61 | $InstallMethod = $this->InstallMethod;
|
---|
62 | $InstallMethod($this);
|
---|
63 | $this->Update();
|
---|
64 | }
|
---|
65 |
|
---|
66 | function Uninstall()
|
---|
67 | {
|
---|
68 |
|
---|
69 | }
|
---|
70 |
|
---|
71 | function InsertSampleData()
|
---|
72 | {
|
---|
73 | $InstallMethod = $this->InsertSampleDataMethod;
|
---|
74 | $InstallMethod($this);
|
---|
75 | }
|
---|
76 |
|
---|
77 | function Execute($Query)
|
---|
78 | {
|
---|
79 | echo($Query.';<br/>');
|
---|
80 | flush();
|
---|
81 | return($this->Database->query($Query));
|
---|
82 | }
|
---|
83 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.