I had deleted a user account in Phabricator but had not removed all references to the user beforehand (in this particular case, I //did// want to delete the user as oposed to disabling the account).
Whilst trying to fix stale references to the deleted user, I accidentally modified the `ccPHIDs` field for all rows in the `maniphest_task` table. I figured that I could essentially rebuild the `ccPHIDs` field by replaying the relevant Maniphest transactions. To do this, I used the following script:
```
#!/usr/bin/env php
<?php
require_once(__DIR__ . '/scripts/__init_script__.php');
$task_table = new ManiphestTask();
$conn_w = $task_table->establishConnection('w');
$rows = queryfx_all(
$conn_w,
'SELECT * FROM maniphest_transaction WHERE transactionType = %s ORDER BY dateCreated ASC',
'ccs'
);
$conn_w->openTransaction();
foreach ($rows as $row) {
$row_id = $row['id'];
$task_id = $row['taskID'];
echo "Replaying transaction {$row_id} (T{$task_id})...\n";
queryfx(
$conn_w,
'UPDATE %T SET ccPHIDs = %s WHERE id = %d',
$task_table->getTableName(),
$row['newValue'],
$task_id
);
}
$conn_w->saveTransaction();
echo "Done.\n";
```
I just wanted to ask if there was a more general way to recover data by replaying transaction logs? And also ask if there are any gotchas that I have missed in my recovery script.