@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.

Almanac: forced interface PHIDs, prefix/suffix device query, DestructibleInterface

Summary: Ref T5833. Ref T6238. These are general capabilities which are particularly useful for synchronizing cluster specifications to instances.

Test Plan:
- Synchronized networks, devices, interfaces, services, bindings and properties to a managed instance.
- Used typeahead.
- Destroyed networks, devices, and services. Saw interfaces and bindings destroyed.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T6238, T5833

Differential Revision: https://secure.phabricator.com/D11024

+126 -12
+4
src/__phutil_library_map__.php
··· 3052 3052 'PhabricatorProjectInterface', 3053 3053 'PhabricatorSSHPublicKeyInterface', 3054 3054 'AlmanacPropertyInterface', 3055 + 'PhabricatorDestructibleInterface', 3055 3056 ), 3056 3057 'AlmanacDeviceController' => 'AlmanacController', 3057 3058 'AlmanacDeviceEditController' => 'AlmanacDeviceController', ··· 3066 3067 'AlmanacInterface' => array( 3067 3068 'AlmanacDAO', 3068 3069 'PhabricatorPolicyInterface', 3070 + 'PhabricatorDestructibleInterface', 3069 3071 ), 3070 3072 'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource', 3071 3073 'AlmanacInterfaceEditController' => 'AlmanacDeviceController', ··· 3083 3085 'AlmanacDAO', 3084 3086 'PhabricatorApplicationTransactionInterface', 3085 3087 'PhabricatorPolicyInterface', 3088 + 'PhabricatorDestructibleInterface', 3086 3089 ), 3087 3090 'AlmanacNetworkController' => 'AlmanacController', 3088 3091 'AlmanacNetworkEditController' => 'AlmanacNetworkController', ··· 3112 3115 'PhabricatorApplicationTransactionInterface', 3113 3116 'PhabricatorProjectInterface', 3114 3117 'AlmanacPropertyInterface', 3118 + 'PhabricatorDestructibleInterface', 3115 3119 ), 3116 3120 'AlmanacServiceController' => 'AlmanacController', 3117 3121 'AlmanacServiceDatasource' => 'PhabricatorTypeaheadDatasource',
+22 -2
src/applications/almanac/editor/AlmanacDeviceEditor.php
··· 94 94 $interface 95 95 ->setNetworkPHID($new['networkPHID']) 96 96 ->setAddress($new['address']) 97 - ->setPort((int)$new['port']) 98 - ->save(); 97 + ->setPort((int)$new['port']); 98 + 99 + if (idx($new, 'phid')) { 100 + $interface->setPHID($new['phid']); 101 + } 102 + 103 + $interface->save(); 99 104 } else { 100 105 $interface->delete(); 101 106 } ··· 209 214 'Port numbers must be between 1 and 65535, inclusive.'), 210 215 $xaction); 211 216 $errors[] = $error; 217 + } 218 + 219 + $phid = idx($new, 'phid'); 220 + if ($phid) { 221 + $interface_phid_type = AlmanacInterfacePHIDType::TYPECONST; 222 + if (phid_get_type($phid) !== $interface_phid_type) { 223 + $error = new PhabricatorApplicationTransactionValidationError( 224 + $type, 225 + pht('Invalid'), 226 + pht( 227 + 'Precomputed interface PHIDs must be of type '. 228 + 'AlmanacInterfacePHIDType.'), 229 + $xaction); 230 + $errors[] = $error; 231 + } 212 232 } 213 233 } 214 234 }
+18 -5
src/applications/almanac/query/AlmanacDeviceQuery.php
··· 6 6 private $ids; 7 7 private $phids; 8 8 private $names; 9 - private $datasourceQuery; 9 + private $namePrefix; 10 + private $nameSuffix; 10 11 11 12 public function withIDs(array $ids) { 12 13 $this->ids = $ids; ··· 23 24 return $this; 24 25 } 25 26 26 - public function withDatasourceQuery($query) { 27 - $this->datasourceQuery = $query; 27 + public function withNamePrefix($prefix) { 28 + $this->namePrefix = $prefix; 29 + return $this; 30 + } 31 + 32 + public function withNameSuffix($suffix) { 33 + $this->nameSuffix = $suffix; 28 34 return $this; 29 35 } 30 36 ··· 71 77 $hashes); 72 78 } 73 79 74 - if ($this->datasourceQuery !== null) { 80 + if ($this->namePrefix !== null) { 75 81 $where[] = qsprintf( 76 82 $conn_r, 77 83 'name LIKE %>', 78 - $this->datasourceQuery); 84 + $this->namePrefix); 85 + } 86 + 87 + if ($this->nameSuffix !== null) { 88 + $where[] = qsprintf( 89 + $conn_r, 90 + 'name LIKE %<', 91 + $this->nameSuffix); 79 92 } 80 93 81 94 $where[] = $this->buildPagingClause($conn_r);
+19 -1
src/applications/almanac/storage/AlmanacDevice.php
··· 8 8 PhabricatorApplicationTransactionInterface, 9 9 PhabricatorProjectInterface, 10 10 PhabricatorSSHPublicKeyInterface, 11 - AlmanacPropertyInterface { 11 + AlmanacPropertyInterface, 12 + PhabricatorDestructibleInterface { 12 13 13 14 protected $name; 14 15 protected $nameIndex; ··· 231 232 return $this->getName(); 232 233 } 233 234 235 + 236 + /* -( PhabricatorDestructibleInterface )----------------------------------- */ 237 + 238 + 239 + public function destroyObjectPermanently( 240 + PhabricatorDestructionEngine $engine) { 241 + 242 + $interfaces = id(new AlmanacInterfaceQuery()) 243 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 244 + ->withDevicePHIDs(array($this->getPHID())) 245 + ->execute(); 246 + foreach ($interfaces as $interface) { 247 + $engine->destroyObject($interface); 248 + } 249 + 250 + $this->delete(); 251 + } 234 252 235 253 }
+21 -1
src/applications/almanac/storage/AlmanacInterface.php
··· 2 2 3 3 final class AlmanacInterface 4 4 extends AlmanacDAO 5 - implements PhabricatorPolicyInterface { 5 + implements 6 + PhabricatorPolicyInterface, 7 + PhabricatorDestructibleInterface { 6 8 7 9 protected $devicePHID; 8 10 protected $networkPHID; ··· 107 109 } 108 110 109 111 return $notes; 112 + } 113 + 114 + 115 + /* -( PhabricatorDestructibleInterface )----------------------------------- */ 116 + 117 + 118 + public function destroyObjectPermanently( 119 + PhabricatorDestructionEngine $engine) { 120 + 121 + $bindings = id(new AlmanacBindingQuery()) 122 + ->setViewer($this->getViewer()) 123 + ->withInterfacePHIDs(array($this->getPHID())) 124 + ->execute(); 125 + foreach ($bindings as $binding) { 126 + $engine->destroyObject($binding); 127 + } 128 + 129 + $this->delete(); 110 130 } 111 131 112 132 }
+21 -1
src/applications/almanac/storage/AlmanacNetwork.php
··· 4 4 extends AlmanacDAO 5 5 implements 6 6 PhabricatorApplicationTransactionInterface, 7 - PhabricatorPolicyInterface { 7 + PhabricatorPolicyInterface, 8 + PhabricatorDestructibleInterface { 8 9 9 10 protected $name; 10 11 protected $mailKey; ··· 92 93 93 94 public function describeAutomaticCapability($capability) { 94 95 return null; 96 + } 97 + 98 + 99 + /* -( PhabricatorDestructibleInterface )----------------------------------- */ 100 + 101 + 102 + public function destroyObjectPermanently( 103 + PhabricatorDestructionEngine $engine) { 104 + 105 + $interfaces = id(new AlmanacInterfaceQuery()) 106 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 107 + ->withNetworkPHIDs(array($this->getPHID())) 108 + ->execute(); 109 + 110 + foreach ($interfaces as $interface) { 111 + $engine->destroyObject($interface); 112 + } 113 + 114 + $this->delete(); 95 115 } 96 116 97 117 }
+20 -1
src/applications/almanac/storage/AlmanacService.php
··· 7 7 PhabricatorCustomFieldInterface, 8 8 PhabricatorApplicationTransactionInterface, 9 9 PhabricatorProjectInterface, 10 - AlmanacPropertyInterface { 10 + AlmanacPropertyInterface, 11 + PhabricatorDestructibleInterface { 11 12 12 13 protected $name; 13 14 protected $nameIndex; ··· 210 211 AphrontRequest $request) { 211 212 212 213 return $timeline; 214 + } 215 + 216 + 217 + /* -( PhabricatorDestructibleInterface )----------------------------------- */ 218 + 219 + 220 + public function destroyObjectPermanently( 221 + PhabricatorDestructionEngine $engine) { 222 + 223 + $bindings = id(new AlmanacBindingQuery()) 224 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 225 + ->withServicePHIDs(array($this->getPHID())) 226 + ->execute(); 227 + foreach ($bindings as $binding) { 228 + $engine->destroyObject($binding); 229 + } 230 + 231 + $this->delete(); 213 232 } 214 233 215 234 }
+1 -1
src/applications/almanac/typeahead/AlmanacInterfaceDatasource.php
··· 17 17 18 18 $devices = id(new AlmanacDeviceQuery()) 19 19 ->setViewer($viewer) 20 - ->withDatasourceQuery($raw_query) 20 + ->withNamePrefix($raw_query) 21 21 ->execute(); 22 22 23 23 if ($devices) {