2011-08-10 20:29:08 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-27 01:52:30 +01:00
|
|
|
final class DifferentialAuxiliaryField {
|
2011-08-10 20:29:08 +02:00
|
|
|
|
2011-08-10 22:46:01 +02:00
|
|
|
public static function loadFromStorage(
|
|
|
|
DifferentialRevision $revision,
|
|
|
|
array $aux_fields) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($aux_fields, 'DifferentialFieldSpecification');
|
2011-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
$storage_keys = array_filter(mpull($aux_fields, 'getStorageKey'));
|
|
|
|
$field_data = array();
|
|
|
|
if ($storage_keys) {
|
2014-02-27 01:52:30 +01:00
|
|
|
$index_map = array();
|
|
|
|
foreach ($storage_keys as $key) {
|
|
|
|
$index_map[PhabricatorHash::digestForIndex($key)] = $key;
|
|
|
|
}
|
|
|
|
|
|
|
|
$index_data = id(new DifferentialCustomFieldStorage())->loadAllWhere(
|
|
|
|
'objectPHID = %s AND fieldIndex IN (%Ls)',
|
2011-08-10 22:46:01 +02:00
|
|
|
$revision->getPHID(),
|
2014-02-27 01:52:30 +01:00
|
|
|
array_keys($index_map));
|
|
|
|
$index_data = mpull($index_data, 'getFieldValue', 'getFieldIndex');
|
|
|
|
|
|
|
|
foreach ($index_data as $index => $data) {
|
|
|
|
$field_data[$index_map[$index]] = $data;
|
|
|
|
}
|
2011-08-10 22:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($aux_fields as $aux_field) {
|
2011-08-14 20:29:56 +02:00
|
|
|
$aux_field->setRevision($revision);
|
2011-08-10 22:46:01 +02:00
|
|
|
$key = $aux_field->getStorageKey();
|
|
|
|
if ($key) {
|
|
|
|
$aux_field->setValueFromStorage(idx($field_data, $key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $aux_fields;
|
|
|
|
}
|
|
|
|
|
2011-08-10 20:29:08 +02:00
|
|
|
}
|