Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/customfield/storage/PhabricatorCustomFieldStorage.php
13418 views
1
<?php
2
3
abstract class PhabricatorCustomFieldStorage
4
extends PhabricatorLiskDAO {
5
6
protected $objectPHID;
7
protected $fieldIndex;
8
protected $fieldValue;
9
10
protected function getConfiguration() {
11
return array(
12
self::CONFIG_TIMESTAMPS => false,
13
self::CONFIG_COLUMN_SCHEMA => array(
14
'fieldIndex' => 'bytes12',
15
'fieldValue' => 'text',
16
),
17
self::CONFIG_KEY_SCHEMA => array(
18
'objectPHID' => array(
19
'columns' => array('objectPHID', 'fieldIndex'),
20
'unique' => true,
21
),
22
),
23
) + parent::getConfiguration();
24
}
25
26
27
/**
28
* Get a key which uniquely identifies this storage source.
29
*
30
* When loading custom fields, fields using sources with the same source key
31
* are loaded in bulk.
32
*
33
* @return string Source identifier.
34
*/
35
final public function getStorageSourceKey() {
36
return $this->getApplicationName().'/'.$this->getTableName();
37
}
38
39
40
/**
41
* Load stored data for custom fields.
42
*
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.
46
*
47
* @param map<string, PhabricatorCustomField> Map of fields.
48
* @return map<String, PhabricatorCustomField> Map of available field data.
49
*/
50
final public function loadStorageSourceData(array $fields) {
51
$map = array();
52
$indexes = array();
53
$object_phids = array();
54
55
foreach ($fields as $key => $field) {
56
$index = $field->getFieldIndex();
57
$object_phid = $field->getObject()->getPHID();
58
59
$map[$index][$object_phid] = $key;
60
$indexes[$index] = $index;
61
$object_phids[$object_phid] = $object_phid;
62
}
63
64
if (!$indexes) {
65
return array();
66
}
67
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);
76
77
$result = array();
78
foreach ($rows as $row) {
79
$index = $row['fieldIndex'];
80
$object_phid = $row['objectPHID'];
81
$value = $row['fieldValue'];
82
83
$key = $map[$index][$object_phid];
84
$result[$key] = $value;
85
}
86
87
return $result;
88
}
89
90
}
91
92