|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Upgrade interface class |
|
14
|
|
|
* |
|
15
|
|
|
* See the enclosed file license.txt for licensing information. |
|
16
|
|
|
* If you did not receive this file, get it at http://www.gnu.org/licenses/gpl-2.0.html |
|
17
|
|
|
* |
|
18
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
|
19
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
20
|
|
|
* @package upgrader |
|
21
|
|
|
* @since 2.3.0 |
|
22
|
|
|
* @author Taiwen Jiang <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class XoopsUpgrade |
|
25
|
|
|
{ |
|
26
|
|
|
public $usedFiles = array(); |
|
27
|
|
|
public $tasks = array(); |
|
28
|
|
|
public $languageFolder = null; |
|
29
|
|
|
public $logs = array(); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param null $dirname |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct($dirname = null) |
|
35
|
|
|
{ |
|
36
|
|
|
if ($dirname) { |
|
37
|
|
|
$this->loadLanguage($dirname); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Run the check_* tasks to see if the patch is needed. |
|
43
|
|
|
* |
|
44
|
|
|
* The check_* methods should return: |
|
45
|
|
|
* - true if the patch has been applied |
|
46
|
|
|
* - false if the patch needs to be performed |
|
47
|
|
|
* |
|
48
|
|
|
* @return PatchStatus |
|
49
|
|
|
*/ |
|
50
|
|
|
public function isApplied() |
|
51
|
|
|
{ |
|
52
|
|
|
return new PatchStatus($this); |
|
53
|
|
|
/* |
|
54
|
|
|
$step = get_class($this); |
|
55
|
|
|
if (!isset($_SESSION['xoops_upgrade'][$step]) || !is_array($_SESSION['xoops_upgrade'][$step])) { |
|
56
|
|
|
$_SESSION['xoops_upgrade'][$step] = array(); |
|
57
|
|
|
} |
|
58
|
|
|
foreach ($this->tasks as $task) { |
|
59
|
|
|
if (!in_array($task, $_SESSION['xoops_upgrade'][$step])) { |
|
60
|
|
|
if (!$res = $this->{"check_{$task}"}()) { |
|
61
|
|
|
$_SESSION['xoops_upgrade'][$step][] = $task; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return empty($_SESSION['xoops_upgrade'][$step]) ? true : false; |
|
67
|
|
|
*/ |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return bool |
|
72
|
|
|
*/ |
|
73
|
|
|
public function apply() |
|
74
|
|
|
{ |
|
75
|
|
|
$patchStatus = $this->isApplied(); |
|
76
|
|
|
$tasks = $patchStatus->tasks; |
|
77
|
|
|
foreach ($tasks as $task) { |
|
78
|
|
|
$res = $this->{"apply_{$task}"}(); |
|
79
|
|
|
if (!$res) { |
|
80
|
|
|
return false; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return true; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param $dirname |
|
89
|
|
|
*/ |
|
90
|
|
|
public function loadLanguage($dirname) |
|
91
|
|
|
{ |
|
92
|
|
|
global $upgradeControl; |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
$upgradeControl->loadLanguage($dirname); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
|
|
public function message() |
|
101
|
|
|
{ |
|
102
|
|
|
return empty($this->logs) ? '' : implode('<br>', $this->logs); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Relocated here from upgrade/index.php |
|
107
|
|
|
* |
|
108
|
|
|
* @param XoopsDatabase $db |
|
109
|
|
|
* @param $table |
|
110
|
|
|
* @param $field |
|
111
|
|
|
* @param string $condition |
|
112
|
|
|
* |
|
113
|
|
|
* @return bool |
|
114
|
|
|
*/ |
|
115
|
|
|
protected function getDbValue(XoopsDatabase $db, $table, $field, $condition = '') |
|
116
|
|
|
{ |
|
117
|
|
|
$table = $db->prefix($table); |
|
118
|
|
|
$sql = "SELECT `{$field}` FROM `{$table}`"; |
|
119
|
|
|
if ($condition) { |
|
120
|
|
|
$sql .= " WHERE {$condition}"; |
|
121
|
|
|
} |
|
122
|
|
|
$result = $db->query($sql); |
|
123
|
|
|
if ($result) { |
|
124
|
|
|
$row = $db->fetchRow($result); |
|
125
|
|
|
if ($row) { |
|
126
|
|
|
return $row[0]; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return false; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state