2021-02-15 19:04:47 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$phid_type = DifferentialChangesetPHIDType::TYPECONST;
|
|
|
|
|
|
|
|
$changeset_table = new DifferentialChangeset();
|
|
|
|
|
|
|
|
$conn = $changeset_table->establishConnection('w');
|
|
|
|
$table_name = $changeset_table->getTableName();
|
|
|
|
|
2021-02-19 16:44:28 +01:00
|
|
|
$chunk_size = 4096;
|
2021-02-15 19:04:47 +01:00
|
|
|
|
2021-02-19 16:44:28 +01:00
|
|
|
$temporary_table = 'tmp_20210215_changeset_id_map';
|
|
|
|
|
|
|
|
queryfx(
|
|
|
|
$conn,
|
|
|
|
'CREATE TEMPORARY TABLE %T (
|
|
|
|
changeset_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
changeset_phid VARBINARY(64) NOT NULL)',
|
|
|
|
$temporary_table);
|
|
|
|
|
|
|
|
$table_iterator = id(new LiskRawMigrationIterator($conn, $table_name))
|
|
|
|
->setPageSize($chunk_size);
|
|
|
|
|
|
|
|
$chunk_iterator = new PhutilChunkedIterator($table_iterator, $chunk_size);
|
|
|
|
foreach ($chunk_iterator as $chunk) {
|
|
|
|
|
|
|
|
$map = array();
|
|
|
|
foreach ($chunk as $changeset_row) {
|
|
|
|
$phid = $changeset_row['phid'];
|
|
|
|
|
|
|
|
if (strlen($phid)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$phid = PhabricatorPHID::generateNewPHID($phid_type);
|
|
|
|
$id = $changeset_row['id'];
|
|
|
|
|
|
|
|
$map[(int)$id] = $phid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$map) {
|
2021-02-15 19:04:47 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-02-19 16:44:28 +01:00
|
|
|
$sql = array();
|
|
|
|
foreach ($map as $changeset_id => $changeset_phid) {
|
|
|
|
$sql[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'(%d, %s)',
|
|
|
|
$changeset_id,
|
|
|
|
$changeset_phid);
|
|
|
|
}
|
|
|
|
|
|
|
|
queryfx(
|
|
|
|
$conn,
|
|
|
|
'TRUNCATE TABLE %T',
|
|
|
|
$temporary_table);
|
|
|
|
|
|
|
|
queryfx(
|
|
|
|
$conn,
|
|
|
|
'INSERT INTO %T (changeset_id, changeset_phid) VALUES %LQ',
|
|
|
|
$temporary_table,
|
|
|
|
$sql);
|
2021-02-15 19:04:47 +01:00
|
|
|
|
|
|
|
queryfx(
|
|
|
|
$conn,
|
2021-02-19 16:44:28 +01:00
|
|
|
'UPDATE %T c JOIN %T x ON c.id = x.changeset_id
|
|
|
|
SET c.phid = x.changeset_phid',
|
2021-02-15 19:04:47 +01:00
|
|
|
$table_name,
|
2021-02-19 16:44:28 +01:00
|
|
|
$temporary_table);
|
2021-02-15 19:04:47 +01:00
|
|
|
}
|