From 9c28ae9ba77d5fb993d11e2fada89bd785c3f7b4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 24 Jan 2016 07:19:54 -0800 Subject: [PATCH] Add more information (colors, members, watchers) to project.search Summary: Fixes T6501. This adds more API information to the newish `project.search` API method. Test Plan: Called `project.search`, used attachments. Reviewers: chad Reviewed By: chad Maniphest Tasks: T6501 Differential Revision: https://secure.phabricator.com/D15105 --- src/__phutil_library_map__.php | 4 +++ ...rProjectsMembersSearchEngineAttachment.php | 31 +++++++++++++++++++ ...ProjectsWatchersSearchEngineAttachment.php | 31 +++++++++++++++++++ .../icon/PhabricatorProjectIconSet.php | 5 +++ .../project/storage/PhabricatorProject.php | 18 ++++++++++- 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/applications/project/engineextension/PhabricatorProjectsMembersSearchEngineAttachment.php create mode 100644 src/applications/project/engineextension/PhabricatorProjectsWatchersSearchEngineAttachment.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6831ad22cf..a54459c690 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2954,10 +2954,12 @@ phutil_register_library_map(array( 'PhabricatorProjectsEditEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsEditEngineExtension.php', 'PhabricatorProjectsEditField' => 'applications/transactions/editfield/PhabricatorProjectsEditField.php', 'PhabricatorProjectsFulltextEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsFulltextEngineExtension.php', + 'PhabricatorProjectsMembersSearchEngineAttachment' => 'applications/project/engineextension/PhabricatorProjectsMembersSearchEngineAttachment.php', 'PhabricatorProjectsMembershipIndexEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsMembershipIndexEngineExtension.php', 'PhabricatorProjectsPolicyRule' => 'applications/project/policyrule/PhabricatorProjectsPolicyRule.php', 'PhabricatorProjectsSearchEngineAttachment' => 'applications/project/engineextension/PhabricatorProjectsSearchEngineAttachment.php', 'PhabricatorProjectsSearchEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsSearchEngineExtension.php', + 'PhabricatorProjectsWatchersSearchEngineAttachment' => 'applications/project/engineextension/PhabricatorProjectsWatchersSearchEngineAttachment.php', 'PhabricatorProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorProtocolAdapter.php', 'PhabricatorPygmentSetupCheck' => 'applications/config/check/PhabricatorPygmentSetupCheck.php', 'PhabricatorQuery' => 'infrastructure/query/PhabricatorQuery.php', @@ -7370,10 +7372,12 @@ phutil_register_library_map(array( 'PhabricatorProjectsEditEngineExtension' => 'PhabricatorEditEngineExtension', 'PhabricatorProjectsEditField' => 'PhabricatorTokenizerEditField', 'PhabricatorProjectsFulltextEngineExtension' => 'PhabricatorFulltextEngineExtension', + 'PhabricatorProjectsMembersSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment', 'PhabricatorProjectsMembershipIndexEngineExtension' => 'PhabricatorIndexEngineExtension', 'PhabricatorProjectsPolicyRule' => 'PhabricatorPolicyRule', 'PhabricatorProjectsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment', 'PhabricatorProjectsSearchEngineExtension' => 'PhabricatorSearchEngineExtension', + 'PhabricatorProjectsWatchersSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment', 'PhabricatorProtocolAdapter' => 'Phobject', 'PhabricatorPygmentSetupCheck' => 'PhabricatorSetupCheck', 'PhabricatorQuery' => 'Phobject', diff --git a/src/applications/project/engineextension/PhabricatorProjectsMembersSearchEngineAttachment.php b/src/applications/project/engineextension/PhabricatorProjectsMembersSearchEngineAttachment.php new file mode 100644 index 0000000000..9418ba2b4f --- /dev/null +++ b/src/applications/project/engineextension/PhabricatorProjectsMembersSearchEngineAttachment.php @@ -0,0 +1,31 @@ +needMembers(true); + } + + public function getAttachmentForObject($object, $data, $spec) { + $members = array(); + foreach ($object->getMemberPHIDs() as $member_phid) { + $members[] = array( + 'phid' => $member_phid, + ); + } + + return array( + 'members' => $members, + ); + } + +} diff --git a/src/applications/project/engineextension/PhabricatorProjectsWatchersSearchEngineAttachment.php b/src/applications/project/engineextension/PhabricatorProjectsWatchersSearchEngineAttachment.php new file mode 100644 index 0000000000..ad98dfaf1c --- /dev/null +++ b/src/applications/project/engineextension/PhabricatorProjectsWatchersSearchEngineAttachment.php @@ -0,0 +1,31 @@ +needWatchers(true); + } + + public function getAttachmentForObject($object, $data, $spec) { + $watchers = array(); + foreach ($object->getWatcherPHIDs() as $watcher_phid) { + $watchers[] = array( + 'phid' => $watcher_phid, + ); + } + + return array( + 'watchers' => $watchers, + ); + } + +} diff --git a/src/applications/project/icon/PhabricatorProjectIconSet.php b/src/applications/project/icon/PhabricatorProjectIconSet.php index 6744353b7c..7e48cdfd74 100644 --- a/src/applications/project/icon/PhabricatorProjectIconSet.php +++ b/src/applications/project/icon/PhabricatorProjectIconSet.php @@ -336,6 +336,11 @@ final class PhabricatorProjectIconSet return $list; } + public static function getColorName($color_key) { + $map = self::getColorMap(); + return idx($map, $color_key); + } + public static function getDefaultColorMap() { return array( array( diff --git a/src/applications/project/storage/PhabricatorProject.php b/src/applications/project/storage/PhabricatorProject.php index 16f4255843..6cf116688e 100644 --- a/src/applications/project/storage/PhabricatorProject.php +++ b/src/applications/project/storage/PhabricatorProject.php @@ -628,10 +628,17 @@ final class PhabricatorProject extends PhabricatorProjectDAO ->setKey('icon') ->setType('map') ->setDescription(pht('Information about the project icon.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('color') + ->setType('map') + ->setDescription(pht('Information about the project color.')), ); } public function getFieldValuesForConduit() { + $color_key = $this->getColor(); + $color_name = PhabricatorProjectIconSet::getColorName($color_key); + return array( 'name' => $this->getName(), 'slug' => $this->getPrimarySlug(), @@ -640,11 +647,20 @@ final class PhabricatorProject extends PhabricatorProjectDAO 'name' => $this->getDisplayIconName(), 'icon' => $this->getDisplayIconIcon(), ), + 'color' => array( + 'key' => $color_key, + 'name' => $color_name, + ), ); } public function getConduitSearchAttachments() { - return array(); + return array( + id(new PhabricatorProjectsMembersSearchEngineAttachment()) + ->setAttachmentKey('members'), + id(new PhabricatorProjectsWatchersSearchEngineAttachment()) + ->setAttachmentKey('watchers'), + ); } }