Path: blob/master/src/applications/almanac/xaction/AlmanacServiceNameTransaction.php
12256 views
<?php12final class AlmanacServiceNameTransaction3extends AlmanacServiceTransactionType {45const TRANSACTIONTYPE = 'almanac:service: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 service 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('Almanac services must have a name.'));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 AlmanacServiceQuery())60->setViewer(PhabricatorUser::getOmnipotentUser())61->withNames(array($name))62->executeOne();63if ($other && ($other->getID() != $object->getID())) {64$errors[] = $this->newInvalidError(65pht('Almanac services must have unique names.'),66$xaction);67continue;68}6970$namespace = AlmanacNamespace::loadRestrictedNamespace(71$this->getActor(),72$name);73if ($namespace) {74$errors[] = $this->newInvalidError(75pht(76'You do not have permission to create Almanac services '.77'within the "%s" namespace.',78$namespace->getName()),79$xaction);80continue;81}82}8384return $errors;85}86}878889