mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-21 00:30:09 +01:00
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
This commit is contained in:
parent
ee2b6eebaa
commit
cd7171ec6e
5 changed files with 45 additions and 36 deletions
22
resources/sql/autopatches/20140226.dxcustom.1.fielddata.php
Normal file
22
resources/sql/autopatches/20140226.dxcustom.1.fielddata.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
$conn_w = id(new DifferentialRevision())->establishConnection('w');
|
||||
$rows = new LiskRawMigrationIterator($conn_w, 'differential_auxiliaryfield');
|
||||
|
||||
echo "Modernizing Differential auxiliary field storage...\n";
|
||||
|
||||
$table_name = id(new DifferentialCustomFieldStorage())->getTableName();
|
||||
foreach ($rows as $row) {
|
||||
$id = $row['id'];
|
||||
echo "Migrating row {$id}...\n";
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'INSERT IGNORE INTO %T (objectPHID, fieldIndex, fieldValue)
|
||||
VALUES (%s, %s, %s)',
|
||||
$table_name,
|
||||
$row['revisionPHID'],
|
||||
PhabricatorHash::digestForIndex($row['name']),
|
||||
$row['value']);
|
||||
}
|
||||
|
||||
echo "Done.\n";
|
|
@ -2891,7 +2891,6 @@ phutil_register_library_map(array(
|
|||
'DifferentialAuditorsFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialAuthorField' => 'DifferentialCustomField',
|
||||
'DifferentialAuthorFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialAuxiliaryField' => 'DifferentialDAO',
|
||||
'DifferentialBlameRevisionFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialBranchFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialCCWelcomeMail' => 'DifferentialReviewRequestMail',
|
||||
|
|
|
@ -707,14 +707,14 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
|
|||
|
||||
$revision = $this->revision;
|
||||
|
||||
$fields = id(new DifferentialAuxiliaryField())->loadAllWhere(
|
||||
'revisionPHID = %s AND name IN (%Ls)',
|
||||
$revision->getPHID(),
|
||||
array_keys($aux_map));
|
||||
$fields = mpull($fields, null, 'getName');
|
||||
$fields = id(new DifferentialCustomFieldStorage())->loadAllWhere(
|
||||
'objectPHID = %s',
|
||||
$revision->getPHID());
|
||||
$fields = mpull($fields, null, 'getFieldIndex');
|
||||
|
||||
foreach ($aux_map as $key => $val) {
|
||||
$obj = idx($fields, $key);
|
||||
$index = PhabricatorHash::digestForIndex($key);
|
||||
$obj = idx($fields, $index);
|
||||
if (!strlen($val)) {
|
||||
// If the new value is empty, just delete the old row if one exists and
|
||||
// don't add a new row if it doesn't.
|
||||
|
@ -723,9 +723,9 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
|
|||
}
|
||||
} else {
|
||||
if (!$obj) {
|
||||
$obj = new DifferentialAuxiliaryField();
|
||||
$obj->setRevisionPHID($revision->getPHID());
|
||||
$obj->setName($key);
|
||||
$obj = new DifferentialCustomFieldStorage();
|
||||
$obj->setObjectPHID($revision->getPHID());
|
||||
$obj->setFieldIndex($index);
|
||||
}
|
||||
|
||||
if ($obj->getValue() !== $val) {
|
||||
|
|
|
@ -1,20 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialAuxiliaryField extends DifferentialDAO {
|
||||
|
||||
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;
|
||||
}
|
||||
final class DifferentialAuxiliaryField {
|
||||
|
||||
public static function loadFromStorage(
|
||||
DifferentialRevision $revision,
|
||||
|
@ -24,11 +10,20 @@ final class DifferentialAuxiliaryField extends DifferentialDAO {
|
|||
$storage_keys = array_filter(mpull($aux_fields, 'getStorageKey'));
|
||||
$field_data = array();
|
||||
if ($storage_keys) {
|
||||
$field_data = id(new DifferentialAuxiliaryField())->loadAllWhere(
|
||||
'revisionPHID = %s AND name IN (%Ls)',
|
||||
$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)',
|
||||
$revision->getPHID(),
|
||||
$storage_keys);
|
||||
$field_data = mpull($field_data, 'getValue', 'getName');
|
||||
array_keys($index_map));
|
||||
$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) {
|
||||
|
|
|
@ -209,13 +209,6 @@ final class DifferentialRevision extends DifferentialDAO
|
|||
$inline->delete();
|
||||
}
|
||||
|
||||
$fields = id(new DifferentialAuxiliaryField())->loadAllWhere(
|
||||
'revisionPHID = %s',
|
||||
$this->getPHID());
|
||||
foreach ($fields as $field) {
|
||||
$field->delete();
|
||||
}
|
||||
|
||||
// we have to do paths a little differentally as they do not have
|
||||
// an id or phid column for delete() to act on
|
||||
$dummy_path = new DifferentialAffectedPath();
|
||||
|
|
Loading…
Add table
Reference in a new issue