Skip to content

Commit cc95818

Browse files
Afaque Hussainepriestley
Afaque Hussain
authored and
epriestley
committed
Code Refactored
Summary: Code Refactored as suggested by epriestley Test Plan: Same test plan as of Installation & Uninstallation of Applications Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4740
1 parent bdecadf commit cc95818

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/applications/base/PhabricatorApplication.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ public function getQuickCreateURI() {
227227

228228
/* -( Application Management )--------------------------------------------- */
229229

230+
public static function getByClass($class_name) {
231+
232+
$selected = null;
233+
$applications = PhabricatorApplication::getAllApplications();
234+
235+
foreach ($applications as $application) {
236+
if (get_class($application) == $class_name) {
237+
$selected = $application;
238+
break;
239+
}
240+
}
241+
return $selected;
242+
}
243+
230244
public static function getAllApplications() {
231245

232246
$classes = id(new PhutilSymbolLoader())

src/applications/meta/controller/PhabricatorApplicationDetailViewController.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@ public function processRequest() {
1313
$request = $this->getRequest();
1414
$user = $request->getUser();
1515

16-
$selected = null;
17-
$applications = PhabricatorApplication::getAllApplications();
18-
19-
foreach ($applications as $application) {
20-
if (get_class($application) == $this->application) {
21-
$selected = $application;
22-
break;
23-
}
24-
}
16+
$selected = PhabricatorApplication::getByClass($this->application);
2517

2618
if (!$selected) {
2719
return new Aphront404Response();

src/applications/meta/controller/PhabricatorApplicationUninstallController.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ public function willProcessRequest(array $data) {
1414
public function processRequest() {
1515
$request = $this->getRequest();
1616
$user = $request->getUser();
17-
$app_name = substr($this->application, strlen('PhabricatorApplication'));
17+
18+
$selected = PhabricatorApplication::getByClass($this->application);
19+
20+
if (!$selected) {
21+
return new Aphront404Response();
22+
}
1823

1924
if ($request->isDialogFormPost()) {
2025
$this->manageApplication();
@@ -26,14 +31,18 @@ public function processRequest() {
2631
$dialog = id(new AphrontDialogView())
2732
->setUser($user)
2833
->setTitle('Confirmation')
29-
->appendChild('Install '. $app_name. ' application ?')
34+
->appendChild(
35+
'Install '. $selected->getName(). ' application ?'
36+
)
3037
->addSubmitButton('Install')
3138
->addCancelButton('/applications/view/'.$this->application);
3239
} else {
3340
$dialog = id(new AphrontDialogView())
3441
->setUser($user)
3542
->setTitle('Confirmation')
36-
->appendChild('Really Uninstall '. $app_name. ' application ?')
43+
->appendChild(
44+
'Really Uninstall '. $selected->getName(). ' application ?'
45+
)
3746
->addSubmitButton('Uninstall')
3847
->addCancelButton('/applications/view/'.$this->application);
3948
}

0 commit comments

Comments
 (0)