public function issueCommand($author_phid, $command, array $parameters = array()) { $command = id(NuanceItemCommand::initializeNewCommand())->setItemPHID($this->getPHID())->setAuthorPHID($author_phid)->setCommand($command)->setParameters($parameters)->save(); $this->scheduleUpdate(); return $this; }
private function syncItem(NuanceItem $item, NuanceItemCommand $command) { $xobj_phid = $item->getItemProperty('doorkeeper.xobj.phid'); if (!$xobj_phid) { throw new Exception(pht('Unable to sync: no external object PHID.')); } // TODO: Write some kind of marker to prevent double-synchronization. $viewer = $this->getViewer(); $xobj = id(new DoorkeeperExternalObjectQuery())->setViewer($viewer)->withPHIDs(array($xobj_phid))->executeOne(); if (!$xobj) { throw new Exception(pht('Unable to sync: failed to load object "%s".', $xobj_phid)); } $acting_as_phid = $this->getActingAsPHID($item); $xactions = array(); $task = id(new ManiphestTaskQuery())->setViewer($viewer)->withBridgedObjectPHIDs(array($xobj_phid))->executeOne(); if (!$task) { $task = ManiphestTask::initializeNewTask($viewer)->setAuthorPHID($acting_as_phid)->setBridgedObjectPHID($xobj_phid); $title = $xobj->getProperty('task.title'); if (!strlen($title)) { $title = pht('Nuance Item %d Task', $item->getID()); } $description = $xobj->getProperty('task.description'); $created = $xobj->getProperty('task.created'); $state = $xobj->getProperty('task.state'); $xactions[] = id(new ManiphestTransaction())->setTransactionType(ManiphestTransaction::TYPE_TITLE)->setNewValue($title)->setDateCreated($created); $xactions[] = id(new ManiphestTransaction())->setTransactionType(ManiphestTransaction::TYPE_DESCRIPTION)->setNewValue($description)->setDateCreated($created); $task->setDateCreated($created); // TODO: Synchronize state. } $event = $this->newRawEvent($item); $comment = $event->getComment(); if (strlen($comment)) { $xactions[] = id(new ManiphestTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new ManiphestTransactionComment())->setContent($comment)); } $agent_phid = $command->getAuthorPHID(); $source = $this->newContentSource($item, $agent_phid); $editor = id(new ManiphestTransactionEditor())->setActor($viewer)->setActingAsPHID($acting_as_phid)->setContentSource($source)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true); $xactions = $editor->applyTransactions($task, $xactions); return array('objectPHID' => $task->getPHID(), 'xactionPHIDs' => mpull($xactions, 'getPHID')); }