diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ace26640ae..0fa26a383a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1417,6 +1417,7 @@ phutil_register_library_map(array( 'OwnersEditConduitAPIMethod' => 'applications/owners/conduit/OwnersEditConduitAPIMethod.php', 'OwnersPackageReplyHandler' => 'applications/owners/mail/OwnersPackageReplyHandler.php', 'OwnersQueryConduitAPIMethod' => 'applications/owners/conduit/OwnersQueryConduitAPIMethod.php', + 'OwnersSearchConduitAPIMethod' => 'applications/owners/conduit/OwnersSearchConduitAPIMethod.php', 'PHIDConduitAPIMethod' => 'applications/phid/conduit/PHIDConduitAPIMethod.php', 'PHIDInfoConduitAPIMethod' => 'applications/phid/conduit/PHIDInfoConduitAPIMethod.php', 'PHIDLookupConduitAPIMethod' => 'applications/phid/conduit/PHIDLookupConduitAPIMethod.php', @@ -1993,7 +1994,7 @@ phutil_register_library_map(array( 'PhabricatorCustomFieldAttachment' => 'infrastructure/customfield/field/PhabricatorCustomFieldAttachment.php', 'PhabricatorCustomFieldConfigOptionType' => 'infrastructure/customfield/config/PhabricatorCustomFieldConfigOptionType.php', 'PhabricatorCustomFieldDataNotAvailableException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldDataNotAvailableException.php', - 'PhabricatorCustomFieldEditEngineExtension' => 'infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php', + 'PhabricatorCustomFieldEditEngineExtension' => 'infrastructure/customfield/engineextension/PhabricatorCustomFieldEditEngineExtension.php', 'PhabricatorCustomFieldEditField' => 'infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php', 'PhabricatorCustomFieldEditType' => 'infrastructure/customfield/editor/PhabricatorCustomFieldEditType.php', 'PhabricatorCustomFieldHeraldField' => 'infrastructure/customfield/herald/PhabricatorCustomFieldHeraldField.php', @@ -2006,6 +2007,7 @@ phutil_register_library_map(array( 'PhabricatorCustomFieldNotAttachedException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldNotAttachedException.php', 'PhabricatorCustomFieldNotProxyException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldNotProxyException.php', 'PhabricatorCustomFieldNumericIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldNumericIndexStorage.php', + 'PhabricatorCustomFieldSearchEngineExtension' => 'infrastructure/customfield/engineextension/PhabricatorCustomFieldSearchEngineExtension.php', 'PhabricatorCustomFieldStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStorage.php', 'PhabricatorCustomFieldStringIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStringIndexStorage.php', 'PhabricatorCustomHeaderConfigType' => 'applications/config/custom/PhabricatorCustomHeaderConfigType.php', @@ -5439,6 +5441,7 @@ phutil_register_library_map(array( 'OwnersEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 'OwnersPackageReplyHandler' => 'PhabricatorMailReplyHandler', 'OwnersQueryConduitAPIMethod' => 'OwnersConduitAPIMethod', + 'OwnersSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'PHIDConduitAPIMethod' => 'ConduitAPIMethod', 'PHIDInfoConduitAPIMethod' => 'PHIDConduitAPIMethod', 'PHIDLookupConduitAPIMethod' => 'PHIDConduitAPIMethod', @@ -6116,6 +6119,7 @@ phutil_register_library_map(array( 'PhabricatorCustomFieldNotAttachedException' => 'Exception', 'PhabricatorCustomFieldNotProxyException' => 'Exception', 'PhabricatorCustomFieldNumericIndexStorage' => 'PhabricatorCustomFieldIndexStorage', + 'PhabricatorCustomFieldSearchEngineExtension' => 'PhabricatorSearchEngineExtension', 'PhabricatorCustomFieldStorage' => 'PhabricatorLiskDAO', 'PhabricatorCustomFieldStringIndexStorage' => 'PhabricatorCustomFieldIndexStorage', 'PhabricatorCustomHeaderConfigType' => 'PhabricatorConfigOptionType', @@ -6791,6 +6795,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionInterface', 'PhabricatorCustomFieldInterface', 'PhabricatorDestructibleInterface', + 'PhabricatorConduitResultInterface', ), 'PhabricatorOwnersPackageDatasource' => 'PhabricatorTypeaheadDatasource', 'PhabricatorOwnersPackageEditEngine' => 'PhabricatorEditEngine', diff --git a/src/applications/owners/conduit/OwnersSearchConduitAPIMethod.php b/src/applications/owners/conduit/OwnersSearchConduitAPIMethod.php new file mode 100644 index 0000000000..8fef33e4bc --- /dev/null +++ b/src/applications/owners/conduit/OwnersSearchConduitAPIMethod.php @@ -0,0 +1,18 @@ +saveTransaction(); } + +/* -( PhabricatorConduitResultInterface )---------------------------------- */ + + + public function getFieldSpecificationsForConduit() { + return array( + 'name' => array( + 'type' => 'string', + 'description' => pht('The name of the package.'), + ), + 'description' => array( + 'type' => 'string', + 'description' => pht('The package description.'), + ), + 'status' => array( + 'type' => 'string', + 'description' => pht('Active or archived status of the package.'), + ), + ); + } + + public function getFieldValuesForConduit() { + return array( + 'name' => $this->getName(), + 'description' => $this->getDescription(), + 'status' => $this->getStatus(), + ); + } + } diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php index f3afb97802..a2462c937a 100644 --- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php +++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php @@ -1174,6 +1174,14 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { public function getSearchFieldsForConduit() { $fields = $this->buildSearchFields(); + + // These are handled separately for Conduit, so don't show them as + // supported. + unset($fields['ids']); + unset($fields['phids']); + unset($fields['order']); + unset($fields['limit']); + return $fields; } @@ -1220,6 +1228,7 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { $query = $this->buildQueryFromSavedQuery($saved_query); $pager = $this->newPagerForSavedQuery($saved_query); + $this->setAutomaticConstraintsForConduit($query, $request, $constraints); $this->setQueryOrderForConduit($query, $request); $this->setPagerLimitForConduit($pager, $request); $this->setPagerOffsetsForConduit($pager, $request); @@ -1269,6 +1278,12 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { $field_extensions = array(); foreach ($extensions as $key => $extension) { + $extension->setViewer($this->requireViewer()); + + if (!$extension->supportsObject($object)) { + continue; + } + if ($extension->getFieldSpecificationsForConduit($object)) { $field_extensions[$key] = $extension; } @@ -1277,6 +1292,22 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { return $field_extensions; } + private function setAutomaticConstraintsForConduit( + $query, + ConduitAPIRequest $request, + array $constraints) { + + $with_ids = idx($constraints, 'ids'); + if ($with_ids) { + $query->withIDs($with_ids); + } + + $with_phids = idx($constraints, 'phids'); + if ($with_phids) { + $query->withPHIDs($with_phids); + } + } + private function setQueryOrderForConduit($query, ConduitAPIRequest $request) { $order = $request->getValue('order'); if ($order === null) { diff --git a/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php b/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php index 2159e54261..ae27cb07c0 100644 --- a/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php +++ b/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php @@ -143,13 +143,18 @@ EOTEXT $head_type = pht('Type'); $head_desc = pht('Description'); + $desc_ids = pht('Search for specific objects by ID.'); + $desc_phids = pht('Search for specific objects by PHID.'); + $fields = $engine->getSearchFieldsForConduit(); $table = array(); $table[] = "| {$head_key} | {$head_label} | {$head_type} | {$head_desc} |"; $table[] = '|-------------|---------------|--------------|--------------|'; + $table[] = "| `ids` | **IDs** | `list` | {$desc_ids} |"; + $table[] = "| `phids` | **PHIDs** | `list` | {$desc_phids} |"; foreach ($fields as $field) { - $key = $field->getKey(); + $key = $field->getKeyForConduit(); $label = $field->getLabel(); // TODO: Support generating and surfacing this information. diff --git a/src/applications/search/field/PhabricatorSearchCustomFieldProxyField.php b/src/applications/search/field/PhabricatorSearchCustomFieldProxyField.php index 15cbfcb09e..a612753f84 100644 --- a/src/applications/search/field/PhabricatorSearchCustomFieldProxyField.php +++ b/src/applications/search/field/PhabricatorSearchCustomFieldProxyField.php @@ -26,6 +26,10 @@ final class PhabricatorSearchCustomFieldProxyField return $this; } + public function getLabel() { + return $this->getCustomField()->getFieldName(); + } + public function getCustomField() { return $this->customField; } @@ -34,6 +38,10 @@ final class PhabricatorSearchCustomFieldProxyField return null; } + public function getKeyForConduit() { + return $this->getCustomField()->getModernFieldKey(); + } + protected function getValueExistsInRequest(AphrontRequest $request, $key) { // TODO: For historical reasons, the keys we look for don't line up with // the keys that CustomFields use. Just skip the check for existence and diff --git a/src/applications/search/field/PhabricatorSearchField.php b/src/applications/search/field/PhabricatorSearchField.php index b6e3e67c4a..0917ac488e 100644 --- a/src/applications/search/field/PhabricatorSearchField.php +++ b/src/applications/search/field/PhabricatorSearchField.php @@ -271,4 +271,14 @@ abstract class PhabricatorSearchField extends Phobject { return $list; } + + + public function getKeyForConduit() { + // TODO: This shouldn't really be different, but internal handling of + // custom field keys is a bit of a mess for now. + return $this->getKey(); + } + + + } diff --git a/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php b/src/infrastructure/customfield/engineextension/PhabricatorCustomFieldEditEngineExtension.php similarity index 100% rename from src/infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php rename to src/infrastructure/customfield/engineextension/PhabricatorCustomFieldEditEngineExtension.php diff --git a/src/infrastructure/customfield/engineextension/PhabricatorCustomFieldSearchEngineExtension.php b/src/infrastructure/customfield/engineextension/PhabricatorCustomFieldSearchEngineExtension.php new file mode 100644 index 0000000000..5601f26729 --- /dev/null +++ b/src/infrastructure/customfield/engineextension/PhabricatorCustomFieldSearchEngineExtension.php @@ -0,0 +1,58 @@ +getFields() as $field) { + $key = $field->getModernFieldKey(); + $map[$key] = array( + 'type' => 'wild', + 'description' => $field->getFieldDescription(), + ); + } + + return $map; + } + + public function getFieldValuesForConduit($object) { + // TODO: This is currently very inefficient. We should bulk-load these + // field values instead. + + $fields = PhabricatorCustomField::getObjectFields( + $object, + PhabricatorCustomField::ROLE_CONDUIT); + + $fields + ->setViewer($this->getViewer()) + ->readFieldsFromStorage($object); + + $map = array(); + foreach ($fields->getFields() as $field) { + $key = $field->getModernFieldKey(); + $map[$key] = $field->getConduitDictionaryValue(); + } + + return $map; + } + +} diff --git a/src/infrastructure/customfield/field/PhabricatorCustomField.php b/src/infrastructure/customfield/field/PhabricatorCustomField.php index f3bf787e72..edc077ff6f 100644 --- a/src/infrastructure/customfield/field/PhabricatorCustomField.php +++ b/src/infrastructure/customfield/field/PhabricatorCustomField.php @@ -188,6 +188,13 @@ abstract class PhabricatorCustomField extends Phobject { $field_key_is_incomplete = true); } + public function getModernFieldKey() { + if ($this->proxy) { + return $this->proxy->getModernFieldKey(); + } + return $this->getFieldKey(); + } + /** * Return a human-readable field name. @@ -199,7 +206,7 @@ abstract class PhabricatorCustomField extends Phobject { if ($this->proxy) { return $this->proxy->getFieldName(); } - return $this->getFieldKey(); + return $this->getModernFieldKey(); } @@ -1109,7 +1116,7 @@ abstract class PhabricatorCustomField extends Phobject { return $this->newEditField() ->setKey($this->getFieldKey()) - ->setEditTypeKey('custom.'.$this->getFieldKey()) + ->setEditTypeKey($this->getModernFieldKey()) ->setLabel($this->getFieldName()) ->setDescription($this->getFieldDescription()) ->setTransactionType($this->getApplicationTransactionType()) diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php index 37c22b8ca3..302607acfa 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php @@ -440,7 +440,7 @@ abstract class PhabricatorStandardCustomField } protected function newStandardEditField() { - $short = 'custom.'.$this->getRawStandardFieldKey(); + $short = $this->getModernFieldKey(); return parent::newStandardEditField() ->setEditTypeKey($short) @@ -451,4 +451,16 @@ abstract class PhabricatorStandardCustomField return true; } + public function shouldAppearInConduitDictionary() { + return true; + } + + public function getModernFieldKey() { + return 'custom.'.$this->getRawStandardFieldKey(); + } + + public function getConduitDictionaryValue() { + return $this->getFieldValue(); + } + } diff --git a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php index ac086a46fa..8a2edd4575 100644 --- a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php +++ b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php @@ -716,13 +716,13 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery continue; } - $key = $field->getFieldKey(); - $digest = $field->getFieldIndex(); + $legacy_key = 'custom:'.$field->getFieldKey(); + $modern_key = $field->getModernFieldKey(); - $full_key = 'custom:'.$key; - $orders[$full_key] = array( - 'vector' => array($full_key, 'id'), + $orders[$modern_key] = array( + 'vector' => array($modern_key, 'id'), 'name' => $field->getFieldName(), + 'aliases' => array($legacy_key), ); } } @@ -903,11 +903,11 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery continue; } - $key = $field->getFieldKey(); $digest = $field->getFieldIndex(); - $full_key = 'custom:'.$key; - $columns[$full_key] = array( + $key = $field->getModernFieldKey(); + + $columns[$key] = array( 'table' => 'appsearch_order_'.$digest, 'column' => 'indexValue', 'type' => $index->getIndexValueType(),