Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91622852
AlmanacInterfaceDeviceTransaction.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
Tue, Nov 12, 20:18
Size
1 KB
Mime Type
text/x-php
Expires
Thu, Nov 14, 20:18 (2 d)
Engine
blob
Format
Raw Data
Handle
22291041
Attached To
rPH Phabricator
AlmanacInterfaceDeviceTransaction.php
View Options
<?php
final
class
AlmanacInterfaceDeviceTransaction
extends
AlmanacInterfaceTransactionType
{
const
TRANSACTIONTYPE
=
'almanac:interface:device'
;
public
function
generateOldValue
(
$object
)
{
return
$object
->
getDevicePHID
();
}
public
function
applyInternalEffects
(
$object
,
$value
)
{
$object
->
setDevicePHID
(
$value
);
}
public
function
getTitle
()
{
return
pht
(
'%s changed the device for this interface from %s to %s.'
,
$this
->
renderAuthor
(),
$this
->
renderOldHandle
(),
$this
->
renderNewHandle
());
}
public
function
validateTransactions
(
$object
,
array
$xactions
)
{
$errors
=
array
();
$device_phid
=
$object
->
getDevicePHID
();
if
(
$this
->
isEmptyTextTransaction
(
$device_phid
,
$xactions
))
{
$errors
[]
=
$this
->
newRequiredError
(
pht
(
'Interfaces must have a device.'
));
}
foreach
(
$xactions
as
$xaction
)
{
if
(!
$this
->
isNewObject
())
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'The device for an interface can not be changed once it has '
.
'been created.'
),
$xaction
);
continue
;
}
$device_phid
=
$xaction
->
getNewValue
();
$devices
=
id
(
new
AlmanacDeviceQuery
())
->
setViewer
(
$this
->
getActor
())
->
withPHIDs
(
array
(
$device_phid
))
->
execute
();
if
(!
$devices
)
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'You can not attach an interface to a nonexistent or restricted '
.
'device.'
),
$xaction
);
continue
;
}
$device
=
head
(
$devices
);
$can_edit
=
PhabricatorPolicyFilter
::
hasCapability
(
$this
->
getActor
(),
$device
,
PhabricatorPolicyCapability
::
CAN_EDIT
);
if
(!
$can_edit
)
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'You can not attach an interface to a device which you do not '
.
'have permission to edit.'
));
continue
;
}
}
return
$errors
;
}
}
Event Timeline
Log In to Comment