From 4e70664ed4fa875bde2b38fb8bb570f51339a9e4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 11 Feb 2014 07:45:33 -0800 Subject: [PATCH] Fix alternate filtering conditions in object selector dialog Summary: These didn't get updated either when the main search got rebuilt. Adjust and modernize them. Also this uses "exclude", which I couldn't find any callsites for but just missed, so restore that. At some point I plan to swap this whole thing to ApplicationSearch and that will let us get rid of a bunch of stuff. Test Plan: Searched for all filters, got sensible results, verified source object doesn't show up as a result. Reviewers: btrahan Reviewed By: btrahan CC: aran, mbishopim3 Differential Revision: https://secure.phabricator.com/D8188 --- .../PhabricatorSearchSelectController.php | 25 +++++++++++-------- .../query/PhabricatorSearchDocumentQuery.php | 17 +++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/applications/search/controller/PhabricatorSearchSelectController.php b/src/applications/search/controller/PhabricatorSearchSelectController.php index 9a6623f66f..e9e62e0393 100644 --- a/src/applications/search/controller/PhabricatorSearchSelectController.php +++ b/src/applications/search/controller/PhabricatorSearchSelectController.php @@ -23,31 +23,36 @@ final class PhabricatorSearchSelectController $query->setParameter('query', $query_str); $query->setParameter('types', array($this->type)); + $status_open = PhabricatorSearchRelationship::RELATIONSHIP_OPEN; + switch ($request->getStr('filter')) { case 'assigned': - $query->setParameter('owner', array($user->getPHID())); - $query->setParameter('open', 1); + $query->setParameter('ownerPHIDs', array($user->getPHID())); + $query->setParameter('statuses', array($status_open)); break; case 'created'; - $query->setParameter('author', array($user->getPHID())); + $query->setParameter('authorPHIDs', array($user->getPHID())); // TODO - if / when we allow pholio mocks to be archived, etc // update this if ($this->type != PholioPHIDTypeMock::TYPECONST) { - $query->setParameter('open', 1); + $query->setParameter('statuses', array($status_open)); } break; case 'open': - $query->setParameter('open', 1); + $query->setParameter('statuses', array($status_open)); break; } - $query->setParameter('exclude', $request->getStr('exclude')); - $query->setParameter('limit', 100); + $query->setParameter('excludePHIDs', array($request->getStr('exclude'))); - $engine = PhabricatorSearchEngineSelector::newSelector()->newEngine(); - $results = $engine->executeSearch($query); + $results = id(new PhabricatorSearchDocumentQuery()) + ->setViewer($user) + ->withSavedQuery($query) + ->setOffset(0) + ->setLimit(100) + ->execute(); - $phids = array_fill_keys($results, true); + $phids = array_fill_keys(mpull($results, 'getPHID'), true); $phids += $this->queryObjectNames($query_str); $phids = array_keys($phids); diff --git a/src/applications/search/query/PhabricatorSearchDocumentQuery.php b/src/applications/search/query/PhabricatorSearchDocumentQuery.php index 92a2ec36ba..bec7cd76fd 100644 --- a/src/applications/search/query/PhabricatorSearchDocumentQuery.php +++ b/src/applications/search/query/PhabricatorSearchDocumentQuery.php @@ -25,6 +25,19 @@ final class PhabricatorSearchDocumentQuery } protected function willFilterPage(array $handles) { + + // NOTE: This is used by the object selector dialog to exclude the object + // you're looking at, so that, e.g., a task can't be set as a dependency + // of itself in the UI. + + // TODO: Remove this after object selection moves to ApplicationSearch. + + $exclude = array(); + if ($this->savedQuery) { + $exclude_phids = $this->savedQuery->getParameter('excludePHIDs', array()); + $exclude = array_fuse($exclude_phids); + } + foreach ($handles as $key => $handle) { if (!$handle->isComplete()) { unset($handles[$key]); @@ -34,6 +47,10 @@ final class PhabricatorSearchDocumentQuery unset($handles[$key]); continue; } + if (isset($exclude[$handle->getPHID()])) { + unset($handles[$key]); + continue; + } } return $handles;