Path: blob/master/src/applications/almanac/xaction/AlmanacNamespaceNameTransaction.php
12256 views
<?php12final class AlmanacNamespaceNameTransaction3extends AlmanacNamespaceTransactionType {45const TRANSACTIONTYPE = 'almanac:namespace: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 namespace 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('Namespace 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 AlmanacNamespaceQuery())60->setViewer(PhabricatorUser::getOmnipotentUser())61->withNames(array($name))62->executeOne();63if ($other && ($other->getID() != $object->getID())) {64$errors[] = $this->newInvalidError(65pht(66'The namespace name "%s" is already in use by another '.67'namespace. Each namespace must have a unique name.',68$name),69$xaction);70continue;71}7273$namespace = AlmanacNamespace::loadRestrictedNamespace(74$this->getActor(),75$name);76if ($namespace) {77$errors[] = $this->newInvalidError(78pht(79'You do not have permission to create Almanac namespaces '.80'within the "%s" namespace.',81$namespace->getName()),82$xaction);83continue;84}85}8687return $errors;88}8990}919293