mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 03:50:54 +01:00
Migrate auxiliary field storage to common field storage
Summary: Ref T418. Moves data from the Maniphest-specific table to the general one. This patch is a bit gross, but mostly about getting the reads and writes aimed correctly. Future patches will clean things up. Test Plan: Migrated data across formats. Verified it survied the migration. Viewed and edited tasks' custom fields. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T418 Differential Revision: https://secure.phabricator.com/D6999
This commit is contained in:
parent
28eaacb491
commit
bd40e74400
8 changed files with 68 additions and 39 deletions
25
resources/sql/patches/20130915.maniphestmigrate.php
Normal file
25
resources/sql/patches/20130915.maniphestmigrate.php
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$conn_w = id(new ManiphestTask())->establishConnection('w');
|
||||||
|
$table_name = id(new ManiphestCustomFieldStorage())->getTableName();
|
||||||
|
|
||||||
|
$rows = new LiskRawMigrationIterator($conn_w, 'maniphest_taskauxiliarystorage');
|
||||||
|
|
||||||
|
echo "Migrating custom storage for Maniphest fields...\n";
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$phid = $row['taskPHID'];
|
||||||
|
$name = $row['name'];
|
||||||
|
|
||||||
|
echo "Migrating {$phid} / {$name}...\n";
|
||||||
|
|
||||||
|
queryfx(
|
||||||
|
$conn_w,
|
||||||
|
'INSERT IGNORE INTO %T (objectPHID, fieldIndex, fieldValue)
|
||||||
|
VALUES (%s, %s, %s)',
|
||||||
|
$table_name,
|
||||||
|
$phid,
|
||||||
|
PhabricatorHash::digestForIndex('std:maniphest:'.$name),
|
||||||
|
$row['value']);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Done.\n";
|
|
@ -711,7 +711,6 @@ phutil_register_library_map(array(
|
||||||
'ManiphestSubpriorityController' => 'applications/maniphest/controller/ManiphestSubpriorityController.php',
|
'ManiphestSubpriorityController' => 'applications/maniphest/controller/ManiphestSubpriorityController.php',
|
||||||
'ManiphestSubscribeController' => 'applications/maniphest/controller/ManiphestSubscribeController.php',
|
'ManiphestSubscribeController' => 'applications/maniphest/controller/ManiphestSubscribeController.php',
|
||||||
'ManiphestTask' => 'applications/maniphest/storage/ManiphestTask.php',
|
'ManiphestTask' => 'applications/maniphest/storage/ManiphestTask.php',
|
||||||
'ManiphestTaskAuxiliaryStorage' => 'applications/maniphest/storage/ManiphestTaskAuxiliaryStorage.php',
|
|
||||||
'ManiphestTaskDescriptionChangeController' => 'applications/maniphest/controller/ManiphestTaskDescriptionChangeController.php',
|
'ManiphestTaskDescriptionChangeController' => 'applications/maniphest/controller/ManiphestTaskDescriptionChangeController.php',
|
||||||
'ManiphestTaskDescriptionPreviewController' => 'applications/maniphest/controller/ManiphestTaskDescriptionPreviewController.php',
|
'ManiphestTaskDescriptionPreviewController' => 'applications/maniphest/controller/ManiphestTaskDescriptionPreviewController.php',
|
||||||
'ManiphestTaskDetailController' => 'applications/maniphest/controller/ManiphestTaskDetailController.php',
|
'ManiphestTaskDetailController' => 'applications/maniphest/controller/ManiphestTaskDetailController.php',
|
||||||
|
@ -2783,7 +2782,6 @@ phutil_register_library_map(array(
|
||||||
4 => 'PhrequentTrackableInterface',
|
4 => 'PhrequentTrackableInterface',
|
||||||
5 => 'PhabricatorCustomFieldInterface',
|
5 => 'PhabricatorCustomFieldInterface',
|
||||||
),
|
),
|
||||||
'ManiphestTaskAuxiliaryStorage' => 'ManiphestDAO',
|
|
||||||
'ManiphestTaskDescriptionChangeController' => 'ManiphestController',
|
'ManiphestTaskDescriptionChangeController' => 'ManiphestController',
|
||||||
'ManiphestTaskDescriptionPreviewController' => 'ManiphestController',
|
'ManiphestTaskDescriptionPreviewController' => 'ManiphestController',
|
||||||
'ManiphestTaskDetailController' => 'ManiphestController',
|
'ManiphestTaskDetailController' => 'ManiphestController',
|
||||||
|
|
|
@ -42,7 +42,7 @@ abstract class ManiphestAuxiliaryFieldSpecification
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAuxiliaryKey() {
|
public function getAuxiliaryKey() {
|
||||||
return $this->auxiliaryKey;
|
return 'std:maniphest:'.$this->auxiliaryKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCaption($val) {
|
public function setCaption($val) {
|
||||||
|
@ -235,6 +235,10 @@ abstract class ManiphestAuxiliaryFieldSpecification
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function shouldUseStorage() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Legacy Migration Support )------------------------------------------- */
|
/* -( Legacy Migration Support )------------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -209,11 +209,6 @@ abstract class ConduitAPI_maniphest_Method extends ConduitAPIMethod {
|
||||||
|
|
||||||
$task_phids = mpull($tasks, 'getPHID');
|
$task_phids = mpull($tasks, 'getPHID');
|
||||||
|
|
||||||
$all_aux = id(new ManiphestTaskAuxiliaryStorage())->loadAllWhere(
|
|
||||||
'taskPHID in (%Ls)',
|
|
||||||
$task_phids);
|
|
||||||
$all_aux = mgroup($all_aux, 'getTaskPHID');
|
|
||||||
|
|
||||||
$all_deps = id(new PhabricatorEdgeQuery())
|
$all_deps = id(new PhabricatorEdgeQuery())
|
||||||
->withSourcePHIDs($task_phids)
|
->withSourcePHIDs($task_phids)
|
||||||
->withEdgeTypes(array(PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK));
|
->withEdgeTypes(array(PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK));
|
||||||
|
@ -221,8 +216,8 @@ abstract class ConduitAPI_maniphest_Method extends ConduitAPIMethod {
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach ($tasks as $task) {
|
foreach ($tasks as $task) {
|
||||||
$auxiliary = idx($all_aux, $task->getPHID(), array());
|
// TODO: Batch this get as CustomField gets cleaned up.
|
||||||
$auxiliary = mpull($auxiliary, 'getValue', 'getName');
|
$auxiliary = $task->loadLegacyAuxiliaryFieldMap();
|
||||||
|
|
||||||
$task_deps = $all_deps->getDestinationPHIDs(
|
$task_deps = $all_deps->getDestinationPHIDs(
|
||||||
array($task->getPHID()),
|
array($task->getPHID()),
|
||||||
|
|
|
@ -137,17 +137,27 @@ final class ManiphestTask extends ManiphestDAO
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loadLegacyAuxiliaryFieldMap() {
|
||||||
|
$field_list = PhabricatorCustomField::getObjectFields(
|
||||||
|
$this,
|
||||||
|
PhabricatorCustomField::ROLE_EDIT);
|
||||||
|
$field_list->readFieldsFromStorage($this);
|
||||||
|
|
||||||
|
$map = array();
|
||||||
|
foreach ($field_list->getFields() as $field) {
|
||||||
|
$map[$field->getFieldKey()] = $field->getValueForStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $map;
|
||||||
|
}
|
||||||
|
|
||||||
public function loadAndAttachAuxiliaryAttributes() {
|
public function loadAndAttachAuxiliaryAttributes() {
|
||||||
if (!$this->getPHID()) {
|
if (!$this->getPHID()) {
|
||||||
$this->auxiliaryAttributes = array();
|
$this->auxiliaryAttributes = array();
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
$storage = id(new ManiphestTaskAuxiliaryStorage())->loadAllWhere(
|
$this->auxiliaryAttributes = $this->loadLegacyAuxiliaryFieldMap();
|
||||||
'taskPHID = %s',
|
|
||||||
$this->getPHID());
|
|
||||||
|
|
||||||
$this->auxiliaryAttributes = mpull($storage, 'getValue', 'getName');
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -182,24 +192,26 @@ final class ManiphestTask extends ManiphestDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
private function writeAuxiliaryUpdates() {
|
private function writeAuxiliaryUpdates() {
|
||||||
$table = new ManiphestTaskAuxiliaryStorage();
|
$table = new ManiphestCustomFieldStorage();
|
||||||
$conn_w = $table->establishConnection('w');
|
$conn_w = $table->establishConnection('w');
|
||||||
$update = array();
|
$update = array();
|
||||||
$remove = array();
|
$remove = array();
|
||||||
|
|
||||||
foreach ($this->auxiliaryDirty as $key => $dirty) {
|
foreach ($this->auxiliaryDirty as $key => $dirty) {
|
||||||
$value = $this->getAuxiliaryAttribute($key);
|
$value = $this->getAuxiliaryAttribute($key);
|
||||||
|
|
||||||
|
$index = PhabricatorHash::digestForIndex($key);
|
||||||
if ($value === null) {
|
if ($value === null) {
|
||||||
$remove[$key] = true;
|
$remove[$index] = true;
|
||||||
} else {
|
} else {
|
||||||
$update[$key] = $value;
|
$update[$index] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($remove) {
|
if ($remove) {
|
||||||
queryfx(
|
queryfx(
|
||||||
$conn_w,
|
$conn_w,
|
||||||
'DELETE FROM %T WHERE taskPHID = %s AND name IN (%Ls)',
|
'DELETE FROM %T WHERE objectPHID = %s AND fieldIndex IN (%Ls)',
|
||||||
$table->getTableName(),
|
$table->getTableName(),
|
||||||
$this->getPHID(),
|
$this->getPHID(),
|
||||||
array_keys($remove));
|
array_keys($remove));
|
||||||
|
@ -207,21 +219,19 @@ final class ManiphestTask extends ManiphestDAO
|
||||||
|
|
||||||
if ($update) {
|
if ($update) {
|
||||||
$sql = array();
|
$sql = array();
|
||||||
foreach ($update as $key => $val) {
|
foreach ($update as $index => $val) {
|
||||||
$sql[] = qsprintf(
|
$sql[] = qsprintf(
|
||||||
$conn_w,
|
$conn_w,
|
||||||
'(%s, %s, %s, %d, %d)',
|
'(%s, %s, %s)',
|
||||||
$this->getPHID(),
|
$this->getPHID(),
|
||||||
$key,
|
$index,
|
||||||
$val,
|
$val);
|
||||||
time(),
|
|
||||||
time());
|
|
||||||
}
|
}
|
||||||
queryfx(
|
queryfx(
|
||||||
$conn_w,
|
$conn_w,
|
||||||
'INSERT INTO %T (taskPHID, name, value, dateCreated, dateModified)
|
'INSERT INTO %T (objectPHID, fieldIndex, fieldValue)
|
||||||
VALUES %Q ON DUPLICATE KEY
|
VALUES %Q ON DUPLICATE KEY
|
||||||
UPDATE value = VALUES(value), dateModified = VALUES(dateModified)',
|
UPDATE fieldValue = VALUES(fieldValue)',
|
||||||
$table->getTableName(),
|
$table->getTableName(),
|
||||||
implode(', ', $sql));
|
implode(', ', $sql));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group maniphest
|
|
||||||
*/
|
|
||||||
final class ManiphestTaskAuxiliaryStorage extends ManiphestDAO {
|
|
||||||
|
|
||||||
protected $taskPHID;
|
|
||||||
protected $name;
|
|
||||||
protected $value;
|
|
||||||
|
|
||||||
}
|
|
|
@ -518,7 +518,12 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
||||||
break;
|
break;
|
||||||
case ManiphestTransactionType::TYPE_AUXILIARY:
|
case ManiphestTransactionType::TYPE_AUXILIARY:
|
||||||
$aux_key = $transaction->getMetadataValue('aux:key');
|
$aux_key = $transaction->getMetadataValue('aux:key');
|
||||||
|
|
||||||
|
// TODO: Migrate all legacy data when everything migrates for T2217.
|
||||||
$aux_field = $this->getAuxiliaryField($aux_key);
|
$aux_field = $this->getAuxiliaryField($aux_key);
|
||||||
|
if (!$aux_field) {
|
||||||
|
$aux_field = $this->getAuxiliaryField('std:maniphest:'.$aux_key);
|
||||||
|
}
|
||||||
|
|
||||||
$verb = null;
|
$verb = null;
|
||||||
if ($aux_field) {
|
if ($aux_field) {
|
||||||
|
|
|
@ -1600,6 +1600,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
||||||
'type' => 'sql',
|
'type' => 'sql',
|
||||||
'name' => $this->getPatchPath('20130915.maniphestcustom.sql'),
|
'name' => $this->getPatchPath('20130915.maniphestcustom.sql'),
|
||||||
),
|
),
|
||||||
|
'20130915.maniphestmigrate.php' => array(
|
||||||
|
'type' => 'php',
|
||||||
|
'name' => $this->getPatchPath('20130915.maniphestmigrate.php'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue