1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-29 17:00:59 +01:00
phorge-phorge/resources/sql/autopatches/20181219.pholio.02.imagemigrate.php
epriestley 21f07bf6f7 Make Images in Pholio refer to mocks by PHID instead of ID
Summary:
Ref T11351. In Pholio, we currently use a `mockID`, but a `mockPHID` is generally preferable / more modern / more flexible. In particular, we need PHIDs to load handles and prefer PHIDs when exposing information to the API, and using PHIDs internally makes a bunch of things easier/better/faster and ~nothing harder/worse/slower.

I'll add some inlines about a few things.

Test Plan: Ran migrations, spot-checked database for sanity. Loaded Pholio, saw data unchanged. Created and edited images.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T11351

Differential Revision: https://secure.phabricator.com/D19914
2018-12-20 14:54:25 -08:00

35 lines
728 B
PHP

<?php
// Old images used a "mockID" instead of a "mockPHID" to reference mocks.
// Set the "mockPHID" column to the value that corresponds to the "mockID".
$image = new PholioImage();
$mock = new PholioMock();
$conn = $image->establishConnection('w');
$iterator = new LiskRawMigrationIterator($conn, $image->getTableName());
foreach ($iterator as $image_row) {
if ($image_row['mockPHID']) {
continue;
}
$mock_id = $image_row['mockID'];
$mock_row = queryfx_one(
$conn,
'SELECT phid FROM %R WHERE id = %d',
$mock,
$mock_id);
if (!$mock_row) {
continue;
}
queryfx(
$conn,
'UPDATE %R SET mockPHID = %s WHERE id = %d',
$image,
$mock_row['phid'],
$image_row['id']);
}