@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3$pull_table = new ReleephRequest();
4$table_name = $pull_table->getTableName();
5$conn_w = $pull_table->establishConnection('w');
6
7echo pht('Setting object PHIDs for requests...')."\n";
8foreach (new LiskMigrationIterator($pull_table) as $pull) {
9 $id = $pull->getID();
10
11 echo pht('Migrating pull request %d...', $id)."\n";
12 if ($pull->getRequestedObjectPHID()) {
13 // We already have a valid PHID, so skip this request.
14 continue;
15 }
16
17 $commit_phids = $pull->getCommitPHIDs();
18 if (count($commit_phids) != 1) {
19 // At the time this migration was written, all requests had exactly one
20 // commit. If a request has more than one, we don't have the information
21 // we need to process it.
22 continue;
23 }
24
25 $commit_phid = head($commit_phids);
26
27 $revision_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
28 $commit_phid,
29 DiffusionCommitHasRevisionEdgeType::EDGECONST);
30
31 if ($revision_phids) {
32 $object_phid = head($revision_phids);
33 } else {
34 $object_phid = $commit_phid;
35 }
36
37 queryfx(
38 $conn_w,
39 'UPDATE %T SET requestedObjectPHID = %s WHERE id = %d',
40 $table_name,
41 $object_phid,
42 $id);
43}
44
45echo pht('Done.')."\n";