Path: blob/master/src/applications/almanac/xaction/AlmanacNetworkNameTransaction.php
12256 views
<?php12final class AlmanacNetworkNameTransaction3extends AlmanacNetworkTransactionType {45const TRANSACTIONTYPE = 'almanac:network:name';67public function generateOldValue($object) {8return $object->getName();9}1011public function applyInternalEffects($object, $value) {12$object->setName($value);13}1415public function getTitle() {16return pht(17'%s renamed this network from %s to %s.',18$this->renderAuthor(),19$this->renderOldValue(),20$this->renderNewValue());21}2223public function getTitleForFeed() {24return pht(25'%s renamed %s from %s to %s.',26$this->renderAuthor(),27$this->renderObject(),28$this->renderOldValue(),29$this->renderNewValue());30}3132public function validateTransactions($object, array $xactions) {33$errors = array();3435if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {36$errors[] = $this->newRequiredError(37pht('Network name is required.'));38}3940foreach ($xactions as $xaction) {41$name = $xaction->getNewValue();4243$message = null;44try {45AlmanacNames::validateName($name);46} catch (Exception $ex) {47$message = $ex->getMessage();48}4950if ($message !== null) {51$errors[] = $this->newInvalidError($message, $xaction);52continue;53}5455if ($name === $object->getName()) {56continue;57}5859$other = id(new AlmanacNetworkQuery())60->setViewer(PhabricatorUser::getOmnipotentUser())61->withNames(array($name))62->executeOne();63if ($other && ($other->getID() != $object->getID())) {64$errors[] = $this->newInvalidError(65pht('Almanac networks must have unique names.'),66$xaction);67continue;68}69}7071return $errors;72}7374}757677