Path: blob/master/src/applications/nuance/command/NuanceCommandImplementation.php
12256 views
<?php12abstract class NuanceCommandImplementation3extends Phobject {45private $actor;67private $transactionQueue = array();89final public function setActor(PhabricatorUser $actor) {10$this->actor = $actor;11return $this;12}1314final public function getActor() {15return $this->actor;16}1718abstract public function getCommandName();19abstract public function canApplyToItem(NuanceItem $item);2021public function canApplyImmediately(22NuanceItem $item,23NuanceItemCommand $command) {24return false;25}2627abstract protected function executeCommand(28NuanceItem $item,29NuanceItemCommand $command);3031final public function applyCommand(32NuanceItem $item,33NuanceItemCommand $command) {3435$command_key = $command->getCommand();36$implementation_key = $this->getCommandKey();37if ($command_key !== $implementation_key) {38throw new Exception(39pht(40'This command implementation("%s") can not apply a command of a '.41'different type ("%s").',42$implementation_key,43$command_key));44}4546if (!$this->canApplyToItem($item)) {47throw new Exception(48pht(49'This command implementation ("%s") can not be applied to an '.50'item of type "%s".',51$implementation_key,52$item->getItemType()));53}5455$this->transactionQueue = array();5657$command_type = NuanceItemCommandTransaction::TRANSACTIONTYPE;58$command_xaction = $this->newTransaction($command_type);5960$result = $this->executeCommand($item, $command);6162$xactions = $this->transactionQueue;63$this->transactionQueue = array();6465$command_xaction->setNewValue(66array(67'command' => $command->getCommand(),68'parameters' => $command->getParameters(),69'result' => $result,70));7172// TODO: Maybe preserve the actor's original content source?73$source = PhabricatorContentSource::newForSource(74PhabricatorDaemonContentSource::SOURCECONST);7576$actor = $this->getActor();7778id(new NuanceItemEditor())79->setActor($actor)80->setActingAsPHID($command->getAuthorPHID())81->setContentSource($source)82->setContinueOnMissingFields(true)83->setContinueOnNoEffect(true)84->applyTransactions($item, $xactions);85}8687final public function getCommandKey() {88return $this->getPhobjectClassConstant('COMMANDKEY');89}9091final public static function getAllCommands() {92return id(new PhutilClassMapQuery())93->setAncestorClass(__CLASS__)94->setUniqueMethod('getCommandKey')95->execute();96}9798protected function newTransaction($type) {99$xaction = id(new NuanceItemTransaction())100->setTransactionType($type);101102$this->transactionQueue[] = $xaction;103104return $xaction;105}106107protected function newStatusTransaction($status) {108return $this->newTransaction(NuanceItemStatusTransaction::TRANSACTIONTYPE)109->setNewValue($status);110}111112}113114115