1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00
phorge-phorge/resources/sql/autopatches/20180208.maniphest.02.populate.php
epriestley f028aa6f60 Track closed date and closing user for tasks explicitly
Summary:
Ref T4434. Although some of the use cases for this data are better fits for Facts, this data is reasonable to track separately.

I have an approximate view of it already ("closed, ordered by date modified") that's useful to review things that were fixed recently. This lets us make that view more effective.

This just adds (and populates) the storage. Followups will add Conduit, Export, Search, and UI support.

This is slightly tricky because merges work oddly (see T13020).

Test Plan:
  - Ran migration, checked database for sensible results.
  - Created a task in open/closed status, got the right database values.
  - Modified a task to close/open it, got the right values.
  - Merged an open task, got updates.

Maniphest Tasks: T4434

Differential Revision: https://secure.phabricator.com/D19037
2018-02-08 15:40:49 -08:00

65 lines
1.8 KiB
PHP

<?php
$table = new ManiphestTask();
$conn = $table->establishConnection('w');
$viewer = PhabricatorUser::getOmnipotentUser();
foreach (new LiskMigrationIterator($table) as $task) {
if ($task->getClosedEpoch()) {
// Task already has a closed date.
continue;
}
$status = $task->getStatus();
if (!ManiphestTaskStatus::isClosedStatus($status)) {
// Task isn't closed.
continue;
}
// Look through the transactions from newest to oldest until we find one
// where the task was closed. A merge also counts as a close, even though
// it doesn't currently produce a separate transaction.
$type_merge = ManiphestTaskStatusTransaction::TRANSACTIONTYPE;
$type_status = ManiphestTaskMergedIntoTransaction::TRANSACTIONTYPE;
$xactions = id(new ManiphestTransactionQuery())
->setViewer($viewer)
->withObjectPHIDs(array($task->getPHID()))
->withTransactionTypes(
array(
$type_merge,
$type_status,
))
->execute();
foreach ($xactions as $xaction) {
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
$type = $xaction->getTransactionType();
// If this is a status change, but is not a close, don't use it.
// (We always use merges, even though it's possible to merge a task which
// was previously closed: we can't tell when this happens very easily.)
if ($type === $type_status) {
if (!ManiphestTaskStatus::isClosedStatus($new)) {
continue;
}
if ($old && ManiphestTaskStatus::isClosedStatus($old)) {
continue;
}
}
queryfx(
$conn,
'UPDATE %T SET closedEpoch = %d, closerPHID = %ns
WHERE id = %d',
$table->getTableName(),
$xaction->getDateCreated(),
$xaction->getAuthorPHID(),
$task->getID());
break;
}
}