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