/
update.php
86 lines (77 loc) · 2.64 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
<?php
namespace Concrete\Controller\SinglePage\Dashboard\Extend;
use Concrete\Core\Page\Controller\DashboardPageController;
use TaskPermission;
use Package;
use Marketplace;
use Concrete\Core\Marketplace\RemoteItem as MarketplaceRemoteItem;
use Localization;
use Loader;
use Exception;
class Update extends DashboardPageController
{
public function on_start()
{
$this->error = Loader::helper('validation/error');
}
public function do_update($pkgHandle = false)
{
$tp = new TaskPermission();
if ($tp->canInstallPackages()) {
if ($pkgHandle) {
$pkg = \Concrete\Core\Support\Facade\Package::getClass($pkgHandle);
$r = $pkg->testForUpgrade();
if ($r !== true) {
$this->error->add($r);
} else {
$p = Package::getByHandle($pkgHandle);
$loc = Localization::getInstance();
$loc->pushActiveContext(Localization::CONTEXT_SYSTEM);
try {
$p->upgradeCoreData();
$p->upgrade();
$p->upgradePackageThemes();
$loc->popActiveContext();
$this->set('message', t('The package has been updated successfully.'));
} catch (Exception $e) {
$loc->popActiveContext();
$this->error->add($e);
}
}
}
}
$this->view();
}
public function view()
{
$tp = new TaskPermission();
if ($tp->canInstallPackages()) {
$mi = Marketplace::getInstance();
if ($mi->isConnected()) {
Marketplace::checkPackageUpdates();
}
}
}
public function prepare_remote_upgrade($remoteMPID = 0)
{
$tp = new TaskPermission();
if ($tp->canInstallPackages()) {
$mri = MarketplaceRemoteItem::getByID($remoteMPID);
if (!is_object($mri)) {
$this->set('error', array(t('Invalid marketplace item ID.')));
return;
}
$local = Package::getbyHandle($mri->getHandle());
if (!is_object($local) || $local->isPackageInstalled() == false) {
$this->error->add(t('Package Not Found.'));
return;
}
$r = $mri->downloadUpdate();
if ($r != false) {
$this->error->add($r);
} else {
$this->redirect('/dashboard/extend/update', 'do_update', $mri->getHandle());
}
}
}
}