Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/query/AlmanacQuery.php
<?php | <?php | ||||
abstract class AlmanacQuery | abstract class AlmanacQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $needProperties; | |||||
public function needProperties($need_properties) { | |||||
$this->needProperties = $need_properties; | |||||
return $this; | |||||
} | |||||
protected function getNeedProperties() { | |||||
return $this->needProperties; | |||||
} | |||||
protected function didFilterPage(array $objects) { | protected function didFilterPage(array $objects) { | ||||
if (head($objects) instanceof AlmanacPropertyInterface) { | $has_properties = (head($objects) instanceof AlmanacPropertyInterface); | ||||
// NOTE: We load properties for obsolete historical reasons. It may make | |||||
// sense to re-examine that assumption shortly. | |||||
if ($has_properties && $this->needProperties) { | |||||
$property_query = id(new AlmanacPropertyQuery()) | $property_query = id(new AlmanacPropertyQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->setParentQuery($this) | ->setParentQuery($this) | ||||
->withObjectPHIDs(mpull($objects, 'getPHID')); | ->withObjects($objects); | ||||
// NOTE: We disable policy filtering and object attachment to avoid | |||||
// a cyclic dependency where objects need their properties and properties | |||||
// need their objects. We'll attach the objects below, and have already | |||||
// implicitly checked the necessary policies. | |||||
$property_query->setDisablePolicyFilteringAndAttachment(true); | |||||
$properties = $property_query->execute(); | $properties = $property_query->execute(); | ||||
$properties = mgroup($properties, 'getObjectPHID'); | $properties = mgroup($properties, 'getObjectPHID'); | ||||
foreach ($objects as $object) { | foreach ($objects as $object) { | ||||
$object_properties = idx($properties, $object->getPHID(), array()); | $object_properties = idx($properties, $object->getPHID(), array()); | ||||
$object_properties = mpull($object_properties, null, 'getFieldName'); | $object_properties = mpull($object_properties, null, 'getFieldName'); | ||||
Show All 27 Lines |