Differential D14837 Diff 35865 src/applications/transactions/worker/PhabricatorApplicationTransactionPublishWorker.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/worker/PhabricatorApplicationTransactionPublishWorker.php
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | private function loadTransactions( | ||||
$xaction_phids = idx($data, 'xactionPHIDs'); | $xaction_phids = idx($data, 'xactionPHIDs'); | ||||
if (!$xaction_phids) { | if (!$xaction_phids) { | ||||
throw new PhabricatorWorkerPermanentFailureException( | throw new PhabricatorWorkerPermanentFailureException( | ||||
pht('Task has no transaction PHIDs!')); | pht('Task has no transaction PHIDs!')); | ||||
} | } | ||||
$viewer = PhabricatorUser::getOmnipotentUser(); | $viewer = PhabricatorUser::getOmnipotentUser(); | ||||
$type = phid_get_subtype(head($xaction_phids)); | $query = PhabricatorApplicationTransactionQuery::newQueryForObject($object); | ||||
$xactions = $this->buildTransactionQuery($type) | if (!$query) { | ||||
throw new PhabricatorWorkerPermanentFailureException( | |||||
pht( | |||||
'Unable to load query for transaction object "%s"!', | |||||
$object->getPHID())); | |||||
} | |||||
$xactions = $query | |||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs($xaction_phids) | ->withPHIDs($xaction_phids) | ||||
->needComments(true) | ->needComments(true) | ||||
->execute(); | ->execute(); | ||||
$xactions = mpull($xactions, null, 'getPHID'); | $xactions = mpull($xactions, null, 'getPHID'); | ||||
$missing = array_diff($xaction_phids, array_keys($xactions)); | $missing = array_diff($xaction_phids, array_keys($xactions)); | ||||
if ($missing) { | if ($missing) { | ||||
throw new PhabricatorWorkerPermanentFailureException( | throw new PhabricatorWorkerPermanentFailureException( | ||||
pht( | pht( | ||||
'Unable to load transactions: %s.', | 'Unable to load transactions: %s.', | ||||
implode(', ', $missing))); | implode(', ', $missing))); | ||||
} | } | ||||
return array_select_keys($xactions, $xaction_phids); | return array_select_keys($xactions, $xaction_phids); | ||||
} | } | ||||
/** | |||||
* Build a new transaction query of the appropriate class so we can load | |||||
* the transactions. | |||||
*/ | |||||
private function buildTransactionQuery($type) { | |||||
$queries = id(new PhutilClassMapQuery()) | |||||
->setAncestorClass('PhabricatorApplicationTransactionQuery') | |||||
->execute(); | |||||
foreach ($queries as $query) { | |||||
$query_type = $query | |||||
->getTemplateApplicationTransaction() | |||||
->getApplicationTransactionType(); | |||||
if ($query_type == $type) { | |||||
return $query; | |||||
} | |||||
} | |||||
throw new PhabricatorWorkerPermanentFailureException( | |||||
pht( | |||||
'Unable to load query for transaction type "%s"!', | |||||
$type)); | |||||
} | |||||
} | } |