Path: blob/master/src/applications/almanac/xaction/AlmanacDeviceNameTransaction.php
12256 views
<?php12final class AlmanacDeviceNameTransaction3extends AlmanacDeviceTransactionType {45const TRANSACTIONTYPE = 'almanac:device: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 device from %s to %s.',18$this->renderAuthor(),19$this->renderOldValue(),20$this->renderNewValue());21}2223public function validateTransactions($object, array $xactions) {24$errors = array();2526if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {27$errors[] = $this->newRequiredError(28pht('Device name is required.'));29}3031foreach ($xactions as $xaction) {32$name = $xaction->getNewValue();3334$message = null;35try {36AlmanacNames::validateName($name);37} catch (Exception $ex) {38$message = $ex->getMessage();39}4041if ($message !== null) {42$errors[] = $this->newInvalidError($message, $xaction);43continue;44}4546if ($name === $object->getName()) {47continue;48}4950$other = id(new AlmanacDeviceQuery())51->setViewer(PhabricatorUser::getOmnipotentUser())52->withNames(array($name))53->executeOne();54if ($other && ($other->getID() != $object->getID())) {55$errors[] = $this->newInvalidError(56pht('Almanac devices must have unique names.'),57$xaction);58continue;59}6061$namespace = AlmanacNamespace::loadRestrictedNamespace(62$this->getActor(),63$name);64if ($namespace) {65$errors[] = $this->newInvalidError(66pht(67'You do not have permission to create Almanac devices '.68'within the "%s" namespace.',69$namespace->getName()),70$xaction);71continue;72}73}7475return $errors;76}7778}798081