Path: blob/master/src/applications/auth/xaction/PhabricatorAuthContactNumberNumberTransaction.php
12256 views
<?php12final class PhabricatorAuthContactNumberNumberTransaction3extends PhabricatorAuthContactNumberTransactionType {45const TRANSACTIONTYPE = 'number';67public function generateOldValue($object) {8return $object->getContactNumber();9}1011public function generateNewValue($object, $value) {12$number = new PhabricatorPhoneNumber($value);13return $number->toE164();14}1516public function applyInternalEffects($object, $value) {17$object->setContactNumber($value);18}1920public function getTitle() {21$old = $this->getOldValue();22$new = $this->getNewValue();2324return pht(25'%s changed this contact number from %s to %s.',26$this->renderAuthor(),27$this->renderOldValue(),28$this->renderNewValue());29}3031public function validateTransactions($object, array $xactions) {32$errors = array();3334$current_value = $object->getContactNumber();35if ($this->isEmptyTextTransaction($current_value, $xactions)) {36$errors[] = $this->newRequiredError(37pht('Contact numbers must have a contact number.'));38return $errors;39}4041$max_length = $object->getColumnMaximumByteLength('contactNumber');42foreach ($xactions as $xaction) {43$new_value = $xaction->getNewValue();44$new_length = strlen($new_value);45if ($new_length > $max_length) {46$errors[] = $this->newInvalidError(47pht(48'Contact numbers can not be longer than %s characters.',49new PhutilNumber($max_length)),50$xaction);51continue;52}5354try {55new PhabricatorPhoneNumber($new_value);56} catch (Exception $ex) {57$errors[] = $this->newInvalidError(58pht(59'Contact number is invalid: %s',60$ex->getMessage()),61$xaction);62continue;63}6465$new_value = $this->generateNewValue($object, $new_value);6667$unique_key = id(clone $object)68->setContactNumber($new_value)69->newUniqueKey();7071$other = id(new PhabricatorAuthContactNumberQuery())72->setViewer(PhabricatorUser::getOmnipotentUser())73->withUniqueKeys(array($unique_key))74->executeOne();7576if ($other) {77if ($other->getID() !== $object->getID()) {78$errors[] = $this->newInvalidError(79pht('Contact number is already in use.'),80$xaction);81continue;82}83}8485$mfa_error = $this->newContactNumberMFAError($object, $xaction);86if ($mfa_error) {87$errors[] = $mfa_error;88continue;89}90}9192return $errors;93}9495}969798