@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * @template R of PhabricatorPolicyInterface
5 * @extends PhabricatorCursorPagedPolicyAwareQuery<R>
6 */
7abstract class AlmanacQuery
8 extends PhabricatorCursorPagedPolicyAwareQuery {
9
10 private $needProperties;
11
12 public function needProperties($need_properties) {
13 $this->needProperties = $need_properties;
14 return $this;
15 }
16
17 protected function getNeedProperties() {
18 return $this->needProperties;
19 }
20
21 protected function didFilterPage(array $objects) {
22 $has_properties = (head($objects) instanceof AlmanacPropertyInterface);
23
24 if ($has_properties && $this->needProperties) {
25 $property_query = id(new AlmanacPropertyQuery())
26 ->setViewer($this->getViewer())
27 ->setParentQuery($this)
28 ->withObjects($objects);
29
30 $properties = $property_query->execute();
31
32 $properties = mgroup($properties, 'getObjectPHID');
33 foreach ($objects as $object) {
34 $object_properties = idx($properties, $object->getPHID(), array());
35 $object_properties = mpull($object_properties, null, 'getFieldName');
36
37 // Create synthetic properties for defaults on the object itself.
38 $specs = $object->getAlmanacPropertyFieldSpecifications();
39 foreach ($specs as $key => $spec) {
40 if (empty($object_properties[$key])) {
41 $default_value = $spec->getValueForTransaction();
42
43 $object_properties[$key] = id(new AlmanacProperty())
44 ->setObjectPHID($object->getPHID())
45 ->setFieldName($key)
46 ->setFieldValue($default_value);
47 }
48 }
49
50 foreach ($object_properties as $property) {
51 $property->attachObject($object);
52 }
53
54 $object->attachAlmanacProperties($object_properties);
55 }
56 }
57
58 return $objects;
59 }
60
61 public function getQueryApplicationClass() {
62 return PhabricatorAlmanacApplication::class;
63 }
64
65}