From e0dea4c4862f271edf2ce4b7363ac11668a5dc1b Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 19 Oct 2018 04:41:40 -0700 Subject: [PATCH] Fix `packages(project)` to work properly and add it to "MailableFunctionDatasource" Summary: Ref T13210. See PHI937. This function datasource isn't quite implemented correctly: it doesn't resolve `package(project)` properly, since the logic only handles users. This blames back to D14013, where it looks like `packages(..)` was added mostly as a general nice-to-have as part of a larger modernization change. Test Plan: Ran a `packages(project)` query in Differential, got accurate results (previously: no results). Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13210 Differential Revision: https://secure.phabricator.com/D19747 --- ...catorMetaMTAMailableFunctionDatasource.php | 1 + ...habricatorOwnersPackageOwnerDatasource.php | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/applications/metamta/typeahead/PhabricatorMetaMTAMailableFunctionDatasource.php b/src/applications/metamta/typeahead/PhabricatorMetaMTAMailableFunctionDatasource.php index 4b231b959e..b5d82c9749 100644 --- a/src/applications/metamta/typeahead/PhabricatorMetaMTAMailableFunctionDatasource.php +++ b/src/applications/metamta/typeahead/PhabricatorMetaMTAMailableFunctionDatasource.php @@ -23,6 +23,7 @@ final class PhabricatorMetaMTAMailableFunctionDatasource new PhabricatorProjectMembersDatasource(), new PhabricatorProjectDatasource(), new PhabricatorOwnersPackageDatasource(), + new PhabricatorOwnersPackageOwnerDatasource(), ); } diff --git a/src/applications/owners/typeahead/PhabricatorOwnersPackageOwnerDatasource.php b/src/applications/owners/typeahead/PhabricatorOwnersPackageOwnerDatasource.php index 99e770d266..2a0b16e60f 100644 --- a/src/applications/owners/typeahead/PhabricatorOwnersPackageOwnerDatasource.php +++ b/src/applications/owners/typeahead/PhabricatorOwnersPackageOwnerDatasource.php @@ -27,7 +27,7 @@ final class PhabricatorOwnersPackageOwnerDatasource 'packages' => array( 'name' => pht('Packages: ...'), 'arguments' => pht('owner'), - 'summary' => pht("Find results in any of an owner's projects."), + 'summary' => pht("Find results in any of an owner's packages."), 'description' => pht( "This function allows you to find results associated with any ". "of the packages a specified user or project is an owner of. ". @@ -61,18 +61,21 @@ final class PhabricatorOwnersPackageOwnerDatasource $phids = $this->resolvePHIDs($phids); - $user_phids = array(); + $owner_phids = array(); foreach ($phids as $key => $phid) { - if (phid_get_type($phid) == PhabricatorPeopleUserPHIDType::TYPECONST) { - $user_phids[] = $phid; - unset($phids[$key]); + switch (phid_get_type($phid)) { + case PhabricatorPeopleUserPHIDType::TYPECONST: + case PhabricatorProjectProjectPHIDType::TYPECONST: + $owner_phids[] = $phid; + unset($phids[$key]); + break; } } - if ($user_phids) { + if ($owner_phids) { $packages = id(new PhabricatorOwnersPackageQuery()) ->setViewer($this->getViewer()) - ->withOwnerPHIDs($user_phids) + ->withOwnerPHIDs($owner_phids) ->execute(); foreach ($packages as $package) { $phids[] = $package->getPHID(); @@ -116,8 +119,13 @@ final class PhabricatorOwnersPackageOwnerDatasource $usernames = array(); foreach ($phids as $key => $phid) { - if (phid_get_type($phid) != PhabricatorPeopleUserPHIDType::TYPECONST) { - $usernames[$key] = $phid; + switch (phid_get_type($phid)) { + case PhabricatorPeopleUserPHIDType::TYPECONST: + case PhabricatorProjectProjectPHIDType::TYPECONST: + break; + default: + $usernames[$key] = $phid; + break; } }