From 99e4472447529a9648f3e0c9dfe604051f204094 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 23 Sep 2015 19:18:44 -0700 Subject: [PATCH] Soften checks on a very old Maniphest transactionmigration Summary: Ref T9464. If an ancient transaction doesn't have array values for whatever reason, we fail here. Instead, just recover as gracefully as we can. We may get the transaction "wrong" in some sense, but this only impacts what is rendered in the transaction log. Test Plan: This is nearly a year old and there's no real way to test it. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9464 Differential Revision: https://secure.phabricator.com/D14149 --- .../autopatches/20141222.maniphestprojtxn.php | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/resources/sql/autopatches/20141222.maniphestprojtxn.php b/resources/sql/autopatches/20141222.maniphestprojtxn.php index ba7a8f2f1f..31aae8b986 100644 --- a/resources/sql/autopatches/20141222.maniphestprojtxn.php +++ b/resources/sql/autopatches/20141222.maniphestprojtxn.php @@ -9,41 +9,53 @@ $metadata = array( 'edge:type' => PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, ); foreach (new LiskMigrationIterator($table) as $txn) { - // ManiphestTransaction::TYPE_PROJECTS - if ($txn->getTransactionType() == 'projects') { - $old_value = mig20141222_build_edge_data( - $txn->getOldValue(), - $txn->getObjectPHID()); - $new_value = mig20141222_build_edge_data( - $txn->getNewvalue(), - $txn->getObjectPHID()); - queryfx( - $conn_w, - 'UPDATE %T SET '. - 'transactionType = %s, oldValue = %s, newValue = %s, metaData = %s '. - 'WHERE id = %d', - $table->getTableName(), - PhabricatorTransactions::TYPE_EDGE, - json_encode($old_value), - json_encode($new_value), - json_encode($metadata), - $txn->getID()); + if ($txn->getTransactionType() != 'projects') { + continue; } + + $old_value = mig20141222_build_edge_data( + $txn->getOldValue(), + $txn->getObjectPHID()); + + $new_value = mig20141222_build_edge_data( + $txn->getNewValue(), + $txn->getObjectPHID()); + + queryfx( + $conn_w, + 'UPDATE %T SET '. + 'transactionType = %s, oldValue = %s, newValue = %s, metaData = %s '. + 'WHERE id = %d', + $table->getTableName(), + PhabricatorTransactions::TYPE_EDGE, + json_encode($old_value), + json_encode($new_value), + json_encode($metadata), + $txn->getID()); } echo pht('Done.')."\n"; -function mig20141222_build_edge_data(array $project_phids, $task_phid) { +function mig20141222_build_edge_data($project_phids, $task_phid) { $edge_data = array(); + + // See T9464. If we didn't get a proper array value out of the transaction, + // just return an empty value so we can move forward. + if (!is_array($project_phids)) { + return $edge_data; + } + foreach ($project_phids as $project_phid) { if (!is_scalar($project_phid)) { continue; } + $edge_data[$project_phid] = array( 'src' => $task_phid, 'type' => PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, 'dst' => $project_phid, ); } + return $edge_data; } -- 2.51.2