1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42: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:
epriestley 2018-04-10 06:22:39 -07:00
parent 6ccf35f9a2
commit d240969e47
3 changed files with 40 additions and 11 deletions

View file

@ -60,6 +60,7 @@ phutil_register_library_map(array(
'AlmanacInterfaceAddressTransaction' => 'applications/almanac/xaction/AlmanacInterfaceAddressTransaction.php',
'AlmanacInterfaceDatasource' => 'applications/almanac/typeahead/AlmanacInterfaceDatasource.php',
'AlmanacInterfaceDeleteController' => 'applications/almanac/controller/AlmanacInterfaceDeleteController.php',
'AlmanacInterfaceDestroyTransaction' => 'applications/almanac/xaction/AlmanacInterfaceDestroyTransaction.php',
'AlmanacInterfaceDeviceTransaction' => 'applications/almanac/xaction/AlmanacInterfaceDeviceTransaction.php',
'AlmanacInterfaceEditController' => 'applications/almanac/controller/AlmanacInterfaceEditController.php',
'AlmanacInterfaceEditEngine' => 'applications/almanac/editor/AlmanacInterfaceEditEngine.php',
@ -5256,6 +5257,7 @@ phutil_register_library_map(array(
'AlmanacInterfaceAddressTransaction' => 'AlmanacInterfaceTransactionType',
'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource',
'AlmanacInterfaceDeleteController' => 'AlmanacDeviceController',
'AlmanacInterfaceDestroyTransaction' => 'AlmanacInterfaceTransactionType',
'AlmanacInterfaceDeviceTransaction' => 'AlmanacInterfaceTransactionType',
'AlmanacInterfaceEditController' => 'AlmanacDeviceController',
'AlmanacInterfaceEditEngine' => 'PhabricatorEditEngine',

View file

@ -34,26 +34,21 @@ final class AlmanacInterfaceDeleteController
}
if ($request->isFormPost()) {
$type_interface = AlmanacDeviceTransaction::TYPE_INTERFACE;
$type_destroy = AlmanacInterfaceDestroyTransaction::TRANSACTIONTYPE;
$xactions = array();
$v_old = array(
'id' => $interface->getID(),
) + $interface->toAddress()->toDictionary();
$xactions[] = $interface->getApplicationTransactionTemplate()
->setTransactionType($type_destroy)
->setNewValue(true);
$xactions[] = id(new AlmanacDeviceTransaction())
->setTransactionType($type_interface)
->setOldValue($v_old)
->setNewValue(null);
$editor = id(new AlmanacDeviceEditor())
$editor = id(new AlmanacInterfaceEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);
$editor->applyTransactions($device, $xactions);
$editor->applyTransactions($interface, $xactions);
return id(new AphrontRedirectResponse())->setURI($device_uri);
}

View file

@ -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;
}
}