@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// Populate the "maxVersion" column by copying the maximum "version" from the
4// content table.
5
6$document_table = new PhrictionDocument();
7$content_table = new PhrictionContent();
8
9$conn = $document_table->establishConnection('w');
10
11$iterator = new LiskRawMigrationIterator(
12 $conn,
13 $document_table->getTableName());
14foreach ($iterator as $row) {
15 $content = queryfx_one(
16 $conn,
17 'SELECT MAX(version) max FROM %T WHERE documentPHID = %s',
18 $content_table->getTableName(),
19 $row['phid']);
20 if (!$content) {
21 continue;
22 }
23
24 queryfx(
25 $conn,
26 'UPDATE %T SET maxVersion = %d WHERE id = %d',
27 $document_table->getTableName(),
28 $content['max'],
29 $row['id']);
30}