mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 07:12:41 +01:00
Use Interface transactions, not Device transactions, to destroy Interfaces
Summary: Depends on D19324. Ref T13120. Ref T12414. This moves "Destroy Interface" to use Interface transactions instead of Device transactions, so we can ultimately get rid of the complex and difficult-to-modernize `AlmanacDeviceTransaction::TYPE_INTERFACE`. This transaction is a bit weird since it makes the interface delete itself, but this should work OK for now. At some point in the future I'd probably want to change this into more of a "disable" action, but I don't think we face any immediate peril by retaining this behavior for now. Test Plan: - Destroyed interfaces on devices using the web UI, saw them vanish. - Ran daemons, nothing fataled/exploded even though the transaction is weird and destroys the object it affects. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13120, T12414 Differential Revision: https://secure.phabricator.com/D19325
This commit is contained in:
parent
6ccf35f9a2
commit
d240969e47
3 changed files with 40 additions and 11 deletions
|
@ -60,6 +60,7 @@ phutil_register_library_map(array(
|
||||||
'AlmanacInterfaceAddressTransaction' => 'applications/almanac/xaction/AlmanacInterfaceAddressTransaction.php',
|
'AlmanacInterfaceAddressTransaction' => 'applications/almanac/xaction/AlmanacInterfaceAddressTransaction.php',
|
||||||
'AlmanacInterfaceDatasource' => 'applications/almanac/typeahead/AlmanacInterfaceDatasource.php',
|
'AlmanacInterfaceDatasource' => 'applications/almanac/typeahead/AlmanacInterfaceDatasource.php',
|
||||||
'AlmanacInterfaceDeleteController' => 'applications/almanac/controller/AlmanacInterfaceDeleteController.php',
|
'AlmanacInterfaceDeleteController' => 'applications/almanac/controller/AlmanacInterfaceDeleteController.php',
|
||||||
|
'AlmanacInterfaceDestroyTransaction' => 'applications/almanac/xaction/AlmanacInterfaceDestroyTransaction.php',
|
||||||
'AlmanacInterfaceDeviceTransaction' => 'applications/almanac/xaction/AlmanacInterfaceDeviceTransaction.php',
|
'AlmanacInterfaceDeviceTransaction' => 'applications/almanac/xaction/AlmanacInterfaceDeviceTransaction.php',
|
||||||
'AlmanacInterfaceEditController' => 'applications/almanac/controller/AlmanacInterfaceEditController.php',
|
'AlmanacInterfaceEditController' => 'applications/almanac/controller/AlmanacInterfaceEditController.php',
|
||||||
'AlmanacInterfaceEditEngine' => 'applications/almanac/editor/AlmanacInterfaceEditEngine.php',
|
'AlmanacInterfaceEditEngine' => 'applications/almanac/editor/AlmanacInterfaceEditEngine.php',
|
||||||
|
@ -5256,6 +5257,7 @@ phutil_register_library_map(array(
|
||||||
'AlmanacInterfaceAddressTransaction' => 'AlmanacInterfaceTransactionType',
|
'AlmanacInterfaceAddressTransaction' => 'AlmanacInterfaceTransactionType',
|
||||||
'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource',
|
'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||||
'AlmanacInterfaceDeleteController' => 'AlmanacDeviceController',
|
'AlmanacInterfaceDeleteController' => 'AlmanacDeviceController',
|
||||||
|
'AlmanacInterfaceDestroyTransaction' => 'AlmanacInterfaceTransactionType',
|
||||||
'AlmanacInterfaceDeviceTransaction' => 'AlmanacInterfaceTransactionType',
|
'AlmanacInterfaceDeviceTransaction' => 'AlmanacInterfaceTransactionType',
|
||||||
'AlmanacInterfaceEditController' => 'AlmanacDeviceController',
|
'AlmanacInterfaceEditController' => 'AlmanacDeviceController',
|
||||||
'AlmanacInterfaceEditEngine' => 'PhabricatorEditEngine',
|
'AlmanacInterfaceEditEngine' => 'PhabricatorEditEngine',
|
||||||
|
|
|
@ -34,26 +34,21 @@ final class AlmanacInterfaceDeleteController
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$type_interface = AlmanacDeviceTransaction::TYPE_INTERFACE;
|
$type_destroy = AlmanacInterfaceDestroyTransaction::TRANSACTIONTYPE;
|
||||||
|
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
|
|
||||||
$v_old = array(
|
$xactions[] = $interface->getApplicationTransactionTemplate()
|
||||||
'id' => $interface->getID(),
|
->setTransactionType($type_destroy)
|
||||||
) + $interface->toAddress()->toDictionary();
|
->setNewValue(true);
|
||||||
|
|
||||||
$xactions[] = id(new AlmanacDeviceTransaction())
|
$editor = id(new AlmanacInterfaceEditor())
|
||||||
->setTransactionType($type_interface)
|
|
||||||
->setOldValue($v_old)
|
|
||||||
->setNewValue(null);
|
|
||||||
|
|
||||||
$editor = id(new AlmanacDeviceEditor())
|
|
||||||
->setActor($viewer)
|
->setActor($viewer)
|
||||||
->setContentSourceFromRequest($request)
|
->setContentSourceFromRequest($request)
|
||||||
->setContinueOnNoEffect(true)
|
->setContinueOnNoEffect(true)
|
||||||
->setContinueOnMissingFields(true);
|
->setContinueOnMissingFields(true);
|
||||||
|
|
||||||
$editor->applyTransactions($device, $xactions);
|
$editor->applyTransactions($interface, $xactions);
|
||||||
|
|
||||||
return id(new AphrontRedirectResponse())->setURI($device_uri);
|
return id(new AphrontRedirectResponse())->setURI($device_uri);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class AlmanacInterfaceDestroyTransaction
|
||||||
|
extends AlmanacInterfaceTransactionType {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'almanac:interface:destroy';
|
||||||
|
|
||||||
|
public function generateOldValue($object) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyExternalEffects($object, $value) {
|
||||||
|
id(new PhabricatorDestructionEngine())
|
||||||
|
->destroyObject($object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateTransactions($object, array $xactions) {
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
if ($xactions) {
|
||||||
|
if ($object->loadIsInUse()) {
|
||||||
|
$errors[] = $this->newInvalidError(
|
||||||
|
pht(
|
||||||
|
'You can not delete this interface because it is currently in '.
|
||||||
|
'use. One or more services are bound to it.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue