Page MenuHomePhabricator

D11024.id26471.diff
No OneTemporary

D11024.id26471.diff

diff --git a/src/applications/almanac/editor/AlmanacDeviceEditor.php b/src/applications/almanac/editor/AlmanacDeviceEditor.php
--- a/src/applications/almanac/editor/AlmanacDeviceEditor.php
+++ b/src/applications/almanac/editor/AlmanacDeviceEditor.php
@@ -94,8 +94,13 @@
$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 @@
$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
--- a/src/applications/almanac/query/AlmanacDeviceQuery.php
+++ b/src/applications/almanac/query/AlmanacDeviceQuery.php
@@ -6,7 +6,8 @@
private $ids;
private $phids;
private $names;
- private $datasourceQuery;
+ private $namePrefix;
+ private $nameSuffix;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -23,8 +24,13 @@
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 @@
$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
--- a/src/applications/almanac/storage/AlmanacDevice.php
+++ b/src/applications/almanac/storage/AlmanacDevice.php
@@ -8,7 +8,8 @@
PhabricatorApplicationTransactionInterface,
PhabricatorProjectInterface,
PhabricatorSSHPublicKeyInterface,
- AlmanacPropertyInterface {
+ AlmanacPropertyInterface,
+ PhabricatorDestructibleInterface {
protected $name;
protected $nameIndex;
@@ -232,4 +233,21 @@
}
+/* -( 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
--- 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 @@
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
--- a/src/applications/almanac/storage/AlmanacNetwork.php
+++ b/src/applications/almanac/storage/AlmanacNetwork.php
@@ -4,7 +4,8 @@
extends AlmanacDAO
implements
PhabricatorApplicationTransactionInterface,
- PhabricatorPolicyInterface {
+ PhabricatorPolicyInterface,
+ PhabricatorDestructibleInterface {
protected $name;
protected $mailKey;
@@ -94,4 +95,23 @@
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
--- a/src/applications/almanac/storage/AlmanacService.php
+++ b/src/applications/almanac/storage/AlmanacService.php
@@ -7,7 +7,8 @@
PhabricatorCustomFieldInterface,
PhabricatorApplicationTransactionInterface,
PhabricatorProjectInterface,
- AlmanacPropertyInterface {
+ AlmanacPropertyInterface,
+ PhabricatorDestructibleInterface {
protected $name;
protected $nameIndex;
@@ -212,4 +213,22 @@
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
--- a/src/applications/almanac/typeahead/AlmanacInterfaceDatasource.php
+++ b/src/applications/almanac/typeahead/AlmanacInterfaceDatasource.php
@@ -17,7 +17,7 @@
$devices = id(new AlmanacDeviceQuery())
->setViewer($viewer)
- ->withDatasourceQuery($raw_query)
+ ->withNamePrefix($raw_query)
->execute();
if ($devices) {

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 23, 12:41 PM (2 w, 15 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7697573
Default Alt Text
D11024.id26471.diff (7 KB)

Event Timeline