Remove product literal strings in "pht()", part 18
[phabricator.git] / src / applications / herald / xaction / HeraldWebhookURITransaction.php
blobe0162085cbec23dcf3347f65647eee73189ff192
1 <?php
3 final class HeraldWebhookURITransaction
4 extends HeraldWebhookTransactionType {
6 const TRANSACTIONTYPE = 'uri';
8 public function generateOldValue($object) {
9 return $object->getWebhookURI();
12 public function applyInternalEffects($object, $value) {
13 $object->setWebhookURI($value);
16 public function getTitle() {
17 return pht(
18 '%s changed the URI for this webhook from %s to %s.',
19 $this->renderAuthor(),
20 $this->renderOldValue(),
21 $this->renderNewValue());
24 public function getTitleForFeed() {
25 return pht(
26 '%s changed the URI for %s from %s to %s.',
27 $this->renderAuthor(),
28 $this->renderObject(),
29 $this->renderOldValue(),
30 $this->renderNewValue());
33 public function validateTransactions($object, array $xactions) {
34 $errors = array();
35 $viewer = $this->getActor();
37 if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
38 $errors[] = $this->newRequiredError(
39 pht('Webhooks must have a URI.'));
40 return $errors;
43 $max_length = $object->getColumnMaximumByteLength('webhookURI');
44 foreach ($xactions as $xaction) {
45 $old_value = $this->generateOldValue($object);
46 $new_value = $xaction->getNewValue();
48 $new_length = strlen($new_value);
49 if ($new_length > $max_length) {
50 $errors[] = $this->newInvalidError(
51 pht(
52 'Webhook URIs can be no longer than %s characters.',
53 new PhutilNumber($max_length)),
54 $xaction);
57 try {
58 PhabricatorEnv::requireValidRemoteURIForFetch(
59 $new_value,
60 array(
61 'http',
62 'https',
63 ));
64 } catch (Exception $ex) {
65 $errors[] = $this->newInvalidError(
66 $ex->getMessage(),
67 $xaction);
71 return $errors;