Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / infrastructure / customfield / storage / PhabricatorCustomFieldStorage.php
blob0f60d7760265984856fbcc16ba480ca8740fcf82
1 <?php
3 abstract class PhabricatorCustomFieldStorage
4 extends PhabricatorLiskDAO {
6 protected $objectPHID;
7 protected $fieldIndex;
8 protected $fieldValue;
10 protected function getConfiguration() {
11 return array(
12 self::CONFIG_TIMESTAMPS => false,
13 self::CONFIG_COLUMN_SCHEMA => array(
14 'fieldIndex' => 'bytes12',
15 'fieldValue' => 'text',
17 self::CONFIG_KEY_SCHEMA => array(
18 'objectPHID' => array(
19 'columns' => array('objectPHID', 'fieldIndex'),
20 'unique' => true,
23 ) + parent::getConfiguration();
27 /**
28 * Get a key which uniquely identifies this storage source.
30 * When loading custom fields, fields using sources with the same source key
31 * are loaded in bulk.
33 * @return string Source identifier.
35 final public function getStorageSourceKey() {
36 return $this->getApplicationName().'/'.$this->getTableName();
40 /**
41 * Load stored data for custom fields.
43 * Given a map of fields, return a map with any stored data for those fields.
44 * The keys in the result should correspond to the keys in the input. The
45 * fields in the list may belong to different objects.
47 * @param map<string, PhabricatorCustomField> Map of fields.
48 * @return map<String, PhabricatorCustomField> Map of available field data.
50 final public function loadStorageSourceData(array $fields) {
51 $map = array();
52 $indexes = array();
53 $object_phids = array();
55 foreach ($fields as $key => $field) {
56 $index = $field->getFieldIndex();
57 $object_phid = $field->getObject()->getPHID();
59 $map[$index][$object_phid] = $key;
60 $indexes[$index] = $index;
61 $object_phids[$object_phid] = $object_phid;
64 if (!$indexes) {
65 return array();
68 $conn = $this->establishConnection('r');
69 $rows = queryfx_all(
70 $conn,
71 'SELECT objectPHID, fieldIndex, fieldValue FROM %T
72 WHERE objectPHID IN (%Ls) AND fieldIndex IN (%Ls)',
73 $this->getTableName(),
74 $object_phids,
75 $indexes);
77 $result = array();
78 foreach ($rows as $row) {
79 $index = $row['fieldIndex'];
80 $object_phid = $row['objectPHID'];
81 $value = $row['fieldValue'];
83 $key = $map[$index][$object_phid];
84 $result[$key] = $value;
87 return $result;