Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / phame / xaction / PhameBlogFullDomainTransaction.php
blob5287f9cc062ac46d7a2870bb3cffdb536acb0809
1 <?php
3 final class PhameBlogFullDomainTransaction
4 extends PhameBlogTransactionType {
6 const TRANSACTIONTYPE = 'phame.blog.full.domain';
8 public function generateOldValue($object) {
9 return $object->getDomainFullURI();
12 public function applyInternalEffects($object, $value) {
13 if (strlen($value)) {
14 $uri = new PhutilURI($value);
15 $domain = $uri->getDomain();
16 $object->setDomain($domain);
17 } else {
18 $object->setDomain(null);
20 $object->setDomainFullURI($value);
23 public function getTitle() {
24 $old = $this->getOldValue();
25 if (!strlen($old)) {
26 return pht(
27 '%s set this blog\'s full domain to %s.',
28 $this->renderAuthor(),
29 $this->renderNewValue());
30 } else {
31 return pht(
32 '%s updated the blog\'s full domain from %s to %s.',
33 $this->renderAuthor(),
34 $this->renderOldValue(),
35 $this->renderNewValue());
39 public function getTitleForFeed() {
40 $old = $this->getOldValue();
41 if (!strlen($old)) {
42 return pht(
43 '%s set %s blog\'s full domain to %s.',
44 $this->renderAuthor(),
45 $this->renderObject(),
46 $this->renderNewValue());
47 } else {
48 return pht(
49 '%s updated %s blog\'s full domain from %s to %s.',
50 $this->renderAuthor(),
51 $this->renderObject(),
52 $this->renderOldValue(),
53 $this->renderNewValue());
57 public function validateTransactions($object, array $xactions) {
58 $errors = array();
60 if (!$xactions) {
61 return $errors;
64 $custom_domain = last($xactions)->getNewValue();
65 if (empty($custom_domain)) {
66 return $errors;
69 $error_text = $object->validateCustomDomain($custom_domain);
70 if ($error_text) {
71 $errors[] = $this->newInvalidError($error_text);
74 if ($object->getViewPolicy() != PhabricatorPolicies::POLICY_PUBLIC) {
75 $errors[] = $this->newInvalidError(
76 pht('For custom domains to work, the blog must have a view policy of '.
77 'public. This blog is currently set to "%s".',
78 $object->getViewPolicy()));
81 $domain = new PhutilURI($custom_domain);
82 $domain = $domain->getDomain();
83 $duplicate_blog = id(new PhameBlogQuery())
84 ->setViewer(PhabricatorUser::getOmnipotentUser())
85 ->withDomain($domain)
86 ->executeOne();
87 if ($duplicate_blog && $duplicate_blog->getID() != $object->getID()) {
88 $errors[] = $this->newInvalidError(
89 pht('Domain must be unique; another blog already has this domain.'));
92 return $errors;