Page MenuHomePhabricator

D15329.id36975.diff
No OneTemporary

D15329.id36975.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
@@ -20,6 +20,7 @@
'AlmanacBindingTransaction' => 'applications/almanac/storage/AlmanacBindingTransaction.php',
'AlmanacBindingTransactionQuery' => 'applications/almanac/query/AlmanacBindingTransactionQuery.php',
'AlmanacBindingViewController' => 'applications/almanac/controller/AlmanacBindingViewController.php',
+ 'AlmanacBindingsSearchEngineAttachment' => 'applications/almanac/engineextension/AlmanacBindingsSearchEngineAttachment.php',
'AlmanacClusterDatabaseServiceType' => 'applications/almanac/servicetype/AlmanacClusterDatabaseServiceType.php',
'AlmanacClusterRepositoryServiceType' => 'applications/almanac/servicetype/AlmanacClusterRepositoryServiceType.php',
'AlmanacClusterServiceType' => 'applications/almanac/servicetype/AlmanacClusterServiceType.php',
@@ -42,6 +43,7 @@
'AlmanacDevicePHIDType' => 'applications/almanac/phid/AlmanacDevicePHIDType.php',
'AlmanacDevicePropertyEditEngine' => 'applications/almanac/editor/AlmanacDevicePropertyEditEngine.php',
'AlmanacDeviceQuery' => 'applications/almanac/query/AlmanacDeviceQuery.php',
+ 'AlmanacDeviceSearchConduitAPIMethod' => 'applications/almanac/conduit/AlmanacDeviceSearchConduitAPIMethod.php',
'AlmanacDeviceSearchEngine' => 'applications/almanac/query/AlmanacDeviceSearchEngine.php',
'AlmanacDeviceTransaction' => 'applications/almanac/storage/AlmanacDeviceTransaction.php',
'AlmanacDeviceTransactionQuery' => 'applications/almanac/query/AlmanacDeviceTransactionQuery.php',
@@ -90,6 +92,7 @@
'AlmanacNetworkTransactionQuery' => 'applications/almanac/query/AlmanacNetworkTransactionQuery.php',
'AlmanacNetworkViewController' => 'applications/almanac/controller/AlmanacNetworkViewController.php',
'AlmanacPropertiesDestructionEngineExtension' => 'applications/almanac/engineextension/AlmanacPropertiesDestructionEngineExtension.php',
+ 'AlmanacPropertiesSearchEngineAttachment' => 'applications/almanac/engineextension/AlmanacPropertiesSearchEngineAttachment.php',
'AlmanacProperty' => 'applications/almanac/storage/AlmanacProperty.php',
'AlmanacPropertyController' => 'applications/almanac/controller/AlmanacPropertyController.php',
'AlmanacPropertyDeleteController' => 'applications/almanac/controller/AlmanacPropertyDeleteController.php',
@@ -101,6 +104,7 @@
'AlmanacQueryDevicesConduitAPIMethod' => 'applications/almanac/conduit/AlmanacQueryDevicesConduitAPIMethod.php',
'AlmanacQueryServicesConduitAPIMethod' => 'applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php',
'AlmanacSchemaSpec' => 'applications/almanac/storage/AlmanacSchemaSpec.php',
+ 'AlmanacSearchEngineAttachment' => 'applications/almanac/engineextension/AlmanacSearchEngineAttachment.php',
'AlmanacService' => 'applications/almanac/storage/AlmanacService.php',
'AlmanacServiceController' => 'applications/almanac/controller/AlmanacServiceController.php',
'AlmanacServiceDatasource' => 'applications/almanac/typeahead/AlmanacServiceDatasource.php',
@@ -111,6 +115,7 @@
'AlmanacServicePHIDType' => 'applications/almanac/phid/AlmanacServicePHIDType.php',
'AlmanacServicePropertyEditEngine' => 'applications/almanac/editor/AlmanacServicePropertyEditEngine.php',
'AlmanacServiceQuery' => 'applications/almanac/query/AlmanacServiceQuery.php',
+ 'AlmanacServiceSearchConduitAPIMethod' => 'applications/almanac/conduit/AlmanacServiceSearchConduitAPIMethod.php',
'AlmanacServiceSearchEngine' => 'applications/almanac/query/AlmanacServiceSearchEngine.php',
'AlmanacServiceTransaction' => 'applications/almanac/storage/AlmanacServiceTransaction.php',
'AlmanacServiceTransactionQuery' => 'applications/almanac/query/AlmanacServiceTransactionQuery.php',
@@ -4007,6 +4012,7 @@
'AlmanacBindingTransaction' => 'AlmanacTransaction',
'AlmanacBindingTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'AlmanacBindingViewController' => 'AlmanacServiceController',
+ 'AlmanacBindingsSearchEngineAttachment' => 'AlmanacSearchEngineAttachment',
'AlmanacClusterDatabaseServiceType' => 'AlmanacClusterServiceType',
'AlmanacClusterRepositoryServiceType' => 'AlmanacClusterServiceType',
'AlmanacClusterServiceType' => 'AlmanacServiceType',
@@ -4029,6 +4035,7 @@
'AlmanacPropertyInterface',
'PhabricatorDestructibleInterface',
'PhabricatorNgramsInterface',
+ 'PhabricatorConduitResultInterface',
),
'AlmanacDeviceController' => 'AlmanacController',
'AlmanacDeviceEditController' => 'AlmanacDeviceController',
@@ -4038,6 +4045,7 @@
'AlmanacDevicePHIDType' => 'PhabricatorPHIDType',
'AlmanacDevicePropertyEditEngine' => 'AlmanacPropertyEditEngine',
'AlmanacDeviceQuery' => 'AlmanacQuery',
+ 'AlmanacDeviceSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
'AlmanacDeviceSearchEngine' => 'PhabricatorApplicationSearchEngine',
'AlmanacDeviceTransaction' => 'AlmanacTransaction',
'AlmanacDeviceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
@@ -4052,7 +4060,7 @@
'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource',
'AlmanacInterfaceEditController' => 'AlmanacDeviceController',
'AlmanacInterfacePHIDType' => 'PhabricatorPHIDType',
- 'AlmanacInterfaceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'AlmanacInterfaceQuery' => 'AlmanacQuery',
'AlmanacInterfaceTableView' => 'AphrontView',
'AlmanacKeys' => 'Phobject',
'AlmanacManagementLockWorkflow' => 'AlmanacManagementWorkflow',
@@ -4098,25 +4106,27 @@
'AlmanacNetworkListController' => 'AlmanacNetworkController',
'AlmanacNetworkNameNgrams' => 'PhabricatorSearchNgrams',
'AlmanacNetworkPHIDType' => 'PhabricatorPHIDType',
- 'AlmanacNetworkQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'AlmanacNetworkQuery' => 'AlmanacQuery',
'AlmanacNetworkSearchEngine' => 'PhabricatorApplicationSearchEngine',
'AlmanacNetworkTransaction' => 'PhabricatorApplicationTransaction',
'AlmanacNetworkTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'AlmanacNetworkViewController' => 'AlmanacNetworkController',
'AlmanacPropertiesDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
+ 'AlmanacPropertiesSearchEngineAttachment' => 'AlmanacSearchEngineAttachment',
'AlmanacProperty' => array(
'AlmanacDAO',
'PhabricatorPolicyInterface',
),
'AlmanacPropertyController' => 'AlmanacController',
- 'AlmanacPropertyDeleteController' => 'AlmanacDeviceController',
- 'AlmanacPropertyEditController' => 'AlmanacDeviceController',
+ 'AlmanacPropertyDeleteController' => 'AlmanacPropertyController',
+ 'AlmanacPropertyEditController' => 'AlmanacPropertyController',
'AlmanacPropertyEditEngine' => 'PhabricatorEditEngine',
'AlmanacPropertyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'AlmanacQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'AlmanacQueryDevicesConduitAPIMethod' => 'AlmanacConduitAPIMethod',
'AlmanacQueryServicesConduitAPIMethod' => 'AlmanacConduitAPIMethod',
'AlmanacSchemaSpec' => 'PhabricatorConfigSchemaSpec',
+ 'AlmanacSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
'AlmanacService' => array(
'AlmanacDAO',
'PhabricatorPolicyInterface',
@@ -4125,6 +4135,7 @@
'AlmanacPropertyInterface',
'PhabricatorDestructibleInterface',
'PhabricatorNgramsInterface',
+ 'PhabricatorConduitResultInterface',
),
'AlmanacServiceController' => 'AlmanacController',
'AlmanacServiceDatasource' => 'PhabricatorTypeaheadDatasource',
@@ -4135,6 +4146,7 @@
'AlmanacServicePHIDType' => 'PhabricatorPHIDType',
'AlmanacServicePropertyEditEngine' => 'AlmanacPropertyEditEngine',
'AlmanacServiceQuery' => 'AlmanacQuery',
+ 'AlmanacServiceSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
'AlmanacServiceSearchEngine' => 'PhabricatorApplicationSearchEngine',
'AlmanacServiceTransaction' => 'AlmanacTransaction',
'AlmanacServiceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
diff --git a/src/applications/almanac/conduit/AlmanacConduitAPIMethod.php b/src/applications/almanac/conduit/AlmanacConduitAPIMethod.php
--- a/src/applications/almanac/conduit/AlmanacConduitAPIMethod.php
+++ b/src/applications/almanac/conduit/AlmanacConduitAPIMethod.php
@@ -8,7 +8,7 @@
}
public function getMethodStatus() {
- return self::METHOD_STATUS_UNSTABLE;
+ return self::METHOD_STATUS_DEPRECATED;
}
public function getMethodStatusDescription() {
diff --git a/src/applications/almanac/conduit/AlmanacDeviceSearchConduitAPIMethod.php b/src/applications/almanac/conduit/AlmanacDeviceSearchConduitAPIMethod.php
new file mode 100644
--- /dev/null
+++ b/src/applications/almanac/conduit/AlmanacDeviceSearchConduitAPIMethod.php
@@ -0,0 +1,18 @@
+<?php
+
+final class AlmanacDeviceSearchConduitAPIMethod
+ extends PhabricatorSearchEngineAPIMethod {
+
+ public function getAPIMethodName() {
+ return 'almanac.device.search';
+ }
+
+ public function newSearchEngine() {
+ return new AlmanacDeviceSearchEngine();
+ }
+
+ public function getMethodSummary() {
+ return pht('Read information about Almanac devices.');
+ }
+
+}
diff --git a/src/applications/almanac/conduit/AlmanacServiceSearchConduitAPIMethod.php b/src/applications/almanac/conduit/AlmanacServiceSearchConduitAPIMethod.php
new file mode 100644
--- /dev/null
+++ b/src/applications/almanac/conduit/AlmanacServiceSearchConduitAPIMethod.php
@@ -0,0 +1,18 @@
+<?php
+
+final class AlmanacServiceSearchConduitAPIMethod
+ extends PhabricatorSearchEngineAPIMethod {
+
+ public function getAPIMethodName() {
+ return 'almanac.service.search';
+ }
+
+ public function newSearchEngine() {
+ return new AlmanacServiceSearchEngine();
+ }
+
+ public function getMethodSummary() {
+ return pht('Read information about Almanac services.');
+ }
+
+}
diff --git a/src/applications/almanac/controller/AlmanacBindingViewController.php b/src/applications/almanac/controller/AlmanacBindingViewController.php
--- a/src/applications/almanac/controller/AlmanacBindingViewController.php
+++ b/src/applications/almanac/controller/AlmanacBindingViewController.php
@@ -15,6 +15,7 @@
$binding = id(new AlmanacBindingQuery())
->setViewer($viewer)
->withIDs(array($id))
+ ->needProperties(true)
->executeOne();
if (!$binding) {
return new Aphront404Response();
diff --git a/src/applications/almanac/controller/AlmanacDeviceViewController.php b/src/applications/almanac/controller/AlmanacDeviceViewController.php
--- a/src/applications/almanac/controller/AlmanacDeviceViewController.php
+++ b/src/applications/almanac/controller/AlmanacDeviceViewController.php
@@ -15,6 +15,7 @@
$device = id(new AlmanacDeviceQuery())
->setViewer($viewer)
->withNames(array($name))
+ ->needProperties(true)
->executeOne();
if (!$device) {
return new Aphront404Response();
diff --git a/src/applications/almanac/controller/AlmanacPropertyController.php b/src/applications/almanac/controller/AlmanacPropertyController.php
--- a/src/applications/almanac/controller/AlmanacPropertyController.php
+++ b/src/applications/almanac/controller/AlmanacPropertyController.php
@@ -1,3 +1,56 @@
<?php
-abstract class AlmanacPropertyController extends AlmanacController {}
+abstract class AlmanacPropertyController extends AlmanacController {
+
+ private $propertyObject;
+
+ public function getPropertyObject() {
+ return $this->propertyObject;
+ }
+
+ protected function loadPropertyObject() {
+ $viewer = $this->getViewer();
+ $request = $this->getRequest();
+ $object_phid = $request->getStr('objectPHID');
+
+
+ switch (phid_get_type($object_phid)) {
+ case AlmanacBindingPHIDType::TYPECONST:
+ $query = new AlmanacBindingQuery();
+ break;
+ case AlmanacDevicePHIDType::TYPECONST:
+ $query = new AlmanacDeviceQuery();
+ break;
+ case AlmanacServicePHIDType::TYPECONST:
+ $query = new AlmanacServiceQuery();
+ break;
+ default:
+ return new Aphront404Response();
+ }
+
+ $object = $query
+ ->setViewer($viewer)
+ ->withPHIDs(array($object_phid))
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->needProperties(true)
+ ->executeOne();
+
+ if (!$object) {
+ return new Aphront404Response();
+ }
+
+ if (!($object instanceof AlmanacPropertyInterface)) {
+ return new Aphront404Response();
+ }
+
+ $this->propertyObject = $object;
+
+ return null;
+ }
+
+
+}
diff --git a/src/applications/almanac/controller/AlmanacPropertyDeleteController.php b/src/applications/almanac/controller/AlmanacPropertyDeleteController.php
--- a/src/applications/almanac/controller/AlmanacPropertyDeleteController.php
+++ b/src/applications/almanac/controller/AlmanacPropertyDeleteController.php
@@ -1,27 +1,17 @@
<?php
final class AlmanacPropertyDeleteController
- extends AlmanacDeviceController {
+ extends AlmanacPropertyController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
- $object = id(new PhabricatorObjectQuery())
- ->setViewer($viewer)
- ->withPHIDs(array($request->getStr('objectPHID')))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->executeOne();
- if (!$object) {
- return new Aphront404Response();
+ $response = $this->loadPropertyObject();
+ if ($response) {
+ return $response;
}
- if (!($object instanceof AlmanacPropertyInterface)) {
- return new Aphront404Response();
- }
+ $object = $this->getPropertyObject();
$key = $request->getStr('key');
if (!strlen($key)) {
diff --git a/src/applications/almanac/controller/AlmanacPropertyEditController.php b/src/applications/almanac/controller/AlmanacPropertyEditController.php
--- a/src/applications/almanac/controller/AlmanacPropertyEditController.php
+++ b/src/applications/almanac/controller/AlmanacPropertyEditController.php
@@ -1,27 +1,17 @@
<?php
final class AlmanacPropertyEditController
- extends AlmanacDeviceController {
+ extends AlmanacPropertyController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
- $object = id(new PhabricatorObjectQuery())
- ->setViewer($viewer)
- ->withPHIDs(array($request->getStr('objectPHID')))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->executeOne();
- if (!$object) {
- return new Aphront404Response();
+ $response = $this->loadPropertyObject();
+ if ($response) {
+ return $response;
}
- if (!($object instanceof AlmanacPropertyInterface)) {
- return new Aphront404Response();
- }
+ $object = $this->getPropertyObject();
$cancel_uri = $object->getURI();
$property_key = $request->getStr('key');
diff --git a/src/applications/almanac/controller/AlmanacServiceViewController.php b/src/applications/almanac/controller/AlmanacServiceViewController.php
--- a/src/applications/almanac/controller/AlmanacServiceViewController.php
+++ b/src/applications/almanac/controller/AlmanacServiceViewController.php
@@ -15,6 +15,7 @@
$service = id(new AlmanacServiceQuery())
->setViewer($viewer)
->withNames(array($name))
+ ->needProperties(true)
->executeOne();
if (!$service) {
return new Aphront404Response();
diff --git a/src/applications/almanac/engineextension/AlmanacBindingsSearchEngineAttachment.php b/src/applications/almanac/engineextension/AlmanacBindingsSearchEngineAttachment.php
new file mode 100644
--- /dev/null
+++ b/src/applications/almanac/engineextension/AlmanacBindingsSearchEngineAttachment.php
@@ -0,0 +1,30 @@
+<?php
+
+final class AlmanacBindingsSearchEngineAttachment
+ extends AlmanacSearchEngineAttachment {
+
+ public function getAttachmentName() {
+ return pht('Almanac Bindings');
+ }
+
+ public function getAttachmentDescription() {
+ return pht('Get Almanac bindings for the service.');
+ }
+
+ public function willLoadAttachmentData($query, $spec) {
+ $query->needProperties(true);
+ $query->needBindings(true);
+ }
+
+ public function getAttachmentForObject($object, $data, $spec) {
+ $bindings = array();
+ foreach ($object->getBindings() as $binding) {
+ $bindings[] = $this->getAlmanacBindingDictionary($binding);
+ }
+
+ return array(
+ 'bindings' => $bindings,
+ );
+ }
+
+}
diff --git a/src/applications/almanac/engineextension/AlmanacPropertiesSearchEngineAttachment.php b/src/applications/almanac/engineextension/AlmanacPropertiesSearchEngineAttachment.php
new file mode 100644
--- /dev/null
+++ b/src/applications/almanac/engineextension/AlmanacPropertiesSearchEngineAttachment.php
@@ -0,0 +1,26 @@
+<?php
+
+final class AlmanacPropertiesSearchEngineAttachment
+ extends AlmanacSearchEngineAttachment {
+
+ public function getAttachmentName() {
+ return pht('Almanac Properties');
+ }
+
+ public function getAttachmentDescription() {
+ return pht('Get Almanac properties for the object.');
+ }
+
+ public function willLoadAttachmentData($query, $spec) {
+ $query->needProperties(true);
+ }
+
+ public function getAttachmentForObject($object, $data, $spec) {
+ $properties = $this->getAlmanacPropertyList($object);
+
+ return array(
+ 'properties' => $properties,
+ );
+ }
+
+}
diff --git a/src/applications/almanac/engineextension/AlmanacSearchEngineAttachment.php b/src/applications/almanac/engineextension/AlmanacSearchEngineAttachment.php
new file mode 100644
--- /dev/null
+++ b/src/applications/almanac/engineextension/AlmanacSearchEngineAttachment.php
@@ -0,0 +1,64 @@
+<?php
+
+abstract class AlmanacSearchEngineAttachment
+ extends PhabricatorSearchEngineAttachment {
+
+ protected function getAlmanacPropertyList($object) {
+ $builtins = $object->getAlmanacPropertyFieldSpecifications();
+
+ $properties = array();
+ foreach ($object->getAlmanacProperties() as $key => $property) {
+ $is_builtin = isset($builtins[$key]);
+
+ $properties[] = array(
+ 'key' => $key,
+ 'value' => $property->getFieldValue(),
+ 'builtin' => $is_builtin,
+ );
+ }
+
+ return $properties;
+ }
+
+ protected function getAlmanacBindingDictionary(AlmanacBinding $binding) {
+ $interface = $binding->getInterface();
+
+ return array(
+ 'id' => (int)$binding->getID(),
+ 'phid' => $binding->getPHID(),
+ 'properties' => $this->getAlmanacPropertyList($binding),
+ 'interface' => $this->getAlmanacInterfaceDictionary($interface),
+ );
+ }
+
+ protected function getAlmanacInterfaceDictionary(
+ AlmanacInterface $interface) {
+
+ return array(
+ 'id' => (int)$interface->getID(),
+ 'phid' => $interface->getPHID(),
+ 'address' => $interface->getAddress(),
+ 'port' => (int)$interface->getPort(),
+ 'device' => $this->getAlmanacDeviceDictionary($interface->getDevice()),
+ 'network' => $this->getAlmanacNetworkDictionary($interface->getNetwork()),
+ );
+ }
+
+ protected function getAlmanacDeviceDictionary(AlmanacDevice $device) {
+ return array(
+ 'id' => (int)$device->getID(),
+ 'phid' => $device->getPHID(),
+ 'name' => $device->getName(),
+ 'properties' => $this->getAlmanacPropertyList($device),
+ );
+ }
+
+ protected function getAlmanacNetworkDictionary(AlmanacNetwork $network) {
+ return array(
+ 'id' => (int)$network->getID(),
+ 'phid' => $network->getPHID(),
+ 'name' => $network->getName(),
+ );
+ }
+
+}
diff --git a/src/applications/almanac/query/AlmanacBindingQuery.php b/src/applications/almanac/query/AlmanacBindingQuery.php
--- a/src/applications/almanac/query/AlmanacBindingQuery.php
+++ b/src/applications/almanac/query/AlmanacBindingQuery.php
@@ -34,19 +34,12 @@
return $this;
}
+ public function newResultObject() {
+ return new AlmanacBinding();
+ }
+
protected function loadPage() {
- $table = new AlmanacBinding();
- $conn_r = $table->establishConnection('r');
-
- $data = queryfx_all(
- $conn_r,
- 'SELECT * FROM %T %Q %Q %Q',
- $table->getTableName(),
- $this->buildWhereClause($conn_r),
- $this->buildOrderClause($conn_r),
- $this->buildLimitClause($conn_r));
-
- return $table->loadAllFromArray($data);
+ return $this->loadStandardPage($this->newResultObject());
}
protected function willFilterPage(array $bindings) {
@@ -58,6 +51,7 @@
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($service_phids)
+ ->needProperties($this->getNeedProperties())
->execute();
$services = mpull($services, null, 'getPHID');
@@ -65,6 +59,7 @@
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($device_phids)
+ ->needProperties($this->getNeedProperties())
->execute();
$devices = mpull($devices, null, 'getPHID');
@@ -72,6 +67,7 @@
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($interface_phids)
+ ->needProperties($this->getNeedProperties())
->execute();
$interfaces = mpull($interfaces, null, 'getPHID');
@@ -93,47 +89,45 @@
return $bindings;
}
- protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
- $where = array();
+ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
+ $where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'phid IN (%Ls)',
$this->phids);
}
if ($this->servicePHIDs !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'servicePHID IN (%Ls)',
$this->servicePHIDs);
}
if ($this->devicePHIDs !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'devicePHID IN (%Ls)',
$this->devicePHIDs);
}
if ($this->interfacePHIDs !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'interfacePHID IN (%Ls)',
$this->interfacePHIDs);
}
- $where[] = $this->buildPagingClause($conn_r);
-
- return $this->formatWhereClause($where);
+ return $where;
}
}
diff --git a/src/applications/almanac/query/AlmanacDeviceSearchEngine.php b/src/applications/almanac/query/AlmanacDeviceSearchEngine.php
--- a/src/applications/almanac/query/AlmanacDeviceSearchEngine.php
+++ b/src/applications/almanac/query/AlmanacDeviceSearchEngine.php
@@ -21,6 +21,10 @@
->setLabel(pht('Name Contains'))
->setKey('match')
->setDescription(pht('Search for devices by name substring.')),
+ id(new PhabricatorSearchStringListField())
+ ->setLabel(pht('Exact Names'))
+ ->setKey('names')
+ ->setDescription(pht('Search for devices with specific names.')),
);
}
@@ -31,6 +35,10 @@
$query->withNameNgrams($map['match']);
}
+ if ($map['names']) {
+ $query->withNames($map['names']);
+ }
+
return $query;
}
diff --git a/src/applications/almanac/query/AlmanacInterfaceQuery.php b/src/applications/almanac/query/AlmanacInterfaceQuery.php
--- a/src/applications/almanac/query/AlmanacInterfaceQuery.php
+++ b/src/applications/almanac/query/AlmanacInterfaceQuery.php
@@ -1,7 +1,7 @@
<?php
final class AlmanacInterfaceQuery
- extends PhabricatorCursorPagedPolicyAwareQuery {
+ extends AlmanacQuery {
private $ids;
private $phids;
@@ -50,6 +50,7 @@
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($network_phids)
+ ->needProperties($this->getNeedProperties())
->execute();
$networks = mpull($networks, null, 'getPHID');
@@ -57,6 +58,7 @@
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($device_phids)
+ ->needProperties($this->getNeedProperties())
->execute();
$devices = mpull($devices, null, 'getPHID');
diff --git a/src/applications/almanac/query/AlmanacNetworkQuery.php b/src/applications/almanac/query/AlmanacNetworkQuery.php
--- a/src/applications/almanac/query/AlmanacNetworkQuery.php
+++ b/src/applications/almanac/query/AlmanacNetworkQuery.php
@@ -1,7 +1,7 @@
<?php
final class AlmanacNetworkQuery
- extends PhabricatorCursorPagedPolicyAwareQuery {
+ extends AlmanacQuery {
private $ids;
private $phids;
diff --git a/src/applications/almanac/query/AlmanacPropertyQuery.php b/src/applications/almanac/query/AlmanacPropertyQuery.php
--- a/src/applications/almanac/query/AlmanacPropertyQuery.php
+++ b/src/applications/almanac/query/AlmanacPropertyQuery.php
@@ -5,8 +5,8 @@
private $ids;
private $objectPHIDs;
+ private $objects;
private $names;
- private $disablePolicyFilteringAndAttachment;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -18,72 +18,72 @@
return $this;
}
- public function withNames(array $names) {
- $this->names = $names;
+ public function withObjects(array $objects) {
+ $this->objects = mpull($objects, null, 'getPHID');
+ $this->objectPHIDs = array_keys($this->objects);
return $this;
}
- public function setDisablePolicyFilteringAndAttachment($disable) {
- $this->disablePolicyFilteringAndAttachment = $disable;
+ public function withNames(array $names) {
+ $this->names = $names;
return $this;
}
- protected function shouldDisablePolicyFiltering() {
- return $this->disablePolicyFilteringAndAttachment;
+ public function newResultObject() {
+ return new AlmanacProperty();
}
protected function loadPage() {
- $table = new AlmanacProperty();
- $conn_r = $table->establishConnection('r');
-
- $data = queryfx_all(
- $conn_r,
- 'SELECT * FROM %T %Q %Q %Q',
- $table->getTableName(),
- $this->buildWhereClause($conn_r),
- $this->buildOrderClause($conn_r),
- $this->buildLimitClause($conn_r));
-
- return $table->loadAllFromArray($data);
+ return $this->loadStandardPage($this->newResultObject());
}
protected function willFilterPage(array $properties) {
- if (!$this->disablePolicyFilteringAndAttachment) {
- $object_phids = mpull($properties, 'getObjectPHID');
+ $object_phids = mpull($properties, 'getObjectPHID');
+
+ $object_phids = array_fuse($object_phids);
+ if ($this->objects !== null) {
+ $object_phids = array_diff_key($object_phids, $this->objects);
+ }
+
+ if ($object_phids) {
$objects = id(new PhabricatorObjectQuery())
->setViewer($this->getViewer())
->setParentQuery($this)
->withPHIDs($object_phids)
->execute();
$objects = mpull($objects, null, 'getPHID');
+ } else {
+ $objects = array();
+ }
- foreach ($properties as $key => $property) {
- $object = idx($objects, $property->getObjectPHID());
- if (!$object) {
- unset($properties[$key]);
- continue;
- }
- $property->attachObject($object);
+ $objects += $this->objects;
+
+ foreach ($properties as $key => $property) {
+ $object = idx($objects, $property->getObjectPHID());
+ if (!$object) {
+ unset($properties[$key]);
+ continue;
}
+ $property->attachObject($object);
}
return $properties;
}
- protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
- $where = array();
+ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
+ $where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->objectPHIDs !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'objectPHID IN (%Ls)',
$this->objectPHIDs);
}
@@ -94,14 +94,12 @@
$hashes[] = PhabricatorHash::digestForIndex($name);
}
$where[] = qsprintf(
- $conn_r,
+ $conn,
'fieldIndex IN (%Ls)',
$hashes);
}
- $where[] = $this->buildPagingClause($conn_r);
-
- return $this->formatWhereClause($where);
+ return $where;
}
public function getQueryApplicationClass() {
diff --git a/src/applications/almanac/query/AlmanacQuery.php b/src/applications/almanac/query/AlmanacQuery.php
--- a/src/applications/almanac/query/AlmanacQuery.php
+++ b/src/applications/almanac/query/AlmanacQuery.php
@@ -3,21 +3,25 @@
abstract class AlmanacQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
+ private $needProperties;
+
+ public function needProperties($need_properties) {
+ $this->needProperties = $need_properties;
+ return $this;
+ }
+
+ protected function getNeedProperties() {
+ return $this->needProperties;
+ }
+
protected function didFilterPage(array $objects) {
- if (head($objects) instanceof AlmanacPropertyInterface) {
- // NOTE: We load properties for obsolete historical reasons. It may make
- // sense to re-examine that assumption shortly.
+ $has_properties = (head($objects) instanceof AlmanacPropertyInterface);
+ if ($has_properties && $this->needProperties) {
$property_query = id(new AlmanacPropertyQuery())
->setViewer($this->getViewer())
->setParentQuery($this)
- ->withObjectPHIDs(mpull($objects, 'getPHID'));
-
- // NOTE: We disable policy filtering and object attachment to avoid
- // a cyclic dependency where objects need their properties and properties
- // need their objects. We'll attach the objects below, and have already
- // implicitly checked the necessary policies.
- $property_query->setDisablePolicyFilteringAndAttachment(true);
+ ->withObjects($objects);
$properties = $property_query->execute();
diff --git a/src/applications/almanac/query/AlmanacServiceQuery.php b/src/applications/almanac/query/AlmanacServiceQuery.php
--- a/src/applications/almanac/query/AlmanacServiceQuery.php
+++ b/src/applications/almanac/query/AlmanacServiceQuery.php
@@ -65,8 +65,12 @@
return $this;
}
+ public function newResultObject() {
+ return new AlmanacService();
+ }
+
protected function loadPage() {
- return $this->loadStandardPage(new AlmanacService());
+ return $this->loadStandardPage($this->newResultObject());
}
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
@@ -172,6 +176,7 @@
$bindings = id(new AlmanacBindingQuery())
->setViewer($this->getViewer())
->withServicePHIDs($service_phids)
+ ->needProperties($this->getNeedProperties())
->execute();
$bindings = mgroup($bindings, 'getServicePHID');
diff --git a/src/applications/almanac/query/AlmanacServiceSearchEngine.php b/src/applications/almanac/query/AlmanacServiceSearchEngine.php
--- a/src/applications/almanac/query/AlmanacServiceSearchEngine.php
+++ b/src/applications/almanac/query/AlmanacServiceSearchEngine.php
@@ -26,6 +26,14 @@
$query->withNameNgrams($map['match']);
}
+ if ($map['names']) {
+ $query->withNames($map['names']);
+ }
+
+ if ($map['devicePHIDs']) {
+ $query->withDevicePHIDs($map['devicePHIDs']);
+ }
+
return $query;
}
@@ -36,6 +44,15 @@
->setLabel(pht('Name Contains'))
->setKey('match')
->setDescription(pht('Search for services by name substring.')),
+ id(new PhabricatorSearchStringListField())
+ ->setLabel(pht('Exact Names'))
+ ->setKey('names')
+ ->setDescription(pht('Search for services with specific names.')),
+ id(new PhabricatorPHIDsSearchField())
+ ->setLabel(pht('Devices'))
+ ->setKey('devicePHIDs')
+ ->setDescription(
+ pht('Search for services bound to particular devices.')),
);
}
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
@@ -9,7 +9,8 @@
PhabricatorSSHPublicKeyInterface,
AlmanacPropertyInterface,
PhabricatorDestructibleInterface,
- PhabricatorNgramsInterface {
+ PhabricatorNgramsInterface,
+ PhabricatorConduitResultInterface {
protected $name;
protected $nameIndex;
@@ -243,4 +244,30 @@
);
}
+
+/* -( PhabricatorConduitResultInterface )---------------------------------- */
+
+
+ public function getFieldSpecificationsForConduit() {
+ return array(
+ id(new PhabricatorConduitSearchFieldSpecification())
+ ->setKey('name')
+ ->setType('string')
+ ->setDescription(pht('The name of the device.')),
+ );
+ }
+
+ public function getFieldValuesForConduit() {
+ return array(
+ 'name' => $this->getName(),
+ );
+ }
+
+ public function getConduitSearchAttachments() {
+ return array(
+ id(new AlmanacPropertiesSearchEngineAttachment())
+ ->setAttachmentKey('properties'),
+ );
+ }
+
}
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
@@ -8,7 +8,8 @@
PhabricatorProjectInterface,
AlmanacPropertyInterface,
PhabricatorDestructibleInterface,
- PhabricatorNgramsInterface {
+ PhabricatorNgramsInterface,
+ PhabricatorConduitResultInterface {
protected $name;
protected $nameIndex;
@@ -224,4 +225,32 @@
);
}
+
+/* -( PhabricatorConduitResultInterface )---------------------------------- */
+
+
+ public function getFieldSpecificationsForConduit() {
+ return array(
+ id(new PhabricatorConduitSearchFieldSpecification())
+ ->setKey('name')
+ ->setType('string')
+ ->setDescription(pht('The name of the service.')),
+ );
+ }
+
+ public function getFieldValuesForConduit() {
+ return array(
+ 'name' => $this->getName(),
+ );
+ }
+
+ public function getConduitSearchAttachments() {
+ return array(
+ id(new AlmanacPropertiesSearchEngineAttachment())
+ ->setAttachmentKey('properties'),
+ id(new AlmanacBindingsSearchEngineAttachment())
+ ->setAttachmentKey('bindings'),
+ );
+ }
+
}
diff --git a/src/applications/search/field/PhabricatorSearchTextField.php b/src/applications/search/field/PhabricatorSearchTextField.php
--- a/src/applications/search/field/PhabricatorSearchTextField.php
+++ b/src/applications/search/field/PhabricatorSearchTextField.php
@@ -15,4 +15,8 @@
return new AphrontFormTextControl();
}
+ protected function newConduitParameterType() {
+ return new ConduitStringParameterType();
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 8:46 AM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6711126
Default Alt Text
D15329.id36975.diff (34 KB)

Event Timeline