diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ad270ab3f0..9ca28af33c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3052,6 +3052,7 @@ phutil_register_library_map(array( 'PhabricatorProjectInterface', 'PhabricatorSSHPublicKeyInterface', 'AlmanacPropertyInterface', + 'PhabricatorDestructibleInterface', ), 'AlmanacDeviceController' => 'AlmanacController', 'AlmanacDeviceEditController' => 'AlmanacDeviceController', @@ -3066,6 +3067,7 @@ phutil_register_library_map(array( 'AlmanacInterface' => array( 'AlmanacDAO', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource', 'AlmanacInterfaceEditController' => 'AlmanacDeviceController', @@ -3083,6 +3085,7 @@ phutil_register_library_map(array( 'AlmanacDAO', 'PhabricatorApplicationTransactionInterface', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'AlmanacNetworkController' => 'AlmanacController', 'AlmanacNetworkEditController' => 'AlmanacNetworkController', @@ -3112,6 +3115,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionInterface', 'PhabricatorProjectInterface', 'AlmanacPropertyInterface', + 'PhabricatorDestructibleInterface', ), 'AlmanacServiceController' => 'AlmanacController', 'AlmanacServiceDatasource' => 'PhabricatorTypeaheadDatasource', diff --git a/src/applications/almanac/editor/AlmanacDeviceEditor.php b/src/applications/almanac/editor/AlmanacDeviceEditor.php index faddb7da9d..98f7604fb4 100644 --- a/src/applications/almanac/editor/AlmanacDeviceEditor.php +++ b/src/applications/almanac/editor/AlmanacDeviceEditor.php @@ -94,8 +94,13 @@ final class AlmanacDeviceEditor $interface ->setNetworkPHID($new['networkPHID']) ->setAddress($new['address']) - ->setPort((int)$new['port']) - ->save(); + ->setPort((int)$new['port']); + + if (idx($new, 'phid')) { + $interface->setPHID($new['phid']); + } + + $interface->save(); } else { $interface->delete(); } @@ -210,6 +215,21 @@ final class AlmanacDeviceEditor $xaction); $errors[] = $error; } + + $phid = idx($new, 'phid'); + if ($phid) { + $interface_phid_type = AlmanacInterfacePHIDType::TYPECONST; + if (phid_get_type($phid) !== $interface_phid_type) { + $error = new PhabricatorApplicationTransactionValidationError( + $type, + pht('Invalid'), + pht( + 'Precomputed interface PHIDs must be of type '. + 'AlmanacInterfacePHIDType.'), + $xaction); + $errors[] = $error; + } + } } } diff --git a/src/applications/almanac/query/AlmanacDeviceQuery.php b/src/applications/almanac/query/AlmanacDeviceQuery.php index b5e797849b..bd1797088f 100644 --- a/src/applications/almanac/query/AlmanacDeviceQuery.php +++ b/src/applications/almanac/query/AlmanacDeviceQuery.php @@ -6,7 +6,8 @@ final class AlmanacDeviceQuery private $ids; private $phids; private $names; - private $datasourceQuery; + private $namePrefix; + private $nameSuffix; public function withIDs(array $ids) { $this->ids = $ids; @@ -23,8 +24,13 @@ final class AlmanacDeviceQuery return $this; } - public function withDatasourceQuery($query) { - $this->datasourceQuery = $query; + public function withNamePrefix($prefix) { + $this->namePrefix = $prefix; + return $this; + } + + public function withNameSuffix($suffix) { + $this->nameSuffix = $suffix; return $this; } @@ -71,11 +77,18 @@ final class AlmanacDeviceQuery $hashes); } - if ($this->datasourceQuery !== null) { + if ($this->namePrefix !== null) { $where[] = qsprintf( $conn_r, 'name LIKE %>', - $this->datasourceQuery); + $this->namePrefix); + } + + if ($this->nameSuffix !== null) { + $where[] = qsprintf( + $conn_r, + 'name LIKE %<', + $this->nameSuffix); } $where[] = $this->buildPagingClause($conn_r); diff --git a/src/applications/almanac/storage/AlmanacDevice.php b/src/applications/almanac/storage/AlmanacDevice.php index f4cd907f8b..8075674831 100644 --- a/src/applications/almanac/storage/AlmanacDevice.php +++ b/src/applications/almanac/storage/AlmanacDevice.php @@ -8,7 +8,8 @@ final class AlmanacDevice PhabricatorApplicationTransactionInterface, PhabricatorProjectInterface, PhabricatorSSHPublicKeyInterface, - AlmanacPropertyInterface { + AlmanacPropertyInterface, + PhabricatorDestructibleInterface { protected $name; protected $nameIndex; @@ -232,4 +233,21 @@ final class AlmanacDevice } +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + + $interfaces = id(new AlmanacInterfaceQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withDevicePHIDs(array($this->getPHID())) + ->execute(); + foreach ($interfaces as $interface) { + $engine->destroyObject($interface); + } + + $this->delete(); + } + } diff --git a/src/applications/almanac/storage/AlmanacInterface.php b/src/applications/almanac/storage/AlmanacInterface.php index 725dadaaa2..16cd09c46d 100644 --- a/src/applications/almanac/storage/AlmanacInterface.php +++ b/src/applications/almanac/storage/AlmanacInterface.php @@ -2,7 +2,9 @@ final class AlmanacInterface extends AlmanacDAO - implements PhabricatorPolicyInterface { + implements + PhabricatorPolicyInterface, + PhabricatorDestructibleInterface { protected $devicePHID; protected $networkPHID; @@ -109,4 +111,22 @@ final class AlmanacInterface return $notes; } + +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + + $bindings = id(new AlmanacBindingQuery()) + ->setViewer($this->getViewer()) + ->withInterfacePHIDs(array($this->getPHID())) + ->execute(); + foreach ($bindings as $binding) { + $engine->destroyObject($binding); + } + + $this->delete(); + } + } diff --git a/src/applications/almanac/storage/AlmanacNetwork.php b/src/applications/almanac/storage/AlmanacNetwork.php index fc49fe7823..3a1e1cb632 100644 --- a/src/applications/almanac/storage/AlmanacNetwork.php +++ b/src/applications/almanac/storage/AlmanacNetwork.php @@ -4,7 +4,8 @@ final class AlmanacNetwork extends AlmanacDAO implements PhabricatorApplicationTransactionInterface, - PhabricatorPolicyInterface { + PhabricatorPolicyInterface, + PhabricatorDestructibleInterface { protected $name; protected $mailKey; @@ -94,4 +95,23 @@ final class AlmanacNetwork return null; } + +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + + $interfaces = id(new AlmanacInterfaceQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withNetworkPHIDs(array($this->getPHID())) + ->execute(); + + foreach ($interfaces as $interface) { + $engine->destroyObject($interface); + } + + $this->delete(); + } + } diff --git a/src/applications/almanac/storage/AlmanacService.php b/src/applications/almanac/storage/AlmanacService.php index dcfda6cfd9..349fbca204 100644 --- a/src/applications/almanac/storage/AlmanacService.php +++ b/src/applications/almanac/storage/AlmanacService.php @@ -7,7 +7,8 @@ final class AlmanacService PhabricatorCustomFieldInterface, PhabricatorApplicationTransactionInterface, PhabricatorProjectInterface, - AlmanacPropertyInterface { + AlmanacPropertyInterface, + PhabricatorDestructibleInterface { protected $name; protected $nameIndex; @@ -212,4 +213,22 @@ final class AlmanacService return $timeline; } + +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + + $bindings = id(new AlmanacBindingQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withServicePHIDs(array($this->getPHID())) + ->execute(); + foreach ($bindings as $binding) { + $engine->destroyObject($binding); + } + + $this->delete(); + } + } diff --git a/src/applications/almanac/typeahead/AlmanacInterfaceDatasource.php b/src/applications/almanac/typeahead/AlmanacInterfaceDatasource.php index 4a3053d357..3609cb06f6 100644 --- a/src/applications/almanac/typeahead/AlmanacInterfaceDatasource.php +++ b/src/applications/almanac/typeahead/AlmanacInterfaceDatasource.php @@ -17,7 +17,7 @@ final class AlmanacInterfaceDatasource $devices = id(new AlmanacDeviceQuery()) ->setViewer($viewer) - ->withDatasourceQuery($raw_query) + ->withNamePrefix($raw_query) ->execute(); if ($devices) {