Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / xaction / PhabricatorRepositoryCallsignTransaction.php
blobab13c6a57152d3e327c05b3835c6fd65df95848a
1 <?php
3 final class PhabricatorRepositoryCallsignTransaction
4 extends PhabricatorRepositoryTransactionType {
6 const TRANSACTIONTYPE = 'repo:callsign';
8 public function generateOldValue($object) {
9 return $object->getCallsign();
12 public function generateNewValue($object, $value) {
13 if (strlen($value)) {
14 return $value;
17 return null;
20 public function applyInternalEffects($object, $value) {
21 $object->setCallsign($value);
24 public function getTitle() {
25 $old = $this->getOldValue();
26 $new = $this->getNewValue();
28 if (!strlen($old)) {
29 return pht(
30 '%s set the callsign for this repository to %s.',
31 $this->renderAuthor(),
32 $this->renderNewValue());
33 } else if (!strlen($new)) {
34 return pht(
35 '%s removed the callsign (%s) for this repository.',
36 $this->renderAuthor(),
37 $this->renderOldValue());
38 } else {
39 return pht(
40 '%s changed the callsign for this repository from %s to %s.',
41 $this->renderAuthor(),
42 $this->renderOldValue(),
43 $this->renderNewValue());
47 public function validateTransactions($object, array $xactions) {
48 $errors = array();
50 foreach ($xactions as $xaction) {
51 $old = $xaction->getOldValue();
52 $new = $xaction->getNewValue();
54 if (!strlen($new)) {
55 continue;
58 if ($new === $old) {
59 continue;
62 try {
63 PhabricatorRepository::assertValidCallsign($new);
64 } catch (Exception $ex) {
65 $errors[] = $this->newInvalidError(
66 $ex->getMessage(),
67 $xaction);
68 continue;
71 $other = id(new PhabricatorRepositoryQuery())
72 ->setViewer(PhabricatorUser::getOmnipotentUser())
73 ->withCallsigns(array($new))
74 ->executeOne();
75 if ($other && ($other->getID() !== $object->getID())) {
76 $errors[] = $this->newError(
77 pht('Duplicate'),
78 pht(
79 'The selected callsign ("%s") is already in use by another '.
80 'repository. Choose a unique callsign.',
81 $new),
82 $xaction);
83 continue;
87 return $errors;