From b8f0613b30dd9c7f37257d514aaa3ea639ab8c57 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 21 Feb 2020 07:57:25 -0800 Subject: [PATCH] Update Asana feed publishing integration for "ExternalAccountIdentifier" Summary: Depends on D21017. Ref T13493. Update the Asana integration so it reads the "ExternalAccountIdentifier" table instead of the old "accountID" field. Test Plan: Linked an Asana account, used `bin/feed republish` to publish activity to Asana. Maniphest Tasks: T13493 Differential Revision: https://secure.phabricator.com/D21018 --- .../worker/DoorkeeperAsanaFeedWorker.php | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/applications/doorkeeper/worker/DoorkeeperAsanaFeedWorker.php b/src/applications/doorkeeper/worker/DoorkeeperAsanaFeedWorker.php index 00b75b7a56..349fbc9d75 100644 --- a/src/applications/doorkeeper/worker/DoorkeeperAsanaFeedWorker.php +++ b/src/applications/doorkeeper/worker/DoorkeeperAsanaFeedWorker.php @@ -532,6 +532,7 @@ final class DoorkeeperAsanaFeedWorker extends DoorkeeperFeedWorker { ->withUserPHIDs($all_phids) ->withAccountTypes(array($provider->getProviderType())) ->withAccountDomains(array($provider->getProviderDomain())) + ->needAccountIdentifiers(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, @@ -540,7 +541,7 @@ final class DoorkeeperAsanaFeedWorker extends DoorkeeperFeedWorker { ->execute(); foreach ($accounts as $account) { - $phid_map[$account->getUserPHID()] = $account->getAccountID(); + $phid_map[$account->getUserPHID()] = $this->getAsanaAccountID($account); } // Put this back in input order. @@ -562,6 +563,7 @@ final class DoorkeeperAsanaFeedWorker extends DoorkeeperFeedWorker { ->withUserPHIDs($user_phids) ->withAccountTypes(array($provider->getProviderType())) ->withAccountDomains(array($provider->getProviderDomain())) + ->needAccountIdentifiers(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, @@ -601,7 +603,7 @@ final class DoorkeeperAsanaFeedWorker extends DoorkeeperFeedWorker { ->withPHIDs(array($account->getUserPHID())) ->executeOne(); if ($user) { - return array($user, $account->getAccountID(), $token); + return array($user, $this->getAsanaAccountID($account), $token); } } @@ -706,4 +708,20 @@ final class DoorkeeperAsanaFeedWorker extends DoorkeeperFeedWorker { } } + private function getAsanaAccountID(PhabricatorExternalAccount $account) { + $identifiers = $account->getAccountIdentifiers(); + + if (count($identifiers) !== 1) { + throw new Exception( + pht( + 'Expected external Asana account to have exactly one external '. + 'account identifier, found %s.', + phutil_count($identifiers))); + } + + return head($identifiers)->getIdentifierRaw(); + } + + + }