Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F437151
PhabricatorAuthContactNumberNumberTransaction.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
PhabricatorAuthContactNumberNumberTransaction.php
View Options
<?php
final
class
PhabricatorAuthContactNumberNumberTransaction
extends
PhabricatorAuthContactNumberTransactionType
{
const
TRANSACTIONTYPE
=
'number'
;
public
function
generateOldValue
(
$object
)
{
return
$object
->
getContactNumber
();
}
public
function
generateNewValue
(
$object
,
$value
)
{
$number
=
new
PhabricatorPhoneNumber
(
$value
);
return
$number
->
toE164
();
}
public
function
applyInternalEffects
(
$object
,
$value
)
{
$object
->
setContactNumber
(
$value
);
}
public
function
getTitle
()
{
$old
=
$this
->
getOldValue
();
$new
=
$this
->
getNewValue
();
return
pht
(
'%s changed this contact number from %s to %s.'
,
$this
->
renderAuthor
(),
$this
->
renderOldValue
(),
$this
->
renderNewValue
());
}
public
function
validateTransactions
(
$object
,
array
$xactions
)
{
$errors
=
array
();
$current_value
=
$object
->
getContactNumber
();
if
(
$this
->
isEmptyTextTransaction
(
$current_value
,
$xactions
))
{
$errors
[]
=
$this
->
newRequiredError
(
pht
(
'Contact numbers must have a contact number.'
));
return
$errors
;
}
$max_length
=
$object
->
getColumnMaximumByteLength
(
'contactNumber'
);
foreach
(
$xactions
as
$xaction
)
{
$new_value
=
$xaction
->
getNewValue
();
$new_length
=
strlen
(
$new_value
);
if
(
$new_length
>
$max_length
)
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'Contact numbers can not be longer than %s characters.'
,
new
PhutilNumber
(
$max_length
)),
$xaction
);
continue
;
}
try
{
new
PhabricatorPhoneNumber
(
$new_value
);
}
catch
(
Exception
$ex
)
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'Contact number is invalid: %s'
,
$ex
->
getMessage
()),
$xaction
);
continue
;
}
$new_value
=
$this
->
generateNewValue
(
$object
,
$new_value
);
$unique_key
=
id
(
clone
$object
)
->
setContactNumber
(
$new_value
)
->
newUniqueKey
();
$other
=
id
(
new
PhabricatorAuthContactNumberQuery
())
->
setViewer
(
PhabricatorUser
::
getOmnipotentUser
())
->
withUniqueKeys
(
array
(
$unique_key
))
->
executeOne
();
if
(
$other
)
{
if
(
$other
->
getID
()
!==
$object
->
getID
())
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'Contact number is already in use.'
),
$xaction
);
continue
;
}
}
$mfa_error
=
$this
->
newContactNumberMFAError
(
$object
,
$xaction
);
if
(
$mfa_error
)
{
$errors
[]
=
$mfa_error
;
continue
;
}
}
return
$errors
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, May 4, 12:42 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
63016
Default Alt Text
PhabricatorAuthContactNumberNumberTransaction.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment