Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/storage/DifferentialAuxiliaryField.php
<?php | <?php | ||||
final class DifferentialAuxiliaryField extends DifferentialDAO { | final class DifferentialAuxiliaryField { | ||||
protected $revisionPHID; | |||||
protected $name; | |||||
protected $value; | |||||
public function setName($name) { | |||||
if (strlen($name) > 32) { | |||||
throw new Exception( | |||||
"Tried to set name '{$name}' for a Differential auxiliary field; ". | |||||
"auxiliary field names must be no longer than 32 characters."); | |||||
} | |||||
$this->name = $name; | |||||
return $this; | |||||
} | |||||
public static function loadFromStorage( | public static function loadFromStorage( | ||||
DifferentialRevision $revision, | DifferentialRevision $revision, | ||||
array $aux_fields) { | array $aux_fields) { | ||||
assert_instances_of($aux_fields, 'DifferentialFieldSpecification'); | assert_instances_of($aux_fields, 'DifferentialFieldSpecification'); | ||||
$storage_keys = array_filter(mpull($aux_fields, 'getStorageKey')); | $storage_keys = array_filter(mpull($aux_fields, 'getStorageKey')); | ||||
$field_data = array(); | $field_data = array(); | ||||
if ($storage_keys) { | if ($storage_keys) { | ||||
$field_data = id(new DifferentialAuxiliaryField())->loadAllWhere( | $index_map = array(); | ||||
'revisionPHID = %s AND name IN (%Ls)', | foreach ($storage_keys as $key) { | ||||
$index_map[PhabricatorHash::digestForIndex($key)] = $key; | |||||
} | |||||
$index_data = id(new DifferentialCustomFieldStorage())->loadAllWhere( | |||||
'objectPHID = %s AND fieldIndex IN (%Ls)', | |||||
$revision->getPHID(), | $revision->getPHID(), | ||||
$storage_keys); | array_keys($index_map)); | ||||
$field_data = mpull($field_data, 'getValue', 'getName'); | $index_data = mpull($index_data, 'getFieldValue', 'getFieldIndex'); | ||||
foreach ($index_data as $index => $data) { | |||||
$field_data[$index_map[$index]] = $data; | |||||
} | |||||
} | } | ||||
foreach ($aux_fields as $aux_field) { | foreach ($aux_fields as $aux_field) { | ||||
$aux_field->setRevision($revision); | $aux_field->setRevision($revision); | ||||
$key = $aux_field->getStorageKey(); | $key = $aux_field->getStorageKey(); | ||||
if ($key) { | if ($key) { | ||||
$aux_field->setValueFromStorage(idx($field_data, $key)); | $aux_field->setValueFromStorage(idx($field_data, $key)); | ||||
} | } | ||||
} | } | ||||
return $aux_fields; | return $aux_fields; | ||||
} | } | ||||
} | } |