Page MenuHomePhabricator

D19325.id.diff
No OneTemporary

D19325.id.diff

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

File Metadata

Mime Type
text/plain
Expires
Wed, Mar 19, 2:24 PM (6 d, 16 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7710268
Default Alt Text
D19325.id.diff (3 KB)

Event Timeline