Skip to content

Commit cd7171e

Browse files
author
epriestley
committed
Migrate old AuxiliaryField storage to modern CustomField storage
Summary: Ref T2222. Ref T3886. Differential has a legacy storage table for auxiliary fields; move the data to modern storage. Test Plan: - Ran migration. - Verified fields still worked properly afterward (view, edit, etc). Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3886, T2222 Differential Revision: https://secure.phabricator.com/D8355
1 parent ee2b6ee commit cd7171e

File tree

5 files changed

+45
-36
lines changed

5 files changed

+45
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
$conn_w = id(new DifferentialRevision())->establishConnection('w');
4+
$rows = new LiskRawMigrationIterator($conn_w, 'differential_auxiliaryfield');
5+
6+
echo "Modernizing Differential auxiliary field storage...\n";
7+
8+
$table_name = id(new DifferentialCustomFieldStorage())->getTableName();
9+
foreach ($rows as $row) {
10+
$id = $row['id'];
11+
echo "Migrating row {$id}...\n";
12+
queryfx(
13+
$conn_w,
14+
'INSERT IGNORE INTO %T (objectPHID, fieldIndex, fieldValue)
15+
VALUES (%s, %s, %s)',
16+
$table_name,
17+
$row['revisionPHID'],
18+
PhabricatorHash::digestForIndex($row['name']),
19+
$row['value']);
20+
}
21+
22+
echo "Done.\n";

src/__phutil_library_map__.php

-1
Original file line numberDiff line numberDiff line change
@@ -2891,7 +2891,6 @@
28912891
'DifferentialAuditorsFieldSpecification' => 'DifferentialFieldSpecification',
28922892
'DifferentialAuthorField' => 'DifferentialCustomField',
28932893
'DifferentialAuthorFieldSpecification' => 'DifferentialFieldSpecification',
2894-
'DifferentialAuxiliaryField' => 'DifferentialDAO',
28952894
'DifferentialBlameRevisionFieldSpecification' => 'DifferentialFieldSpecification',
28962895
'DifferentialBranchFieldSpecification' => 'DifferentialFieldSpecification',
28972896
'DifferentialCCWelcomeMail' => 'DifferentialReviewRequestMail',

src/applications/differential/editor/DifferentialRevisionEditor.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -707,14 +707,14 @@ private function updateAuxiliaryFields() {
707707

708708
$revision = $this->revision;
709709

710-
$fields = id(new DifferentialAuxiliaryField())->loadAllWhere(
711-
'revisionPHID = %s AND name IN (%Ls)',
712-
$revision->getPHID(),
713-
array_keys($aux_map));
714-
$fields = mpull($fields, null, 'getName');
710+
$fields = id(new DifferentialCustomFieldStorage())->loadAllWhere(
711+
'objectPHID = %s',
712+
$revision->getPHID());
713+
$fields = mpull($fields, null, 'getFieldIndex');
715714

716715
foreach ($aux_map as $key => $val) {
717-
$obj = idx($fields, $key);
716+
$index = PhabricatorHash::digestForIndex($key);
717+
$obj = idx($fields, $index);
718718
if (!strlen($val)) {
719719
// If the new value is empty, just delete the old row if one exists and
720720
// don't add a new row if it doesn't.
@@ -723,9 +723,9 @@ private function updateAuxiliaryFields() {
723723
}
724724
} else {
725725
if (!$obj) {
726-
$obj = new DifferentialAuxiliaryField();
727-
$obj->setRevisionPHID($revision->getPHID());
728-
$obj->setName($key);
726+
$obj = new DifferentialCustomFieldStorage();
727+
$obj->setObjectPHID($revision->getPHID());
728+
$obj->setFieldIndex($index);
729729
}
730730

731731
if ($obj->getValue() !== $val) {

src/applications/differential/storage/DifferentialAuxiliaryField.php

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
<?php
22

3-
final class DifferentialAuxiliaryField extends DifferentialDAO {
4-
5-
protected $revisionPHID;
6-
protected $name;
7-
protected $value;
8-
9-
public function setName($name) {
10-
if (strlen($name) > 32) {
11-
throw new Exception(
12-
"Tried to set name '{$name}' for a Differential auxiliary field; ".
13-
"auxiliary field names must be no longer than 32 characters.");
14-
}
15-
$this->name = $name;
16-
return $this;
17-
}
3+
final class DifferentialAuxiliaryField {
184

195
public static function loadFromStorage(
206
DifferentialRevision $revision,
@@ -24,11 +10,20 @@ public static function loadFromStorage(
2410
$storage_keys = array_filter(mpull($aux_fields, 'getStorageKey'));
2511
$field_data = array();
2612
if ($storage_keys) {
27-
$field_data = id(new DifferentialAuxiliaryField())->loadAllWhere(
28-
'revisionPHID = %s AND name IN (%Ls)',
13+
$index_map = array();
14+
foreach ($storage_keys as $key) {
15+
$index_map[PhabricatorHash::digestForIndex($key)] = $key;
16+
}
17+
18+
$index_data = id(new DifferentialCustomFieldStorage())->loadAllWhere(
19+
'objectPHID = %s AND fieldIndex IN (%Ls)',
2920
$revision->getPHID(),
30-
$storage_keys);
31-
$field_data = mpull($field_data, 'getValue', 'getName');
21+
array_keys($index_map));
22+
$index_data = mpull($index_data, 'getFieldValue', 'getFieldIndex');
23+
24+
foreach ($index_data as $index => $data) {
25+
$field_data[$index_map[$index]] = $data;
26+
}
3227
}
3328

3429
foreach ($aux_fields as $aux_field) {

src/applications/differential/storage/DifferentialRevision.php

-7
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,6 @@ public function delete() {
209209
$inline->delete();
210210
}
211211

212-
$fields = id(new DifferentialAuxiliaryField())->loadAllWhere(
213-
'revisionPHID = %s',
214-
$this->getPHID());
215-
foreach ($fields as $field) {
216-
$field->delete();
217-
}
218-
219212
// we have to do paths a little differentally as they do not have
220213
// an id or phid column for delete() to act on
221214
$dummy_path = new DifferentialAffectedPath();

0 commit comments

Comments
 (0)