Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / resources / sql / autopatches / 20180208.maniphest.02.populate.php
blob4b4e5495748ded198753bd200fed6295a7507844
1 <?php
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.
10 continue;
13 $status = $task->getStatus();
14 if (!ManiphestTaskStatus::isClosedStatus($status)) {
15 // Task isn't closed.
16 continue;
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())
27 ->setViewer($viewer)
28 ->withObjectPHIDs(array($task->getPHID()))
29 ->needHandles(false)
30 ->withTransactionTypes(
31 array(
32 $type_merge,
33 $type_status,
35 ->execute();
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)) {
47 continue;
50 if ($old && ManiphestTaskStatus::isClosedStatus($old)) {
51 continue;
55 queryfx(
56 $conn,
57 'UPDATE %T SET closedEpoch = %d, closerPHID = %ns
58 WHERE id = %d',
59 $table->getTableName(),
60 $xaction->getDateCreated(),
61 $xaction->getAuthorPHID(),
62 $task->getID());
64 break;