@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
3final class AlmanacProperty
4 extends AlmanacDAO
5 implements PhabricatorPolicyInterface {
6
7 protected $objectPHID;
8 protected $fieldIndex;
9 protected $fieldName;
10 protected $fieldValue;
11
12 private $object = self::ATTACHABLE;
13
14 protected function getConfiguration() {
15 return array(
16 self::CONFIG_TIMESTAMPS => false,
17 self::CONFIG_SERIALIZATION => array(
18 'fieldValue' => self::SERIALIZATION_JSON,
19 ),
20 self::CONFIG_COLUMN_SCHEMA => array(
21 'fieldIndex' => 'bytes12',
22 'fieldName' => 'text128',
23 ),
24 self::CONFIG_KEY_SCHEMA => array(
25 'objectPHID' => array(
26 'columns' => array('objectPHID', 'fieldIndex'),
27 'unique' => true,
28 ),
29 ),
30 ) + parent::getConfiguration();
31 }
32
33 public function getObject() {
34 return $this->assertAttached($this->object);
35 }
36
37 public function attachObject(PhabricatorLiskDAO $object) {
38 $this->object = $object;
39 return $this;
40 }
41
42 public static function newPropertyUpdateTransactions(
43 AlmanacPropertyInterface $object,
44 array $properties,
45 $only_builtins = false) {
46
47 $template = $object->getApplicationTransactionTemplate();
48 $builtins = $object->getAlmanacPropertyFieldSpecifications();
49
50 $xactions = array();
51 foreach ($properties as $name => $property) {
52 if ($only_builtins && empty($builtins[$name])) {
53 continue;
54 }
55
56 $xactions[] = id(clone $template)
57 ->setTransactionType($object->getAlmanacPropertySetTransactionType())
58 ->setMetadataValue('almanac.property', $name)
59 ->setNewValue($property);
60 }
61
62 return $xactions;
63 }
64
65 public static function newPropertyRemoveTransactions(
66 AlmanacPropertyInterface $object,
67 array $properties) {
68
69 $template = $object->getApplicationTransactionTemplate();
70
71 $xactions = array();
72 foreach ($properties as $property) {
73 $xactions[] = id(clone $template)
74 ->setTransactionType($object->getAlmanacPropertyDeleteTransactionType())
75 ->setMetadataValue('almanac.property', $property)
76 ->setNewValue(null);
77 }
78
79 return $xactions;
80 }
81
82 public function save() {
83 $hash = PhabricatorHash::digestForIndex($this->getFieldName());
84 $this->setFieldIndex($hash);
85
86 return parent::save();
87 }
88
89
90/* -( PhabricatorPolicyInterface )----------------------------------------- */
91
92
93 public function getCapabilities() {
94 return array(
95 PhabricatorPolicyCapability::CAN_VIEW,
96 PhabricatorPolicyCapability::CAN_EDIT,
97 );
98 }
99
100 public function getPolicy($capability) {
101 return $this->getObject()->getPolicy($capability);
102 }
103
104 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
105 return $this->getObject()->hasAutomaticCapability($capability, $viewer);
106 }
107
108 public function describeAutomaticCapability($capability) {
109 return pht('Properties inherit the policies of their object.');
110 }
111
112}