Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F104768079
PhabricatorAuthContactNumberNumberTransaction.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Mar 12, 05:51
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Mar 14, 05:51 (1 d, 16 h)
Engine
blob
Format
Raw Data
Handle
24857261
Attached To
rPH Phabricator
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
;
}
}
Event Timeline
Log In to Comment