@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.

Make throwing things into the trash actually work in Nuance

Summary: Ref T12738. Implements some modular behavior for Nuance commands.

Test Plan: {F4975322}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12738

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

+187 -48
+6
src/__phutil_library_map__.php
··· 1601 1601 'MultimeterLabel' => 'applications/multimeter/storage/MultimeterLabel.php', 1602 1602 'MultimeterSampleController' => 'applications/multimeter/controller/MultimeterSampleController.php', 1603 1603 'MultimeterViewer' => 'applications/multimeter/storage/MultimeterViewer.php', 1604 + 'NuanceCommandImplementation' => 'applications/nuance/command/NuanceCommandImplementation.php', 1604 1605 'NuanceConduitAPIMethod' => 'applications/nuance/conduit/NuanceConduitAPIMethod.php', 1605 1606 'NuanceConsoleController' => 'applications/nuance/controller/NuanceConsoleController.php', 1606 1607 'NuanceContentSource' => 'applications/nuance/contentsource/NuanceContentSource.php', ··· 1636 1637 'NuanceItemRequestorTransaction' => 'applications/nuance/xaction/NuanceItemRequestorTransaction.php', 1637 1638 'NuanceItemSearchEngine' => 'applications/nuance/query/NuanceItemSearchEngine.php', 1638 1639 'NuanceItemSourceTransaction' => 'applications/nuance/xaction/NuanceItemSourceTransaction.php', 1640 + 'NuanceItemStatusTransaction' => 'applications/nuance/xaction/NuanceItemStatusTransaction.php', 1639 1641 'NuanceItemTransaction' => 'applications/nuance/storage/NuanceItemTransaction.php', 1640 1642 'NuanceItemTransactionComment' => 'applications/nuance/storage/NuanceItemTransactionComment.php', 1641 1643 'NuanceItemTransactionQuery' => 'applications/nuance/query/NuanceItemTransactionQuery.php', ··· 1690 1692 'NuanceSourceTransactionType' => 'applications/nuance/xaction/NuanceSourceTransactionType.php', 1691 1693 'NuanceSourceViewController' => 'applications/nuance/controller/NuanceSourceViewController.php', 1692 1694 'NuanceTransaction' => 'applications/nuance/storage/NuanceTransaction.php', 1695 + 'NuanceTrashCommand' => 'applications/nuance/command/NuanceTrashCommand.php', 1693 1696 'NuanceWorker' => 'applications/nuance/worker/NuanceWorker.php', 1694 1697 'OwnersConduitAPIMethod' => 'applications/owners/conduit/OwnersConduitAPIMethod.php', 1695 1698 'OwnersEditConduitAPIMethod' => 'applications/owners/conduit/OwnersEditConduitAPIMethod.php', ··· 6714 6717 'MultimeterLabel' => 'MultimeterDimension', 6715 6718 'MultimeterSampleController' => 'MultimeterController', 6716 6719 'MultimeterViewer' => 'MultimeterDimension', 6720 + 'NuanceCommandImplementation' => 'Phobject', 6717 6721 'NuanceConduitAPIMethod' => 'ConduitAPIMethod', 6718 6722 'NuanceConsoleController' => 'NuanceController', 6719 6723 'NuanceContentSource' => 'PhabricatorContentSource', ··· 6759 6763 'NuanceItemRequestorTransaction' => 'NuanceItemTransactionType', 6760 6764 'NuanceItemSearchEngine' => 'PhabricatorApplicationSearchEngine', 6761 6765 'NuanceItemSourceTransaction' => 'NuanceItemTransactionType', 6766 + 'NuanceItemStatusTransaction' => 'NuanceItemTransactionType', 6762 6767 'NuanceItemTransaction' => 'NuanceTransaction', 6763 6768 'NuanceItemTransactionComment' => 'PhabricatorApplicationTransactionComment', 6764 6769 'NuanceItemTransactionQuery' => 'PhabricatorApplicationTransactionQuery', ··· 6822 6827 'NuanceSourceTransactionType' => 'PhabricatorModularTransactionType', 6823 6828 'NuanceSourceViewController' => 'NuanceSourceController', 6824 6829 'NuanceTransaction' => 'PhabricatorModularTransaction', 6830 + 'NuanceTrashCommand' => 'NuanceCommandImplementation', 6825 6831 'NuanceWorker' => 'PhabricatorWorker', 6826 6832 'OwnersConduitAPIMethod' => 'ConduitAPIMethod', 6827 6833 'OwnersEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
+107
src/applications/nuance/command/NuanceCommandImplementation.php
··· 1 + <?php 2 + 3 + abstract class NuanceCommandImplementation 4 + extends Phobject { 5 + 6 + private $actor; 7 + 8 + private $transactionQueue = array(); 9 + 10 + final public function setActor(PhabricatorUser $actor) { 11 + $this->actor = $actor; 12 + return $this; 13 + } 14 + 15 + final public function getActor() { 16 + return $this->actor; 17 + } 18 + 19 + abstract public function getCommandName(); 20 + abstract public function canApplyToItem(NuanceItem $item); 21 + 22 + abstract protected function executeCommand( 23 + NuanceItem $item, 24 + NuanceItemCommand $command); 25 + 26 + final public function applyCommand( 27 + NuanceItem $item, 28 + NuanceItemCommand $command) { 29 + 30 + $command_key = $command->getCommand(); 31 + $implementation_key = $this->getCommandKey(); 32 + if ($command_key !== $implementation_key) { 33 + throw new Exception( 34 + pht( 35 + 'This command implementation("%s") can not apply a command of a '. 36 + 'different type ("%s").', 37 + $implementation_key, 38 + $command_key)); 39 + } 40 + 41 + if (!$this->canApplyToItem($item)) { 42 + throw new Exception( 43 + pht( 44 + 'This command implementation ("%s") can not be applied to an '. 45 + 'item of type "%s".', 46 + $implementation_key, 47 + $item->getItemType())); 48 + } 49 + 50 + $this->transactionQueue = array(); 51 + 52 + $command_type = NuanceItemCommandTransaction::TRANSACTIONTYPE; 53 + $command_xaction = $this->newTransaction($command_type); 54 + 55 + $result = $this->executeCommand($item, $command); 56 + 57 + $xactions = $this->transactionQueue; 58 + $this->transactionQueue = array(); 59 + 60 + $command_xaction->setNewValue( 61 + array( 62 + 'command' => $command->getCommand(), 63 + 'parameters' => $command->getParameters(), 64 + 'result' => $result, 65 + )); 66 + 67 + // TODO: Maybe preserve the actor's original content source? 68 + $source = PhabricatorContentSource::newForSource( 69 + PhabricatorDaemonContentSource::SOURCECONST); 70 + 71 + $actor = $this->getActor(); 72 + 73 + id(new NuanceItemEditor()) 74 + ->setActor($actor) 75 + ->setActingAsPHID($command->getAuthorPHID()) 76 + ->setContentSource($source) 77 + ->setContinueOnMissingFields(true) 78 + ->setContinueOnNoEffect(true) 79 + ->applyTransactions($item, $xactions); 80 + } 81 + 82 + final public function getCommandKey() { 83 + return $this->getPhobjectClassConstant('COMMANDKEY'); 84 + } 85 + 86 + final public static function getAllCommands() { 87 + return id(new PhutilClassMapQuery()) 88 + ->setAncestorClass(__CLASS__) 89 + ->setUniqueMethod('getCommandKey') 90 + ->execute(); 91 + } 92 + 93 + protected function newTransaction($type) { 94 + $xaction = id(new NuanceItemTransaction()) 95 + ->setTransactionType($type); 96 + 97 + $this->transactionQueue[] = $xaction; 98 + 99 + return $xaction; 100 + } 101 + 102 + protected function newStatusTransaction($status) { 103 + return $this->newTransaction(NuanceItemStatusTransaction::TRANSACTIONTYPE) 104 + ->setNewValue($status); 105 + } 106 + 107 + }
+23
src/applications/nuance/command/NuanceTrashCommand.php
··· 1 + <?php 2 + 3 + final class NuanceTrashCommand 4 + extends NuanceCommandImplementation { 5 + 6 + const COMMANDKEY = 'trash'; 7 + 8 + public function getCommandName() { 9 + return pht('Throw in Trash'); 10 + } 11 + 12 + public function canApplyToItem(NuanceItem $item) { 13 + $type = $item->getImplementation(); 14 + return ($type instanceof NuanceFormItemType); 15 + } 16 + 17 + protected function executeCommand( 18 + NuanceItem $item, 19 + NuanceItemCommand $command) { 20 + $this->newStatusTransaction(NuanceItem::STATUS_CLOSED); 21 + } 22 + 23 + }
+3
src/applications/nuance/item/NuanceGitHubEventItemType.php
··· 329 329 NuanceItem $item, 330 330 NuanceItemCommand $command) { 331 331 332 + // TODO: This code is no longer reachable, and has moved to 333 + // CommandImplementation subclasses. 334 + 332 335 $action = $command->getCommand(); 333 336 switch ($action) { 334 337 case 'sync':
-40
src/applications/nuance/item/NuanceItemType.php
··· 106 106 return $this->newWorkCommands($item); 107 107 } 108 108 109 - final public function applyCommand( 110 - NuanceItem $item, 111 - NuanceItemCommand $command) { 112 - 113 - $result = $this->handleCommand($item, $command); 114 - 115 - if ($result === null) { 116 - return; 117 - } 118 - 119 - $xaction = id(new NuanceItemTransaction()) 120 - ->setTransactionType(NuanceItemCommandTransaction::TRANSACTIONTYPE) 121 - ->setNewValue( 122 - array( 123 - 'command' => $command->getCommand(), 124 - 'parameters' => $command->getParameters(), 125 - 'result' => $result, 126 - )); 127 - 128 - $viewer = $this->getViewer(); 129 - 130 - // TODO: Maybe preserve the actor's original content source? 131 - $source = PhabricatorContentSource::newForSource( 132 - PhabricatorDaemonContentSource::SOURCECONST); 133 - 134 - $editor = id(new NuanceItemEditor()) 135 - ->setActor($viewer) 136 - ->setActingAsPHID($command->getAuthorPHID()) 137 - ->setContentSource($source) 138 - ->setContinueOnMissingFields(true) 139 - ->setContinueOnNoEffect(true) 140 - ->applyTransactions($item, array($xaction)); 141 - } 142 - 143 - protected function handleCommand( 144 - NuanceItem $item, 145 - NuanceItemCommand $command) { 146 - return null; 147 - } 148 - 149 109 final protected function newContentSource( 150 110 NuanceItem $item, 151 111 $agent_phid) {
-1
src/applications/nuance/storage/NuanceItem.php
··· 9 9 const STATUS_IMPORTING = 'importing'; 10 10 const STATUS_ROUTING = 'routing'; 11 11 const STATUS_OPEN = 'open'; 12 - const STATUS_ASSIGNED = 'assigned'; 13 12 const STATUS_CLOSED = 'closed'; 14 13 15 14 protected $status;
+17 -1
src/applications/nuance/worker/NuanceItemUpdateWorker.php
··· 68 68 ->execute(); 69 69 $commands = msort($commands, 'getID'); 70 70 71 + $executors = NuanceCommandImplementation::getAllCommands(); 71 72 foreach ($commands as $command) { 72 73 $command 73 74 ->setStatus(NuanceItemCommand::STATUS_EXECUTING) 74 75 ->save(); 75 76 76 77 try { 77 - $impl->applyCommand($item, $command); 78 + $command_key = $command->getCommand(); 79 + 80 + $executor = idx($executors, $command_key); 81 + if (!$executor) { 82 + throw new Exception( 83 + pht( 84 + 'Unable to execute command "%s": this command does not have '. 85 + 'a recognized command implementation.', 86 + $command_key)); 87 + } 88 + 89 + $executor = clone $executor; 90 + 91 + $executor 92 + ->setActor($viewer) 93 + ->applyCommand($item, $command); 78 94 79 95 $command 80 96 ->setStatus(NuanceItemCommand::STATUS_DONE)
+6 -6
src/applications/nuance/xaction/NuanceItemCommandTransaction.php
··· 9 9 return null; 10 10 } 11 11 12 - public function applyInternalEffects($object, $value) { 13 - // TODO: Probably implement this. 14 - } 15 - 16 12 public function getTitle() { 13 + $spec = $this->getNewValue(); 14 + $command_key = idx($spec, 'command', '???'); 15 + 17 16 return pht( 18 - '%s applied a command to this item.', 19 - $this->renderAuthor()); 17 + '%s applied a "%s" command to this item.', 18 + $this->renderAuthor(), 19 + $command_key); 20 20 } 21 21 22 22 }
+25
src/applications/nuance/xaction/NuanceItemStatusTransaction.php
··· 1 + <?php 2 + 3 + final class NuanceItemStatusTransaction 4 + extends NuanceItemTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'nuance.item.status'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getStatus(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setStatus($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s changed the status of this item from %s to %s.', 19 + $this->renderAuthor(), 20 + $this->renderOldValue(), 21 + $this->renderNewValue()); 22 + } 23 + 24 + 25 + }