Path: blob/master/src/applications/herald/xaction/HeraldWebhookURITransaction.php
12256 views
<?php12final class HeraldWebhookURITransaction3extends HeraldWebhookTransactionType {45const TRANSACTIONTYPE = 'uri';67public function generateOldValue($object) {8return $object->getWebhookURI();9}1011public function applyInternalEffects($object, $value) {12$object->setWebhookURI($value);13}1415public function getTitle() {16return pht(17'%s changed the URI for this webhook from %s to %s.',18$this->renderAuthor(),19$this->renderOldValue(),20$this->renderNewValue());21}2223public function getTitleForFeed() {24return pht(25'%s changed the URI for %s from %s to %s.',26$this->renderAuthor(),27$this->renderObject(),28$this->renderOldValue(),29$this->renderNewValue());30}3132public function validateTransactions($object, array $xactions) {33$errors = array();34$viewer = $this->getActor();3536if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {37$errors[] = $this->newRequiredError(38pht('Webhooks must have a URI.'));39return $errors;40}4142$max_length = $object->getColumnMaximumByteLength('webhookURI');43foreach ($xactions as $xaction) {44$old_value = $this->generateOldValue($object);45$new_value = $xaction->getNewValue();4647$new_length = strlen($new_value);48if ($new_length > $max_length) {49$errors[] = $this->newInvalidError(50pht(51'Webhook URIs can be no longer than %s characters.',52new PhutilNumber($max_length)),53$xaction);54}5556try {57PhabricatorEnv::requireValidRemoteURIForFetch(58$new_value,59array(60'http',61'https',62));63} catch (Exception $ex) {64$errors[] = $this->newInvalidError(65$ex->getMessage(),66$xaction);67}68}6970return $errors;71}7273}747576