Path: blob/master/src/applications/differential/xaction/DifferentialRevisionRepositoryTransaction.php
12256 views
<?php12final class DifferentialRevisionRepositoryTransaction3extends DifferentialRevisionTransactionType {45const TRANSACTIONTYPE = 'differential.revision.repository';67public function generateOldValue($object) {8return $object->getRepositoryPHID();9}1011public function applyInternalEffects($object, $value) {12$object->setRepositoryPHID($value);13}1415public function getTitle() {16$old = $this->getOldValue();17$new = $this->getNewValue();18if ($old && $new) {19return pht(20'%s changed the repository for this revision from %s to %s.',21$this->renderAuthor(),22$this->renderHandle($old),23$this->renderHandle($new));24} else if ($new) {25return pht(26'%s set the repository for this revision to %s.',27$this->renderAuthor(),28$this->renderHandle($new));29} else {30return pht(31'%s removed %s as the repository for this revision.',32$this->renderAuthor(),33$this->renderHandle($old));34}35}3637public function getTitleForFeed() {38$old = $this->getOldValue();39$new = $this->getNewValue();40if ($old && $new) {41return pht(42'%s changed the repository for %s from %s to %s.',43$this->renderAuthor(),44$this->renderObject(),45$this->renderHandle($old),46$this->renderHandle($new));47} else if ($new) {48return pht(49'%s set the repository for %s to %s.',50$this->renderAuthor(),51$this->renderObject(),52$this->renderHandle($new));53} else {54return pht(55'%s removed %s as the repository for %s.',56$this->renderAuthor(),57$this->renderHandle($old),58$this->renderObject());59}60}6162public function validateTransactions($object, array $xactions) {63$actor = $this->getActor();6465$errors = array();6667$old_value = $object->getRepositoryPHID();68foreach ($xactions as $xaction) {69$new_value = $xaction->getNewValue();70if (!$new_value) {71continue;72}7374if ($new_value == $old_value) {75continue;76}7778$repository = id(new PhabricatorRepositoryQuery())79->setViewer($actor)80->withPHIDs(array($new_value))81->executeOne();82if (!$repository) {83$errors[] = $this->newInvalidError(84pht(85'Repository "%s" is not a valid repository, or you do not have '.86'permission to view it.',87$new_value),88$xaction);89}90}9192return $errors;93}9495}969798