Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F438352
20170915.ref.01.migrate.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
20170915.ref.01.migrate.php
View Options
<?php
$table
=
new
PhabricatorRepositoryRefCursor
();
$conn
=
$table
->
establishConnection
(
'w'
);
$map
=
array
();
foreach
(
new
LiskMigrationIterator
(
$table
)
as
$ref
)
{
$repository_phid
=
$ref
->
getRepositoryPHID
();
$ref_type
=
$ref
->
getRefType
();
$ref_hash
=
$ref
->
getRefNameHash
();
$ref_key
=
"{$repository_phid}/{$ref_type}/{$ref_hash}"
;
if
(!
isset
(
$map
[
$ref_key
]))
{
$map
[
$ref_key
]
=
array
(
'id'
=>
$ref
->
getID
(),
'type'
=>
$ref_type
,
'hash'
=>
$ref_hash
,
'repositoryPHID'
=>
$repository_phid
,
'positions'
=>
array
(),
);
}
// NOTE: When this migration runs, the table will have "commitIdentifier" and
// "isClosed" fields. Later, it won't. Since they'll be removed, we can't
// rely on being able to access them via the object. Instead, run a separate
// raw query to read them.
$row
=
queryfx_one
(
$conn
,
'SELECT commitIdentifier, isClosed FROM %T WHERE id = %d'
,
$ref
->
getTableName
(),
$ref
->
getID
());
$map
[
$ref_key
][
'positions'
][]
=
array
(
'identifier'
=>
$row
[
'commitIdentifier'
],
'isClosed'
=>
(
int
)
$row
[
'isClosed'
],
);
}
// Now, write all the position rows.
$position_table
=
new
PhabricatorRepositoryRefPosition
();
foreach
(
$map
as
$ref_key
=>
$spec
)
{
$id
=
$spec
[
'id'
];
foreach
(
$spec
[
'positions'
]
as
$position
)
{
queryfx
(
$conn
,
'INSERT IGNORE INTO %T (cursorID, commitIdentifier, isClosed)
VALUES (%d, %s, %d)'
,
$position_table
->
getTableName
(),
$id
,
$position
[
'identifier'
],
$position
[
'isClosed'
]);
}
}
// Finally, delete all the redundant RefCursor rows (rows with the same name)
// so we can add proper unique keys in the next migration.
foreach
(
$map
as
$ref_key
=>
$spec
)
{
queryfx
(
$conn
,
'DELETE FROM %T WHERE refType = %s
AND refNameHash = %s
AND repositoryPHID = %s
AND id != %d'
,
$table
->
getTableName
(),
$spec
[
'type'
],
$spec
[
'hash'
],
$spec
[
'repositoryPHID'
],
$spec
[
'id'
]);
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, May 4, 2:23 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
63042
Default Alt Text
20170915.ref.01.migrate.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment