diff --git a/src/applications/meta/controller/PhabricatorApplicationDetailViewController.php b/src/applications/meta/controller/PhabricatorApplicationDetailViewController.php index 259b3c743..beda1d894 100644 --- a/src/applications/meta/controller/PhabricatorApplicationDetailViewController.php +++ b/src/applications/meta/controller/PhabricatorApplicationDetailViewController.php @@ -1,93 +1,101 @@ application = $data['application']; } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $selected = PhabricatorApplication::getByClass($this->application); if (!$selected) { return new Aphront404Response(); } $title = $selected->getName(); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addCrumb( id(new PhabricatorCrumbView()) ->setName(pht('Applications')) ->setHref($this->getApplicationURI())); $properties = $this->buildPropertyView($selected); $actions = $this->buildActionView($user, $selected); return $this->buildApplicationPage( array( $crumbs, id(new PhabricatorHeaderView())->setHeader($title), $actions, $properties, ), array( 'title' => $title, 'device' => true, )); } private function buildPropertyView(PhabricatorApplication $selected) { $properties = new PhabricatorPropertyListView(); if ($selected->isInstalled()) { $properties->addProperty( pht('Status'), pht('Installed')); } else { $properties->addProperty( pht('Status'), pht('Uninstalled')); } $properties->addProperty( pht('Description'), $selected->getShortDescription()); return $properties; } private function buildActionView( PhabricatorUser $user, PhabricatorApplication $selected) { + $view = id(new PhabricatorActionListView()) + ->setUser($user); + if ($selected->canUninstall()) { if ($selected->isInstalled()) { - - return id(new PhabricatorActionListView()) - ->setUser($user) - ->addAction( - id(new PhabricatorActionView()) - ->setName(pht('Uninstall')) - ->setIcon('delete') - ->setHref( + $view->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Uninstall')) + ->setIcon('delete') + ->setHref( $this->getApplicationURI(get_class($selected).'/uninstall/')) - ); + ); } else { - return id(new PhabricatorActionListView()) - ->setUser($user) - ->addAction( - id(new PhabricatorActionView()) - ->setName(pht('Install')) - ->setIcon('new') - ->setHref( - $this->getApplicationURI(get_class($selected).'/install/')) - ); + $view->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Install')) + ->setIcon('new') + ->setHref( + $this->getApplicationURI(get_class($selected).'/install/')) + ); } + } else { + $view->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Uninstall')) + ->setIcon('delete') + ->setDisabled(true) + ->setHref( + $this->getApplicationURI(get_class($selected).'/uninstall/')) + ); } + return $view; } } diff --git a/src/applications/meta/controller/PhabricatorApplicationUninstallController.php b/src/applications/meta/controller/PhabricatorApplicationUninstallController.php index fcf32ea4a..51b03cb08 100644 --- a/src/applications/meta/controller/PhabricatorApplicationUninstallController.php +++ b/src/applications/meta/controller/PhabricatorApplicationUninstallController.php @@ -1,102 +1,112 @@ application = $data['application']; $this->action = $data['action']; } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $selected = PhabricatorApplication::getByClass($this->application); - if (!$selected || !$selected->canUninstall()) { + if (!$selected) { return new Aphront404Response(); } if ($request->isDialogFormPost()) { $this->manageApplication(); return id(new AphrontRedirectResponse())->setURI('/applications/'); } - if ($this->action == 'install') { + $dialog = id(new AphrontDialogView()) + ->setUser($user) + ->addCancelButton('/applications/view/'.$this->application); - $dialog = id(new AphrontDialogView()) - ->setUser($user) - ->setTitle('Confirmation') - ->appendChild( - 'Install '. $selected->getName(). ' application ?' - ) - ->addSubmitButton('Install') - ->addCancelButton('/applications/view/'.$this->application); + if ($this->action == 'install') { + if ($selected->canUninstall()) { + $dialog->setTitle('Confirmation') + ->appendChild( + 'Install '. $selected->getName(). ' application ?' + ) + ->addSubmitButton('Install'); + + } else { + $dialog->setTitle('Information') + ->appendChild('You cannot install a installed application.'); + } } else { - $dialog = id(new AphrontDialogView()) - ->setUser($user) - ->setTitle('Confirmation') - ->appendChild( - 'Really Uninstall '. $selected->getName(). ' application ?' - ) - ->addSubmitButton('Uninstall') - ->addCancelButton('/applications/view/'.$this->application); + if ($selected->canUninstall()) { + $dialog->setTitle('Confirmation') + ->appendChild( + 'Really Uninstall '. $selected->getName(). ' application ?' + ) + ->addSubmitButton('Uninstall'); + } else { + $dialog->setTitle('Information') + ->appendChild( + 'This application cannot be uninstalled, + because it is required for Phabricator to work.' + ); + } } - return id(new AphrontDialogResponse())->setDialog($dialog); } public function manageApplication() { $key = 'phabricator.uninstalled-applications'; $config_entry = id(new PhabricatorConfigEntry()) ->loadOneWhere( 'configKey = %s AND namespace = %s', $key, 'default'); if (!$config_entry) { $config_entry = id(new PhabricatorConfigEntry()) ->setConfigKey($key) ->setNamespace('default'); } $list = $config_entry->getValue(); $uninstalled = PhabricatorEnv::getEnvConfig($key); if ($uninstalled[$this->application]) { unset($list[$this->application]); } else { $list[$this->application] = true; } $xaction = id(new PhabricatorConfigTransaction()) ->setTransactionType(PhabricatorConfigTransaction::TYPE_EDIT) ->setNewValue( array( 'deleted' => false, 'value' => $list )); $editor = id(new PhabricatorConfigEditor()) ->setActor($this->getRequest()->getUser()) ->setContinueOnNoEffect(true) ->setContentSource( PhabricatorContentSource::newForSource( PhabricatorContentSource::SOURCE_WEB, array( 'ip' => $this->getRequest()->getRemoteAddr(), ))); $editor->applyTransactions($config_entry, array($xaction)); } }