3 final class PhabricatorAuthContactNumberNumberTransaction
4 extends PhabricatorAuthContactNumberTransactionType
{
6 const TRANSACTIONTYPE
= 'number';
8 public function generateOldValue($object) {
9 return $object->getContactNumber();
12 public function generateNewValue($object, $value) {
13 $number = new PhabricatorPhoneNumber($value);
14 return $number->toE164();
17 public function applyInternalEffects($object, $value) {
18 $object->setContactNumber($value);
21 public function getTitle() {
22 $old = $this->getOldValue();
23 $new = $this->getNewValue();
26 '%s changed this contact number from %s to %s.',
27 $this->renderAuthor(),
28 $this->renderOldValue(),
29 $this->renderNewValue());
32 public function validateTransactions($object, array $xactions) {
35 $current_value = $object->getContactNumber();
36 if ($this->isEmptyTextTransaction($current_value, $xactions)) {
37 $errors[] = $this->newRequiredError(
38 pht('Contact numbers must have a contact number.'));
42 $max_length = $object->getColumnMaximumByteLength('contactNumber');
43 foreach ($xactions as $xaction) {
44 $new_value = $xaction->getNewValue();
45 $new_length = strlen($new_value);
46 if ($new_length > $max_length) {
47 $errors[] = $this->newInvalidError(
49 'Contact numbers can not be longer than %s characters.',
50 new PhutilNumber($max_length)),
56 new PhabricatorPhoneNumber($new_value);
57 } catch (Exception
$ex) {
58 $errors[] = $this->newInvalidError(
60 'Contact number is invalid: %s',
66 $new_value = $this->generateNewValue($object, $new_value);
68 $unique_key = id(clone $object)
69 ->setContactNumber($new_value)
72 $other = id(new PhabricatorAuthContactNumberQuery())
73 ->setViewer(PhabricatorUser
::getOmnipotentUser())
74 ->withUniqueKeys(array($unique_key))
78 if ($other->getID() !== $object->getID()) {
79 $errors[] = $this->newInvalidError(
80 pht('Contact number is already in use.'),
86 $mfa_error = $this->newContactNumberMFAError($object, $xaction);
88 $errors[] = $mfa_error;