3 final class AlmanacDeviceNameTransaction
4 extends AlmanacDeviceTransactionType
{
6 const TRANSACTIONTYPE
= 'almanac:device:name';
8 public function generateOldValue($object) {
9 return $object->getName();
12 public function applyInternalEffects($object, $value) {
13 $object->setName($value);
16 public function getTitle() {
18 '%s renamed this device from %s to %s.',
19 $this->renderAuthor(),
20 $this->renderOldValue(),
21 $this->renderNewValue());
24 public function validateTransactions($object, array $xactions) {
27 if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
28 $errors[] = $this->newRequiredError(
29 pht('Device name is required.'));
32 foreach ($xactions as $xaction) {
33 $name = $xaction->getNewValue();
37 AlmanacNames
::validateName($name);
38 } catch (Exception
$ex) {
39 $message = $ex->getMessage();
42 if ($message !== null) {
43 $errors[] = $this->newInvalidError($message, $xaction);
47 if ($name === $object->getName()) {
51 $other = id(new AlmanacDeviceQuery())
52 ->setViewer(PhabricatorUser
::getOmnipotentUser())
53 ->withNames(array($name))
55 if ($other && ($other->getID() != $object->getID())) {
56 $errors[] = $this->newInvalidError(
57 pht('Almanac devices must have unique names.'),
62 $namespace = AlmanacNamespace
::loadRestrictedNamespace(
66 $errors[] = $this->newInvalidError(
68 'You do not have permission to create Almanac devices '.
69 'within the "%s" namespace.',
70 $namespace->getName()),