diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -60,6 +60,7 @@ '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 @@ 'AlmanacInterfaceAddressTransaction' => 'AlmanacInterfaceTransactionType', 'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource', 'AlmanacInterfaceDeleteController' => 'AlmanacDeviceController', + 'AlmanacInterfaceDestroyTransaction' => 'AlmanacInterfaceTransactionType', 'AlmanacInterfaceDeviceTransaction' => 'AlmanacInterfaceTransactionType', 'AlmanacInterfaceEditController' => 'AlmanacDeviceController', 'AlmanacInterfaceEditEngine' => 'PhabricatorEditEngine', diff --git a/src/applications/almanac/controller/AlmanacInterfaceDeleteController.php b/src/applications/almanac/controller/AlmanacInterfaceDeleteController.php --- a/src/applications/almanac/controller/AlmanacInterfaceDeleteController.php +++ b/src/applications/almanac/controller/AlmanacInterfaceDeleteController.php @@ -34,26 +34,21 @@ } 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); } diff --git a/src/applications/almanac/xaction/AlmanacInterfaceDestroyTransaction.php b/src/applications/almanac/xaction/AlmanacInterfaceDestroyTransaction.php new file mode 100644 --- /dev/null +++ b/src/applications/almanac/xaction/AlmanacInterfaceDestroyTransaction.php @@ -0,0 +1,32 @@ +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; + } + +}