3 abstract class NuanceCommandImplementation
8 private $transactionQueue = array();
10 final public function setActor(PhabricatorUser
$actor) {
11 $this->actor
= $actor;
15 final public function getActor() {
19 abstract public function getCommandName();
20 abstract public function canApplyToItem(NuanceItem
$item);
22 public function canApplyImmediately(
24 NuanceItemCommand
$command) {
28 abstract protected function executeCommand(
30 NuanceItemCommand
$command);
32 final public function applyCommand(
34 NuanceItemCommand
$command) {
36 $command_key = $command->getCommand();
37 $implementation_key = $this->getCommandKey();
38 if ($command_key !== $implementation_key) {
41 'This command implementation("%s") can not apply a command of a '.
42 'different type ("%s").',
47 if (!$this->canApplyToItem($item)) {
50 'This command implementation ("%s") can not be applied to an '.
53 $item->getItemType()));
56 $this->transactionQueue
= array();
58 $command_type = NuanceItemCommandTransaction
::TRANSACTIONTYPE
;
59 $command_xaction = $this->newTransaction($command_type);
61 $result = $this->executeCommand($item, $command);
63 $xactions = $this->transactionQueue
;
64 $this->transactionQueue
= array();
66 $command_xaction->setNewValue(
68 'command' => $command->getCommand(),
69 'parameters' => $command->getParameters(),
73 // TODO: Maybe preserve the actor's original content source?
74 $source = PhabricatorContentSource
::newForSource(
75 PhabricatorDaemonContentSource
::SOURCECONST
);
77 $actor = $this->getActor();
79 id(new NuanceItemEditor())
81 ->setActingAsPHID($command->getAuthorPHID())
82 ->setContentSource($source)
83 ->setContinueOnMissingFields(true)
84 ->setContinueOnNoEffect(true)
85 ->applyTransactions($item, $xactions);
88 final public function getCommandKey() {
89 return $this->getPhobjectClassConstant('COMMANDKEY');
92 final public static function getAllCommands() {
93 return id(new PhutilClassMapQuery())
94 ->setAncestorClass(__CLASS__
)
95 ->setUniqueMethod('getCommandKey')
99 protected function newTransaction($type) {
100 $xaction = id(new NuanceItemTransaction())
101 ->setTransactionType($type);
103 $this->transactionQueue
[] = $xaction;
108 protected function newStatusTransaction($status) {
109 return $this->newTransaction(NuanceItemStatusTransaction
::TRANSACTIONTYPE
)
110 ->setNewValue($status);