@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add transactions for installing/uninstalling applications

Summary: Fixes T11476.

Test Plan:
- Installed/uninstalled the Conpherence application
- Observed correct timeline stories
- Observed correct config in database
- Observed 404 for application page

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T11476

Differential Revision: https://secure.phabricator.com/D19339

+120 -38
+2
src/__phutil_library_map__.php
··· 2069 2069 'PhabricatorApplicationTransactionWarningException' => 'applications/transactions/exception/PhabricatorApplicationTransactionWarningException.php', 2070 2070 'PhabricatorApplicationTransactionWarningResponse' => 'applications/transactions/response/PhabricatorApplicationTransactionWarningResponse.php', 2071 2071 'PhabricatorApplicationUninstallController' => 'applications/meta/controller/PhabricatorApplicationUninstallController.php', 2072 + 'PhabricatorApplicationUninstallTransaction' => 'applications/meta/xactions/PhabricatorApplicationUninstallTransaction.php', 2072 2073 'PhabricatorApplicationsApplication' => 'applications/meta/application/PhabricatorApplicationsApplication.php', 2073 2074 'PhabricatorApplicationsController' => 'applications/meta/controller/PhabricatorApplicationsController.php', 2074 2075 'PhabricatorApplicationsListController' => 'applications/meta/controller/PhabricatorApplicationsListController.php', ··· 7533 7534 'PhabricatorApplicationTransactionWarningException' => 'Exception', 7534 7535 'PhabricatorApplicationTransactionWarningResponse' => 'AphrontProxyResponse', 7535 7536 'PhabricatorApplicationUninstallController' => 'PhabricatorApplicationsController', 7537 + 'PhabricatorApplicationUninstallTransaction' => 'PhabricatorApplicationTransactionType', 7536 7538 'PhabricatorApplicationsApplication' => 'PhabricatorApplication', 7537 7539 'PhabricatorApplicationsController' => 'PhabricatorController', 7538 7540 'PhabricatorApplicationsListController' => 'PhabricatorApplicationsController',
+38 -37
src/applications/meta/controller/PhabricatorApplicationUninstallController.php
··· 3 3 final class PhabricatorApplicationUninstallController 4 4 extends PhabricatorApplicationsController { 5 5 6 - private $application; 7 - private $action; 8 - 9 6 public function handleRequest(AphrontRequest $request) { 10 7 $viewer = $request->getViewer(); 11 - $this->action = $request->getURIData('action'); 12 - $this->application = $request->getURIData('application'); 8 + $user = $request->getUser(); 9 + $action = $request->getURIData('action'); 10 + $application_name = $request->getURIData('application'); 13 11 14 - $selected = id(new PhabricatorApplicationQuery()) 12 + $application = id(new PhabricatorApplicationQuery()) 15 13 ->setViewer($viewer) 16 - ->withClasses(array($this->application)) 14 + ->withClasses(array($application_name)) 17 15 ->requireCapabilities( 18 16 array( 19 17 PhabricatorPolicyCapability::CAN_VIEW, ··· 21 19 )) 22 20 ->executeOne(); 23 21 24 - if (!$selected) { 22 + if (!$application) { 25 23 return new Aphront404Response(); 26 24 } 27 25 28 - $view_uri = $this->getApplicationURI('view/'.$this->application); 26 + $view_uri = $this->getApplicationURI('view/'.$application_name); 29 27 30 28 $prototypes_enabled = PhabricatorEnv::getEnvConfig( 31 29 'phabricator.show-prototypes'); ··· 34 32 ->setUser($viewer) 35 33 ->addCancelButton($view_uri); 36 34 37 - if ($selected->isPrototype() && !$prototypes_enabled) { 35 + if ($application->isPrototype() && !$prototypes_enabled) { 38 36 $dialog 39 37 ->setTitle(pht('Prototypes Not Enabled')) 40 38 ->appendChild( ··· 46 44 } 47 45 48 46 if ($request->isDialogFormPost()) { 49 - $this->manageApplication(); 50 - return id(new AphrontRedirectResponse())->setURI($view_uri); 47 + $xactions = array(); 48 + $template = $application->getApplicationTransactionTemplate(); 49 + $xactions[] = id(clone $template) 50 + ->setTransactionType( 51 + PhabricatorApplicationUninstallTransaction::TRANSACTIONTYPE) 52 + ->setNewValue($action); 53 + 54 + $editor = id(new PhabricatorApplicationEditor()) 55 + ->setActor($user) 56 + ->setContentSourceFromRequest($request) 57 + ->setContinueOnNoEffect(true) 58 + ->setContinueOnMissingFields(true); 59 + 60 + try { 61 + $editor->applyTransactions($application, $xactions); 62 + return id(new AphrontRedirectResponse())->setURI($view_uri); 63 + } catch (PhabricatorApplicationTransactionValidationException $ex) { 64 + $validation_exception = $ex; 65 + } 66 + 67 + return $this->newDialog() 68 + ->setTitle(pht('Validation Failed')) 69 + ->setValidationException($validation_exception) 70 + ->addCancelButton($view_uri); 51 71 } 52 72 53 - if ($this->action == 'install') { 54 - if ($selected->canUninstall()) { 73 + if ($action == 'install') { 74 + if ($application->canUninstall()) { 55 75 $dialog 56 76 ->setTitle(pht('Confirmation')) 57 77 ->appendChild( 58 78 pht( 59 79 'Install %s application?', 60 - $selected->getName())) 80 + $application->getName())) 61 81 ->addSubmitButton(pht('Install')); 62 82 63 83 } else { ··· 66 86 ->appendChild(pht('You cannot install an installed application.')); 67 87 } 68 88 } else { 69 - if ($selected->canUninstall()) { 89 + if ($application->canUninstall()) { 70 90 $dialog->setTitle(pht('Really Uninstall Application?')); 71 91 72 - if ($selected instanceof PhabricatorHomeApplication) { 92 + if ($application instanceof PhabricatorHomeApplication) { 73 93 $dialog 74 94 ->appendParagraph( 75 95 pht( ··· 86 106 ->appendParagraph( 87 107 pht( 88 108 'Really uninstall the %s application?', 89 - $selected->getName())) 109 + $application->getName())) 90 110 ->addSubmitButton(pht('Uninstall')); 91 111 } 92 112 } else { ··· 99 119 } 100 120 } 101 121 return id(new AphrontDialogResponse())->setDialog($dialog); 102 - } 103 - 104 - public function manageApplication() { 105 - $key = 'phabricator.uninstalled-applications'; 106 - $config_entry = PhabricatorConfigEntry::loadConfigEntry($key); 107 - $list = $config_entry->getValue(); 108 - $uninstalled = PhabricatorEnv::getEnvConfig($key); 109 - 110 - if (isset($uninstalled[$this->application])) { 111 - unset($list[$this->application]); 112 - } else { 113 - $list[$this->application] = true; 114 - } 115 - 116 - PhabricatorConfigEditor::storeNewValue( 117 - $this->getViewer(), 118 - $config_entry, 119 - $list, 120 - PhabricatorContentSource::newFromRequest($this->getRequest())); 121 122 } 122 123 123 124 }
+1 -1
src/applications/meta/xactions/PhabricatorApplicationPolicyChangeTransaction.php
··· 14 14 return $application->getPolicy($capability); 15 15 } 16 16 17 - public function applyInternalEffects($object, $value) { 17 + public function applyExternalEffects($object, $value) { 18 18 $application = $object; 19 19 $user = $this->getActor(); 20 20
+79
src/applications/meta/xactions/PhabricatorApplicationUninstallTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorApplicationUninstallTransaction 4 + extends PhabricatorApplicationTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'application.uninstall'; 7 + 8 + public function generateOldValue($object) { 9 + $key = 'phabricator.uninstalled-applications'; 10 + $config_entry = PhabricatorConfigEntry::loadConfigEntry($key); 11 + $list = $config_entry->getValue(); 12 + $uninstalled = PhabricatorEnv::getEnvConfig($key); 13 + 14 + if (isset($uninstalled[get_class($object)])) { 15 + return 'uninstalled'; 16 + } else { 17 + return 'installed'; 18 + } 19 + } 20 + 21 + public function generateNewValue($object, $value) { 22 + if ($value === 'uninstall') { 23 + return 'uninstalled'; 24 + } else { 25 + return 'installed'; 26 + } 27 + } 28 + 29 + public function applyExternalEffects($object, $value) { 30 + $application = $object; 31 + $user = $this->getActor(); 32 + 33 + $key = 'phabricator.uninstalled-applications'; 34 + $config_entry = PhabricatorConfigEntry::loadConfigEntry($key); 35 + $list = $config_entry->getValue(); 36 + $uninstalled = PhabricatorEnv::getEnvConfig($key); 37 + 38 + if (isset($uninstalled[get_class($application)])) { 39 + unset($list[get_class($application)]); 40 + } else { 41 + $list[get_class($application)] = true; 42 + } 43 + 44 + $editor = $this->getEditor(); 45 + $content_source = $editor->getContentSource(); 46 + PhabricatorConfigEditor::storeNewValue( 47 + $user, 48 + $config_entry, 49 + $list, 50 + $content_source); 51 + } 52 + 53 + public function getTitle() { 54 + if ($this->getNewValue() === 'uninstalled') { 55 + return pht( 56 + '%s uninstalled this application.', 57 + $this->renderAuthor()); 58 + } else { 59 + return pht( 60 + '%s installed this application.', 61 + $this->renderAuthor()); 62 + } 63 + } 64 + 65 + public function getTitleForFeed() { 66 + if ($this->getNewValue() === 'uninstalled') { 67 + return pht( 68 + '%s uninstalled %s.', 69 + $this->renderAuthor(), 70 + $this->renderObject()); 71 + } else { 72 + return pht( 73 + '%s installed %s.', 74 + $this->renderAuthor(), 75 + $this->renderObject()); 76 + } 77 + } 78 + 79 + }