Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / resources / sql / autopatches / 20210215.changeset.02.phid-populate.php
blob93f886c7b04332355859408ddb03397ccfd8fb0b
1 <?php
3 $phid_type = DifferentialChangesetPHIDType::TYPECONST;
5 $changeset_table = new DifferentialChangeset();
7 $conn = $changeset_table->establishConnection('w');
8 $table_name = $changeset_table->getTableName();
10 $chunk_size = 4096;
12 $temporary_table = 'tmp_20210215_changeset_id_map';
14 try {
15 queryfx(
16 $conn,
17 'CREATE TEMPORARY TABLE %T (
18 changeset_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
19 changeset_phid VARBINARY(64) NOT NULL)',
20 $temporary_table);
21 } catch (AphrontAccessDeniedQueryException $ex) {
22 throw new PhutilProxyException(
23 pht(
24 'Failed to "CREATE TEMPORARY TABLE". You may need to "GRANT" the '.
25 'current MySQL user this permission.'),
26 $ex);
29 $table_iterator = id(new LiskRawMigrationIterator($conn, $table_name))
30 ->setPageSize($chunk_size);
32 $chunk_iterator = new PhutilChunkedIterator($table_iterator, $chunk_size);
33 foreach ($chunk_iterator as $chunk) {
35 $map = array();
36 foreach ($chunk as $changeset_row) {
37 $phid = $changeset_row['phid'];
39 if (strlen($phid)) {
40 continue;
43 $phid = PhabricatorPHID::generateNewPHID($phid_type);
44 $id = $changeset_row['id'];
46 $map[(int)$id] = $phid;
49 if (!$map) {
50 continue;
53 $sql = array();
54 foreach ($map as $changeset_id => $changeset_phid) {
55 $sql[] = qsprintf(
56 $conn,
57 '(%d, %s)',
58 $changeset_id,
59 $changeset_phid);
62 queryfx(
63 $conn,
64 'TRUNCATE TABLE %T',
65 $temporary_table);
67 queryfx(
68 $conn,
69 'INSERT INTO %T (changeset_id, changeset_phid) VALUES %LQ',
70 $temporary_table,
71 $sql);
73 queryfx(
74 $conn,
75 'UPDATE %T c JOIN %T x ON c.id = x.changeset_id
76 SET c.phid = x.changeset_phid',
77 $table_name,
78 $temporary_table);