3 $table = new PhabricatorRepositoryRefCursor();
4 $conn = $table->establishConnection('w');
7 foreach (new LiskMigrationIterator($table) as $ref) {
8 $repository_phid = $ref->getRepositoryPHID();
9 $ref_type = $ref->getRefType();
10 $ref_hash = $ref->getRefNameHash();
12 $ref_key = "{$repository_phid}/{$ref_type}/{$ref_hash}";
14 if (!isset($map[$ref_key])) {
15 $map[$ref_key] = array(
16 'id' => $ref->getID(),
19 'repositoryPHID' => $repository_phid,
20 'positions' => array(),
24 // NOTE: When this migration runs, the table will have "commitIdentifier" and
25 // "isClosed" fields. Later, it won't. Since they'll be removed, we can't
26 // rely on being able to access them via the object. Instead, run a separate
27 // raw query to read them.
31 'SELECT commitIdentifier, isClosed FROM %T WHERE id = %d',
35 $map[$ref_key]['positions'][] = array(
36 'identifier' => $row['commitIdentifier'],
37 'isClosed' => (int)$row['isClosed'],
41 // Now, write all the position rows.
42 $position_table = new PhabricatorRepositoryRefPosition();
43 foreach ($map as $ref_key => $spec) {
45 foreach ($spec['positions'] as $position) {
48 'INSERT IGNORE INTO %T (cursorID, commitIdentifier, isClosed)
50 $position_table->getTableName(),
52 $position['identifier'],
53 $position['isClosed']);
57 // Finally, delete all the redundant RefCursor rows (rows with the same name)
58 // so we can add proper unique keys in the next migration.
59 foreach ($map as $ref_key => $spec) {
62 'DELETE FROM %T WHERE refType = %s
64 AND repositoryPHID = %s
66 $table->getTableName(),
69 $spec['repositoryPHID'],