@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+40 -11
+2
src/__phutil_library_map__.php
··· 60 60 'AlmanacInterfaceAddressTransaction' => 'applications/almanac/xaction/AlmanacInterfaceAddressTransaction.php', 61 61 'AlmanacInterfaceDatasource' => 'applications/almanac/typeahead/AlmanacInterfaceDatasource.php', 62 62 'AlmanacInterfaceDeleteController' => 'applications/almanac/controller/AlmanacInterfaceDeleteController.php', 63 + 'AlmanacInterfaceDestroyTransaction' => 'applications/almanac/xaction/AlmanacInterfaceDestroyTransaction.php', 63 64 'AlmanacInterfaceDeviceTransaction' => 'applications/almanac/xaction/AlmanacInterfaceDeviceTransaction.php', 64 65 'AlmanacInterfaceEditController' => 'applications/almanac/controller/AlmanacInterfaceEditController.php', 65 66 'AlmanacInterfaceEditEngine' => 'applications/almanac/editor/AlmanacInterfaceEditEngine.php', ··· 5256 5257 'AlmanacInterfaceAddressTransaction' => 'AlmanacInterfaceTransactionType', 5257 5258 'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource', 5258 5259 'AlmanacInterfaceDeleteController' => 'AlmanacDeviceController', 5260 + 'AlmanacInterfaceDestroyTransaction' => 'AlmanacInterfaceTransactionType', 5259 5261 'AlmanacInterfaceDeviceTransaction' => 'AlmanacInterfaceTransactionType', 5260 5262 'AlmanacInterfaceEditController' => 'AlmanacDeviceController', 5261 5263 'AlmanacInterfaceEditEngine' => 'PhabricatorEditEngine',
+6 -11
src/applications/almanac/controller/AlmanacInterfaceDeleteController.php
··· 34 34 } 35 35 36 36 if ($request->isFormPost()) { 37 - $type_interface = AlmanacDeviceTransaction::TYPE_INTERFACE; 37 + $type_destroy = AlmanacInterfaceDestroyTransaction::TRANSACTIONTYPE; 38 38 39 39 $xactions = array(); 40 40 41 - $v_old = array( 42 - 'id' => $interface->getID(), 43 - ) + $interface->toAddress()->toDictionary(); 41 + $xactions[] = $interface->getApplicationTransactionTemplate() 42 + ->setTransactionType($type_destroy) 43 + ->setNewValue(true); 44 44 45 - $xactions[] = id(new AlmanacDeviceTransaction()) 46 - ->setTransactionType($type_interface) 47 - ->setOldValue($v_old) 48 - ->setNewValue(null); 49 - 50 - $editor = id(new AlmanacDeviceEditor()) 45 + $editor = id(new AlmanacInterfaceEditor()) 51 46 ->setActor($viewer) 52 47 ->setContentSourceFromRequest($request) 53 48 ->setContinueOnNoEffect(true) 54 49 ->setContinueOnMissingFields(true); 55 50 56 - $editor->applyTransactions($device, $xactions); 51 + $editor->applyTransactions($interface, $xactions); 57 52 58 53 return id(new AphrontRedirectResponse())->setURI($device_uri); 59 54 }
+32
src/applications/almanac/xaction/AlmanacInterfaceDestroyTransaction.php
··· 1 + <?php 2 + 3 + final class AlmanacInterfaceDestroyTransaction 4 + extends AlmanacInterfaceTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'almanac:interface:destroy'; 7 + 8 + public function generateOldValue($object) { 9 + return false; 10 + } 11 + 12 + public function applyExternalEffects($object, $value) { 13 + id(new PhabricatorDestructionEngine()) 14 + ->destroyObject($object); 15 + } 16 + 17 + public function validateTransactions($object, array $xactions) { 18 + $errors = array(); 19 + 20 + if ($xactions) { 21 + if ($object->loadIsInUse()) { 22 + $errors[] = $this->newInvalidError( 23 + pht( 24 + 'You can not delete this interface because it is currently in '. 25 + 'use. One or more services are bound to it.')); 26 + } 27 + } 28 + 29 + return $errors; 30 + } 31 + 32 + }