@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 95 lines 2.6 kB view raw
1<?php 2 3final class PhameBlogFullDomainTransaction 4 extends PhameBlogTransactionType { 5 6 const TRANSACTIONTYPE = 'phame.blog.full.domain'; 7 8 public function generateOldValue($object) { 9 return $object->getDomainFullURI(); 10 } 11 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); 19 } 20 $object->setDomainFullURI($value); 21 } 22 23 public function getTitle() { 24 $old = $this->getOldValue(); 25 if (!phutil_nonempty_string($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()); 36 } 37 } 38 39 public function getTitleForFeed() { 40 $old = $this->getOldValue(); 41 if (!phutil_nonempty_string($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()); 54 } 55 } 56 57 public function validateTransactions($object, array $xactions) { 58 $errors = array(); 59 60 if (!$xactions) { 61 return $errors; 62 } 63 64 $custom_domain = last($xactions)->getNewValue(); 65 if (empty($custom_domain)) { 66 return $errors; 67 } 68 69 $error_text = $object->validateCustomDomain($custom_domain); 70 if ($error_text) { 71 $errors[] = $this->newInvalidError($error_text); 72 } 73 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())); 79 } 80 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.')); 90 } 91 92 return $errors; 93 } 94 95}