Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F470472
AlmanacBindingInterfaceTransaction.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
AlmanacBindingInterfaceTransaction.php
View Options
<?php
final
class
AlmanacBindingInterfaceTransaction
extends
AlmanacBindingTransactionType
{
const
TRANSACTIONTYPE
=
'almanac:binding:interface'
;
public
function
generateOldValue
(
$object
)
{
return
$object
->
getInterfacePHID
();
}
public
function
applyInternalEffects
(
$object
,
$value
)
{
$interface
=
$this
->
loadInterface
(
$value
);
$object
->
setDevicePHID
(
$interface
->
getDevicePHID
())
->
setInterfacePHID
(
$interface
->
getPHID
());
}
public
function
applyExternalEffects
(
$object
,
$value
)
{
// When we change which services a device is bound to, we need to
// recalculate whether it is a cluster device or not so we can tell if
// the "Can Manage Cluster Services" permission applies to it.
$viewer
=
PhabricatorUser
::
getOmnipotentUser
();
$interface_phids
=
array
();
$interface_phids
[]
=
$this
->
getOldValue
();
$interface_phids
[]
=
$this
->
getNewValue
();
$interface_phids
=
array_filter
(
$interface_phids
);
$interface_phids
=
array_unique
(
$interface_phids
);
$interfaces
=
id
(
new
AlmanacInterfaceQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
$interface_phids
)
->
execute
();
$device_phids
=
array
();
foreach
(
$interfaces
as
$interface
)
{
$device_phids
[]
=
$interface
->
getDevicePHID
();
}
$device_phids
=
array_unique
(
$device_phids
);
$devices
=
id
(
new
AlmanacDeviceQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
$device_phids
)
->
execute
();
foreach
(
$devices
as
$device
)
{
$device
->
rebuildClusterBindingStatus
();
}
}
public
function
getTitle
()
{
return
pht
(
'%s changed the interface for this binding from %s to %s.'
,
$this
->
renderAuthor
(),
$this
->
renderOldHandle
(),
$this
->
renderNewHandle
());
}
public
function
validateTransactions
(
$object
,
array
$xactions
)
{
$errors
=
array
();
$interface_phid
=
$object
->
getInterfacePHID
();
if
(
$this
->
isEmptyTextTransaction
(
$interface_phid
,
$xactions
))
{
$errors
[]
=
$this
->
newRequiredError
(
pht
(
'Bindings must specify an interface.'
));
}
foreach
(
$xactions
as
$xaction
)
{
$interface_phid
=
$xaction
->
getNewValue
();
$interface
=
$this
->
loadInterface
(
$interface_phid
);
if
(!
$interface
)
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'You can not bind a service to an invalid or restricted '
.
'interface.'
),
$xaction
);
continue
;
}
$binding
=
id
(
new
AlmanacBindingQuery
())
->
setViewer
(
PhabricatorUser
::
getOmnipotentUser
())
->
withServicePHIDs
(
array
(
$object
->
getServicePHID
()))
->
withInterfacePHIDs
(
array
(
$interface_phid
))
->
executeOne
();
if
(
$binding
&&
(
$binding
->
getID
()
!=
$object
->
getID
()))
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'You can not bind a service to the same interface multiple '
.
'times.'
),
$xaction
);
continue
;
}
}
return
$errors
;
}
private
function
loadInterface
(
$phid
)
{
return
id
(
new
AlmanacInterfaceQuery
())
->
setViewer
(
$this
->
getActor
())
->
withPHIDs
(
array
(
$phid
))
->
executeOne
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, May 6, 11:01 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
82020
Default Alt Text
AlmanacBindingInterfaceTransaction.php (3 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment