@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<?php
2
3final class PhortuneAccountEmailAddressTransaction
4 extends PhortuneAccountEmailTransactionType {
5
6 const TRANSACTIONTYPE = 'address';
7
8 public function generateOldValue($object) {
9 return $object->getAddress();
10 }
11
12 public function applyInternalEffects($object, $value) {
13 $object->setAddress($value);
14 }
15
16 public function validateTransactions($object, array $xactions) {
17 $errors = array();
18
19 if ($this->isEmptyTextTransaction($object->getAddress(), $xactions)) {
20 $errors[] = $this->newRequiredError(
21 pht('You must provide an email address.'));
22 }
23
24 $max_length = $object->getColumnMaximumByteLength('address');
25 foreach ($xactions as $xaction) {
26 $old_value = $xaction->getOldValue();
27 $new_value = $xaction->getNewValue();
28
29 $new_length = strlen($new_value);
30 if ($new_length > $max_length) {
31 $errors[] = $this->newInvalidError(
32 pht(
33 'The address can be no longer than %s characters.',
34 new PhutilNumber($max_length)),
35 $xaction);
36 continue;
37 }
38
39 if (!PhabricatorUserEmail::isValidAddress($new_value)) {
40 $errors[] = $this->newInvalidError(
41 PhabricatorUserEmail::describeValidAddresses(),
42 $xaction);
43 continue;
44 }
45
46 if ($new_value !== $old_value) {
47 if (!$this->isNewObject()) {
48 $errors[] = $this->newInvalidError(
49 pht(
50 'Account email addresses can not be edited once they are '.
51 'created. To change the billing address for an account, '.
52 'disable the old address and then add a new address.'),
53 $xaction);
54 continue;
55 }
56 }
57
58 }
59
60 return $errors;
61 }
62
63}