Skip to content

Commit 5017c80

Browse files
Afaque Hussainepriestley
authored andcommitted
Installation & Uninstallion of Applications
Summary: Created Applications application which allows uninstallation & installation of application. Test Plan: In "Applications" application, clicked on uninstalled the application by cliking Uninstall and chekcing whether they are really uninstalled(Disabling URI & in appearance in the side pane). Then Clicked on the install button of the uninstalled application to check whether they are installed. Reviewers: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4715
1 parent 683df86 commit 5017c80

18 files changed

+252
-37
lines changed

conf/default.conf.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@
839839
// Should Phabricator show beta applications on the homepage
840840
'phabricator.show-beta-applications' => false,
841841

842+
// Contains a list of uninstalled applications
843+
'phabricator.uninstalled-applications' => array(),
844+
842845
// -- Files ----------------------------------------------------------------- //
843846

844847
// Lists which uploaded file types may be viewed in the browser. If a file

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@
673673
'PhabricatorApplicationTransactionView' => 'applications/transactions/view/PhabricatorApplicationTransactionView.php',
674674
'PhabricatorApplicationTransactions' => 'applications/transactions/application/PhabricatorApplicationTransactions.php',
675675
'PhabricatorApplicationUIExamples' => 'applications/uiexample/application/PhabricatorApplicationUIExamples.php',
676+
'PhabricatorApplicationUninstallController' => 'applications/meta/controller/PhabricatorApplicationUninstallController.php',
676677
'PhabricatorApplicationsController' => 'applications/meta/controller/PhabricatorApplicationsController.php',
677678
'PhabricatorApplicationsListController' => 'applications/meta/controller/PhabricatorApplicationsListController.php',
678679
'PhabricatorAuditActionConstants' => 'applications/audit/constants/PhabricatorAuditActionConstants.php',
@@ -2103,6 +2104,7 @@
21032104
'PhabricatorApplicationTransactionView' => 'AphrontView',
21042105
'PhabricatorApplicationTransactions' => 'PhabricatorApplication',
21052106
'PhabricatorApplicationUIExamples' => 'PhabricatorApplication',
2107+
'PhabricatorApplicationUninstallController' => 'PhabricatorApplicationsController',
21062108
'PhabricatorApplicationsController' => 'PhabricatorController',
21072109
'PhabricatorApplicationsListController' => 'PhabricatorApplicationsController',
21082110
'PhabricatorAuditAddCommentController' => 'PhabricatorAuditController',

src/applications/auth/application/PhabricatorApplicationAuth.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ public function shouldAppearInLaunchView() {
66
return false;
77
}
88

