Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / storage / AlmanacProperty.php
blobbd3fe83347b3cdc022ceaf0c8ce5f5788297892a
1 <?php
3 final class AlmanacProperty
4 extends AlmanacDAO
5 implements PhabricatorPolicyInterface {
7 protected $objectPHID;
8 protected $fieldIndex;
9 protected $fieldName;
10 protected $fieldValue;
12 private $object = self::ATTACHABLE;
14 protected function getConfiguration() {
15 return array(
16 self::CONFIG_TIMESTAMPS => false,
17 self::CONFIG_SERIALIZATION => array(
18 'fieldValue' => self::SERIALIZATION_JSON,
20 self::CONFIG_COLUMN_SCHEMA => array(
21 'fieldIndex' => 'bytes12',
22 'fieldName' => 'text128',
24 self::CONFIG_KEY_SCHEMA => array(
25 'objectPHID' => array(
26 'columns' => array('objectPHID', 'fieldIndex'),
27 'unique' => true,
30 ) + parent::getConfiguration();
33 public function getObject() {
34 return $this->assertAttached($this->object);
37 public function attachObject(PhabricatorLiskDAO $object) {
38 $this->object = $object;
39 return $this;
42 public static function newPropertyUpdateTransactions(
43 AlmanacPropertyInterface $object,
44 array $properties,
45 $only_builtins = false) {
47 $template = $object->getApplicationTransactionTemplate();
48 $builtins = $object->getAlmanacPropertyFieldSpecifications();
50 $xactions = array();
51 foreach ($properties as $name => $property) {
52 if ($only_builtins && empty($builtins[$name])) {
53 continue;
56 $xactions[] = id(clone $template)
57 ->setTransactionType($object->getAlmanacPropertySetTransactionType())
58 ->setMetadataValue('almanac.property', $name)
59 ->setNewValue($property);
62 return $xactions;
65 public static function newPropertyRemoveTransactions(
66 AlmanacPropertyInterface $object,
67 array $properties) {
69 $template = $object->getApplicationTransactionTemplate();
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);
79 return $xactions;
82 public function save() {
83 $hash = PhabricatorHash::digestForIndex($this->getFieldName());
84 $this->setFieldIndex($hash);
86 return parent::save();
90 /* -( PhabricatorPolicyInterface )----------------------------------------- */
93 public function getCapabilities() {
94 return array(
95 PhabricatorPolicyCapability::CAN_VIEW,
96 PhabricatorPolicyCapability::CAN_EDIT,
100 public function getPolicy($capability) {
101 return $this->getObject()->getPolicy($capability);
104 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
105 return $this->getObject()->hasAutomaticCapability($capability, $viewer);
108 public function describeAutomaticCapability($capability) {
109 return pht('Properties inherit the policies of their object.');