Path: blob/master/src/applications/almanac/storage/AlmanacProperty.php
12256 views
<?php12final class AlmanacProperty3extends AlmanacDAO4implements PhabricatorPolicyInterface {56protected $objectPHID;7protected $fieldIndex;8protected $fieldName;9protected $fieldValue;1011private $object = self::ATTACHABLE;1213protected function getConfiguration() {14return array(15self::CONFIG_TIMESTAMPS => false,16self::CONFIG_SERIALIZATION => array(17'fieldValue' => self::SERIALIZATION_JSON,18),19self::CONFIG_COLUMN_SCHEMA => array(20'fieldIndex' => 'bytes12',21'fieldName' => 'text128',22),23self::CONFIG_KEY_SCHEMA => array(24'objectPHID' => array(25'columns' => array('objectPHID', 'fieldIndex'),26'unique' => true,27),28),29) + parent::getConfiguration();30}3132public function getObject() {33return $this->assertAttached($this->object);34}3536public function attachObject(PhabricatorLiskDAO $object) {37$this->object = $object;38return $this;39}4041public static function newPropertyUpdateTransactions(42AlmanacPropertyInterface $object,43array $properties,44$only_builtins = false) {4546$template = $object->getApplicationTransactionTemplate();47$builtins = $object->getAlmanacPropertyFieldSpecifications();4849$xactions = array();50foreach ($properties as $name => $property) {51if ($only_builtins && empty($builtins[$name])) {52continue;53}5455$xactions[] = id(clone $template)56->setTransactionType($object->getAlmanacPropertySetTransactionType())57->setMetadataValue('almanac.property', $name)58->setNewValue($property);59}6061return $xactions;62}6364public static function newPropertyRemoveTransactions(65AlmanacPropertyInterface $object,66array $properties) {6768$template = $object->getApplicationTransactionTemplate();6970$xactions = array();71foreach ($properties as $property) {72$xactions[] = id(clone $template)73->setTransactionType($object->getAlmanacPropertyDeleteTransactionType())74->setMetadataValue('almanac.property', $property)75->setNewValue(null);76}7778return $xactions;79}8081public function save() {82$hash = PhabricatorHash::digestForIndex($this->getFieldName());83$this->setFieldIndex($hash);8485return parent::save();86}878889/* -( PhabricatorPolicyInterface )----------------------------------------- */909192public function getCapabilities() {93return array(94PhabricatorPolicyCapability::CAN_VIEW,95PhabricatorPolicyCapability::CAN_EDIT,96);97}9899public function getPolicy($capability) {100return $this->getObject()->getPolicy($capability);101}102103public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {104return $this->getObject()->hasAutomaticCapability($capability, $viewer);105}106107public function describeAutomaticCapability($capability) {108return pht('Properties inherit the policies of their object.');109}110111}112113114