3 $table = new ManiphestTask();
4 $conn = $table->establishConnection('w');
5 $viewer = PhabricatorUser
::getOmnipotentUser();
7 foreach (new LiskMigrationIterator($table) as $task) {
8 if ($task->getClosedEpoch()) {
9 // Task already has a closed date.
13 $status = $task->getStatus();
14 if (!ManiphestTaskStatus
::isClosedStatus($status)) {
19 // Look through the transactions from newest to oldest until we find one
20 // where the task was closed. A merge also counts as a close, even though
21 // it doesn't currently produce a separate transaction.
23 $type_status = ManiphestTaskStatusTransaction
::TRANSACTIONTYPE
;
24 $type_merge = ManiphestTaskMergedIntoTransaction
::TRANSACTIONTYPE
;
26 $xactions = id(new ManiphestTransactionQuery())
28 ->withObjectPHIDs(array($task->getPHID()))
30 ->withTransactionTypes(
36 foreach ($xactions as $xaction) {
37 $old = $xaction->getOldValue();
38 $new = $xaction->getNewValue();
40 $type = $xaction->getTransactionType();
42 // If this is a status change, but is not a close, don't use it.
43 // (We always use merges, even though it's possible to merge a task which
44 // was previously closed: we can't tell when this happens very easily.)
45 if ($type === $type_status) {
46 if (!ManiphestTaskStatus
::isClosedStatus($new)) {
50 if ($old && ManiphestTaskStatus
::isClosedStatus($old)) {
57 'UPDATE %T SET closedEpoch = %d, closerPHID = %ns
59 $table->getTableName(),
60 $xaction->getDateCreated(),
61 $xaction->getAuthorPHID(),