Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/controller/HeraldTestConsoleController.php
Show All 40 Lines | public function handleRequest(AphrontRequest $request) { | ||||
$source = $this->newContentSource($object); | $source = $this->newContentSource($object); | ||||
$adapter | $adapter | ||||
->setContentSource($source) | ->setContentSource($source) | ||||
->setIsNewObject(false) | ->setIsNewObject(false) | ||||
->setActingAsPHID($viewer->getPHID()) | ->setActingAsPHID($viewer->getPHID()) | ||||
->setViewer($viewer); | ->setViewer($viewer); | ||||
$applied_xactions = $this->loadAppliedTransactions($object); | |||||
if ($applied_xactions !== null) { | |||||
$adapter->setAppliedTransactions($applied_xactions); | |||||
} | |||||
$rules = id(new HeraldRuleQuery()) | $rules = id(new HeraldRuleQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withContentTypes(array($adapter->getAdapterContentType())) | ->withContentTypes(array($adapter->getAdapterContentType())) | ||||
->withDisabled(false) | ->withDisabled(false) | ||||
->needConditionsAndActions(true) | ->needConditionsAndActions(true) | ||||
->needAppliedToPHIDs(array($object->getPHID())) | ->needAppliedToPHIDs(array($object->getPHID())) | ||||
->needValidateAuthors(true) | ->needValidateAuthors(true) | ||||
->execute(); | ->execute(); | ||||
▲ Show 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | private function newContentSource($object) { | ||||
// If we couldn't find a transaction (which should be rare), fall back to | // If we couldn't find a transaction (which should be rare), fall back to | ||||
// building a new content source from the test console request itself. | // building a new content source from the test console request itself. | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
return PhabricatorContentSource::newFromRequest($request); | return PhabricatorContentSource::newFromRequest($request); | ||||
} | } | ||||
private function loadAppliedTransactions($object) { | |||||
$viewer = $this->getViewer(); | |||||
if (!($object instanceof PhabricatorApplicationTransactionInterface)) { | |||||
return null; | |||||
} | |||||
$query = PhabricatorApplicationTransactionQuery::newQueryForObject( | |||||
$object); | |||||
$xactions = $query | |||||
->withObjectPHIDs(array($object->getPHID())) | |||||
->setViewer($viewer) | |||||
->setLimit(100) | |||||
->execute(); | |||||
$applied = array(); | |||||
// Pick the most recent group of transactions. This may not be exactly the | |||||
// same as what Herald acted on: for example, we may select a single group | |||||
// of transactions here which were really applied across two or more edits. | |||||
// Since this is relatively rare and we show you what we picked, it's okay | |||||
// that we just do roughly the right thing. | |||||
foreach ($xactions as $xaction) { | |||||
if (!$xaction->shouldDisplayGroupWith($applied)) { | |||||
break; | |||||
} | |||||
$applied[] = $xaction; | |||||
} | |||||
return $applied; | |||||
amckinley: Should we check if we've grouped all 100 of the fetched transactions together and start paging… | |||||
} | |||||
} | } |
Should we check if we've grouped all 100 of the fetched transactions together and start paging if we did? Or maybe just show a little "this simulation returned more than 100 recent transactions and is therefore only an approximate simulation" notice?