/
update.php
231 lines (209 loc) · 7.62 KB
/
update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
namespace Concrete\Controller\SinglePage\Dashboard\System\Update;
use Concrete\Controller\Upgrade;
use Concrete\Core\Page\Controller\DashboardPageController;
use Concrete\Core\Updater\ApplicationUpdate;
use Concrete\Core\Updater\Archive;
use Config;
use Exception;
use Loader;
class UpdateArchive extends Archive
{
public function __construct()
{
parent::__construct();
$this->targetDirectory = DIR_CORE_UPDATES;
}
public function install($file, $inplace = true)
{
parent::install($file, $inplace);
}
}
if (!ini_get('safe_mode')) {
@set_time_limit(0);
ini_set('max_execution_time', 0);
}
class Update extends DashboardPageController
{
public function check_for_updates()
{
Config::clear('concrete.misc.latest_version');
\Concrete\Core\Updater\Update::getLatestAvailableVersionNumber();
$this->redirect('/dashboard/system/update/update');
}
public function on_start()
{
parent::on_start();
$this->error = Loader::helper('validation/error');
id(new Upgrade())->checkSecurity();
}
public function download_update()
{
$p = new \Permissions();
if (!$p->canUpgrade()) {
return false;
}
$vt = Loader::helper('validation/token');
if (!$vt->validate('download_update')) {
$this->error->add($vt->getErrorMessage());
}
if (!is_dir(DIR_CORE_UPDATES)) {
$this->error->add(t('The directory %s does not exist.', DIR_CORE_UPDATES));
} else {
if (!is_writable(DIR_CORE_UPDATES)) {
$this->error->add(t('The directory %s must be writable by the web server.', DIR_CORE_UPDATES));
}
}
if (!$this->error->has()) {
$remote = \Concrete\Core\Updater\Update::getApplicationUpdateInformation();
if (is_object($remote)) {
// try to download
$r = \Marketplace::downloadRemoteFile($remote->getDirectDownloadURL());
if (is_object($r)) {
// error object
$this->error->add($r);
}
if (!$this->error->has()) {
// the file exists in the right spot
$ar = new UpdateArchive();
try {
$ar->install($r);
} catch (Exception $e) {
$this->error->add($e->getMessage());
}
}
} else {
$this->error->add(t('Unable to retrieve software from update server.'));
}
}
$this->view();
}
public function view()
{
$p = new \Permissions();
if ($p->canUpgrade()) {
$upd = new \Concrete\Core\Updater\Update();
$updates = $upd->getLocalAvailableUpdates();
$remote = $upd->getApplicationUpdateInformation();
$this->set('updates', $updates);
if (is_object($remote) && version_compare($remote->getVersion(), APP_VERSION, '>')) {
// loop through local updates
$downloadableUpgradeAvailable = true;
foreach ($updates as $upd) {
if ($upd->getUpdateVersion() == $remote->getVersion()) {
// we have a LOCAL version ready to install that is the same, so we abort
$downloadableUpgradeAvailable = false;
$this->set('showDownloadBox', false);
break;
}
}
$this->set('downloadableUpgradeAvailable', $downloadableUpgradeAvailable);
$this->set('remoteUpdate', $remote);
} else {
$this->set('downloadableUpgradeAvailable', false);
}
if (count($updates) == 1) {
$this->set('update', $updates[0]);
}
$this->set('canUpgrade', true);
}
}
public function get_update_diagnostic_information()
{
$p = new \Permissions();
if ($p->canUpgrade()) {
$updateVersion = trim($this->post('version'));
if ($updateVersion) {
$upd = ApplicationUpdate::getByVersionNumber($updateVersion);
if (is_object($upd)) {
$diagnostic = $upd->getDiagnosticObject();
echo json_encode($diagnostic->getJSONObject());
}
}
}
exit;
}
public function do_update()
{
$p = new \Permissions();
if (!$p->canUpgrade()) {
return false;
}
$updateVersion = $this->post('version');
if (!$updateVersion) {
$this->error->add(t('Invalid version'));
} else {
$upd = ApplicationUpdate::getByVersionNumber($updateVersion);
}
if (!is_object($upd)) {
$this->error->add(t('Invalid version'));
} else {
if (version_compare($upd->getUpdateVersion(), APP_VERSION, '<=')) {
$this->error->add(
t(
'You may only apply updates with a greater version number than the version you are currently running.'));
}
}
if (!$this->error->has()) {
$resp = $upd->apply();
if ($resp !== true) {
switch ($resp) {
case ApplicationUpdate::E_UPDATE_WRITE_CONFIG:
$this->error->add(
t(
'Unable to write to %1$s. You must make %1$s writable in order to upgrade in this manner.',
'application/config/update.php'
)
);
break;
}
} else {
$token = Loader::helper("validation/token");
\Redirect::to('/ccm/system/upgrade/submit?ccm_token=' . $token->generate('Concrete\Controller\Upgrade'))->send();
exit;
}
}
}
public function start()
{
$p = new \Permissions();
if (!$p->canUpgrade()) {
return false;
}
$updateVersion = $this->post('updateVersion');
if (!$updateVersion) {
$this->error->add(t('Invalid version'));
} else {
$upd = ApplicationUpdate::getByVersionNumber($updateVersion);
}
if (!is_object($upd)) {
$this->error->add(t('Invalid version'));
} else {
if (version_compare($upd->getUpdateVersion(), APP_VERSION, '<=')) {
$this->error->add(
t(
'You may only apply updates with a greater version number than the version you are currently running.'));
}
}
if (!$this->error->has()) {
/*
$resp = $upd->apply();
if ($resp !== true) {
switch ($resp) {
case ApplicationUpdate::E_UPDATE_WRITE_CONFIG:
$this->error->add(
t(
'Unable to write to config/site.php. You must make config/site.php writable in order to upgrade in this manner.'));
break;
}
} else {
$token = Loader::helper("validation/token");
\Redirect::to('/ccm/system/upgrade/submit?ccm_token=' . $token->generate('Concrete\Controller\Upgrade'))->send();
exit;
}
*/
$this->set('update', $upd);
}
$this->view();
}
}