9+
public function canUninstall() {
10+
return false;
11+
}
12+
913
public function buildMainMenuItems(
1014
PhabricatorUser $user,
1115
PhabricatorController $controller = null) {

src/applications/base/PhabricatorApplication.php

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,25 @@ public function isEnabled() {
6262
return true;
6363
}
6464

65+
public function isInstalled() {
66+
$uninstalled =
67+
PhabricatorEnv::getEnvConfig('phabricator.uninstalled-applications');
68+
69+
if (isset($uninstalled[get_class($this)])) {
70+
return false;
71+
} else {
72+
return true;
73+
}
74+
}
75+
6576
public function isBeta() {
6677
return false;
6778
}
6879

80+
public function canUninstall() {
81+
return true;
82+
}
83+
6984
public function getPHID() {
7085
return 'PHID-APPS-'.get_class($this);
7186
}
@@ -212,13 +227,34 @@ public function getQuickCreateURI() {
212227

213228
/* -( Application Management )--------------------------------------------- */
214229

230+
public static function getAllApplications() {
231+
232+
$classes = id(new PhutilSymbolLoader())
233+
->setAncestorClass(__CLASS__)
234+
->setConcreteOnly(true)
235+
->selectAndLoadSymbols();
236+
237+
$apps = array();
238+
239+
foreach ($classes as $class) {
240+
$app = newv($class['name'], array());
241+
$apps[] = $app;
242+
}
243+
244+
return $apps;
245+
}
215246

216247
public static function getAllInstalledApplications() {
217248
static $applications;
218249

219250
$show_beta =
220251
PhabricatorEnv::getEnvConfig('phabricator.show-beta-applications');
221252

253+
$uninstalled =
254+
PhabricatorEnv::getEnvConfig('phabricator.uninstalled-applications');
255+
256+
257+
222258
if (empty($applications)) {
223259
$classes = id(new PhutilSymbolLoader())
224260
->setAncestorClass(__CLASS__)
@@ -227,22 +263,29 @@ public static function getAllInstalledApplications() {
227263

228264
$apps = array();
229265
foreach ($classes as $class) {
230-
$app = newv($class['name'], array());
231-
if (!$app->isEnabled()) {
266+
267+
if (isset($uninstalled[$class['name']])) {
268+
continue;
269+
}
270+
271+
$app = newv($class['name'], array());
272+
273+
if (!$app->isEnabled()) {
232274
continue;
233-
}
275+
}
234276

235-
if (!$show_beta && $app->isBeta()) {
277+
if (!$show_beta && $app->isBeta()) {
236278
continue;
237-
}
279+
}
238280

239-
$apps[] = $app;
281+
$apps[] = $app;
240282
}
283+
241284
$applications = $apps;
242285
}
243286

244287
return $applications;
245288
}
246289

247-
248290
}
291+

src/applications/config/application/PhabricatorApplicationConfig.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public function getApplicationGroup() {
1818
return self::GROUP_ADMIN;
1919
}
2020

21+
public function canUninstall() {
22+
return false;
23+
}
24+
2125
public function getRoutes() {
2226
return array(
2327
'/config/' => array(

src/applications/config/option/PhabricatorCoreConfigOptions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public function getOptions() {
128128
$this->newOption('test.value', 'wild', null)
129129
->setLocked(true)
130130
->setDescription(pht('Unit test value.')),
131+
$this->newOption('phabricator.uninstalled-applications', 'set', array())
132+
->setLocked(true)
133+
->setDescription(
134+
pht('Array containing list of Uninstalled applications.')
135+
),
131136
);
132137
}
133138

src/applications/daemon/application/PhabricatorApplicationDaemons.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public function getApplicationGroup() {
2626
return self::GROUP_ADMIN;
2727
}
2828

29+
public function canUninstall() {
30+
return false;
31+
}
32+
2933
public function getRoutes() {
3034
return array(
3135
'/daemon/' => array(

src/applications/feed/application/PhabricatorApplicationFeed.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public function getIconName() {
1414
return 'feed';
1515
}
1616

17+
public function canUninstall() {
18+
return false;
19+
}
20+
1721
public function getRoutes() {
1822
return array(
1923
'/feed/' => array(

src/applications/files/application/PhabricatorApplicationFiles.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function getQuickCreateURI() {
3030
return $this->getBaseURI().'upload/';
3131
}
3232

33+
public function canUninstall() {
34+
return false;
35+
}
36+
3337
public function getRoutes() {
3438
return array(
3539
'/F(?P<id>[1-9]\d*)' => 'PhabricatorFileShortcutController',

src/applications/meta/application/PhabricatorApplicationApplications.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
final class PhabricatorApplicationApplications extends PhabricatorApplication {
44

5+
public function canUninstall() {
6+
return false;
7+
}
8+
59
public function getBaseURI() {
610
return '/applications/';
711
}
@@ -28,7 +32,8 @@ public function getRoutes() {
2832
'' => 'PhabricatorApplicationsListController',
2933
'view/(?P<application>\w+)/' =>
3034
'PhabricatorApplicationDetailViewController',
31-
35+
'(?P<application>\w+)/(?P<action>install|uninstall)/' =>
36+
'PhabricatorApplicationUninstallController',
3237
),
3338

3439
);

src/applications/meta/controller/PhabricatorApplicationDetailViewController.php

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public function processRequest() {
1414
$user = $request->getUser();
1515

1616
$selected = null;
17-
$applications = PhabricatorApplication::getAllInstalledApplications();
17+
$applications = PhabricatorApplication::getAllApplications();
1818

1919
foreach ($applications as $application) {
2020
if (get_class($application) == $this->application) {
21-
$selected = $application;
22-
break;
21+
$selected = $application;
22+
break;
2323
}
2424
}
2525

@@ -35,43 +35,67 @@ public function processRequest() {
3535
->setName(pht('Applications'))
3636
->setHref($this->getApplicationURI()));
3737

38-
$properties = $this->buildPropertyView($selected);
39-
$actions = $this->buildActionView($user);
40-
41-
return $this->buildApplicationPage(
42-
array(
43-
$crumbs,
44-
id(new PhabricatorHeaderView())->setHeader($title),
45-
$actions,
46-
$properties,
47-
),
48-
array(
49-
'title' => $title,
50-
'device' => true,
51-
));
38+
$properties = $this->buildPropertyView($selected);
39+
$actions = $this->buildActionView($user, $selected);
40+
41+
return $this->buildApplicationPage(
42+
array(
43+
$crumbs,
44+
id(new PhabricatorHeaderView())->setHeader($title),
45+
$actions,
46+
$properties,
47+
),
48+
array(
49+
'title' => $title,
50+
'device' => true,
51+
));
5252
}
5353

5454
private function buildPropertyView(PhabricatorApplication $selected) {
5555
$properties = new PhabricatorPropertyListView();
5656

57-
$properties->addProperty(
58-
pht('Status'), pht('Installed'));
57+
if ($selected->isInstalled()) {
58+
$properties->addProperty(
59+
pht('Status'), pht('Installed'));
60+
61+
} else {
62+
$properties->addProperty(
63+
pht('Status'), pht('Uninstalled'));
64+
}
5965

6066
$properties->addProperty(
6167
pht('Description'), $selected->getShortDescription());
6268

6369
return $properties;
6470
}
6571

66-
private function buildActionView(PhabricatorUser $user) {
67-
68-
return id(new PhabricatorActionListView())
69-
->setUser($user)
70-
->addAction(
71-
id(new PhabricatorActionView())
72-
->setName(pht('Uninstall'))
73-
->setIcon('delete')
74-
);
72+
private function buildActionView(
73+
PhabricatorUser $user, PhabricatorApplication $selected) {
74+
75+
if ($selected->canUninstall()) {
76+
if ($selected->isInstalled()) {
77+
78+
return id(new PhabricatorActionListView())
79+
->setUser($user)
80+
->addAction(
81+
id(new PhabricatorActionView())
82+
->setName(pht('Uninstall'))
83+
->setIcon('delete')
84+
->setHref(
85+
$this->getApplicationURI(get_class($selected).'/uninstall/'))
86+
);
87+
} else {
88+
return id(new PhabricatorActionListView())
89+
->setUser($user)
90+
->addAction(
91+
id(new PhabricatorActionView())
92+
->setName(pht('Install'))
93+
->setIcon('new')
94+
->setHref(
95+
$this->getApplicationURI(get_class($selected).'/install/'))
96+
);
97+
}
98+
}
7599
}
76100

77101
}

0 commit comments

Comments
 (0)