Path: blob/master/src/infrastructure/customfield/storage/PhabricatorCustomFieldStorage.php
13418 views
<?php12abstract class PhabricatorCustomFieldStorage3extends PhabricatorLiskDAO {45protected $objectPHID;6protected $fieldIndex;7protected $fieldValue;89protected function getConfiguration() {10return array(11self::CONFIG_TIMESTAMPS => false,12self::CONFIG_COLUMN_SCHEMA => array(13'fieldIndex' => 'bytes12',14'fieldValue' => 'text',15),16self::CONFIG_KEY_SCHEMA => array(17'objectPHID' => array(18'columns' => array('objectPHID', 'fieldIndex'),19'unique' => true,20),21),22) + parent::getConfiguration();23}242526/**27* Get a key which uniquely identifies this storage source.28*29* When loading custom fields, fields using sources with the same source key30* are loaded in bulk.31*32* @return string Source identifier.33*/34final public function getStorageSourceKey() {35return $this->getApplicationName().'/'.$this->getTableName();36}373839/**40* Load stored data for custom fields.41*42* Given a map of fields, return a map with any stored data for those fields.43* The keys in the result should correspond to the keys in the input. The44* fields in the list may belong to different objects.45*46* @param map<string, PhabricatorCustomField> Map of fields.47* @return map<String, PhabricatorCustomField> Map of available field data.48*/49final public function loadStorageSourceData(array $fields) {50$map = array();51$indexes = array();52$object_phids = array();5354foreach ($fields as $key => $field) {55$index = $field->getFieldIndex();56$object_phid = $field->getObject()->getPHID();5758$map[$index][$object_phid] = $key;59$indexes[$index] = $index;60$object_phids[$object_phid] = $object_phid;61}6263if (!$indexes) {64return array();65}6667$conn = $this->establishConnection('r');68$rows = queryfx_all(69$conn,70'SELECT objectPHID, fieldIndex, fieldValue FROM %T71WHERE objectPHID IN (%Ls) AND fieldIndex IN (%Ls)',72$this->getTableName(),73$object_phids,74$indexes);7576$result = array();77foreach ($rows as $row) {78$index = $row['fieldIndex'];79$object_phid = $row['objectPHID'];80$value = $row['fieldValue'];8182$key = $map[$index][$object_phid];83$result[$key] = $value;84}8586return $result;87}8889}909192