Path: blob/master/src/applications/differential/xaction/DifferentialRevisionAuthorTransaction.php
12256 views
<?php12final class DifferentialRevisionAuthorTransaction3extends DifferentialRevisionTransactionType {45const TRANSACTIONTYPE = 'differential.revision.author';6const EDITKEY = 'author';78public function generateOldValue($object) {9return $object->getAuthorPHID();10}1112public function generateNewValue($object, $value) {13return $value;14}1516public function applyInternalEffects($object, $value) {17$object->setAuthorPHID($value);18}1920public function validateTransactions($object, array $xactions) {21$actor = $this->getActor();22$errors = array();2324if (!$xactions) {25return $errors;26}2728foreach ($xactions as $xaction) {29$old = $xaction->generateOldValue($object);30$new = $xaction->getNewValue();3132if ($old === $new) {33continue;34}3536if (!$new) {37$errors[] = $this->newInvalidError(38pht('Revisions must have an assigned author.'),39$xaction);40continue;41}4243$author_objects = id(new PhabricatorPeopleQuery())44->setViewer($actor)45->withPHIDs(array($new))46->execute();47if (!$author_objects) {48$errors[] = $this->newInvalidError(49pht('Author "%s" is not a valid user.', $new),50$xaction);51continue;52}53}5455return $errors;56}5758public function getIcon() {59$author_phid = $this->getAuthorPHID();60$old_phid = $this->getOldValue();61$new_phid = $this->getNewValue();6263$is_commandeer = ($author_phid === $new_phid);64$is_foist = ($author_phid === $old_phid);6566if ($is_commandeer) {67return 'fa-flag';68}6970if ($is_foist) {71return 'fa-gift';72}7374return 'fa-user';75}7677public function getColor() {78return 'sky';79}8081public function getTitle() {82$author_phid = $this->getAuthorPHID();83$old_phid = $this->getOldValue();84$new_phid = $this->getNewValue();8586$is_commandeer = ($author_phid === $new_phid);87$is_foist = ($author_phid === $old_phid);8889if ($is_commandeer) {90return pht(91'%s commandeered this revision from %s.',92$this->renderAuthor(),93$this->renderOldHandle());94}9596if ($is_foist) {97if ($new_phid) {98return pht(99'%s foisted this revision upon %s.',100$this->renderAuthor(),101$this->renderNewHandle());102} else {103104// This isn't a valid transaction that can be applied, but happens in105// the preview if you temporarily delete the tokenizer value.106107return pht(108'%s foisted this revision upon...',109$this->renderAuthor());110}111}112113return pht(114'%s changed the author of this revision from %s to %s.',115$this->renderAuthor(),116$this->renderOldHandle(),117$this->renderNewHandle());118}119120public function getTitleForFeed() {121$author_phid = $this->getAuthorPHID();122$old_phid = $this->getOldValue();123$new_phid = $this->getNewValue();124125$is_commandeer = ($author_phid === $new_phid);126$is_foist = ($author_phid === $old_phid);127128if ($is_commandeer) {129return pht(130'%s commandeered %s from %s.',131$this->renderAuthor(),132$this->renderObject(),133$this->renderOldHandle());134}135136if ($is_foist) {137return pht(138'%s foisted %s upon %s.',139$this->renderAuthor(),140$this->renderObject(),141$this->renderNewHandle());142}143144return pht(145'%s changed the author of %s from %s to %s.',146$this->renderAuthor(),147$this->renderObject(),148$this->renderOldHandle(),149$this->renderNewHandle());150151}152153public function getTransactionTypeForConduit($xaction) {154return 'author';155}156157public function getFieldValuesForConduit($object, $data) {158return array(159'old' => $object->getOldValue(),160'new' => $object->getNewValue(),161);162}163164}165166167