2014-11-08 00:34:44 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$table = new PhabricatorAuthSSHKey();
|
|
|
|
$conn_w = $table->establishConnection('w');
|
|
|
|
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Updating SSH public key indexes...')."\n";
|
2014-11-08 00:34:44 +01:00
|
|
|
|
|
|
|
$keys = new LiskMigrationIterator($table);
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
$id = $key->getID();
|
|
|
|
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Updating key %d...', $id)."\n";
|
2014-11-08 00:34:44 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
$hash = $key->toPublicKey()->getHash();
|
|
|
|
} catch (Exception $ex) {
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Key has bad format! Removing key.')."\n";
|
2014-11-08 00:34:44 +01:00
|
|
|
queryfx(
|
|
|
|
$conn_w,
|
|
|
|
'DELETE FROM %T WHERE id = %d',
|
|
|
|
$table->getTableName(),
|
|
|
|
$id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$collision = queryfx_all(
|
|
|
|
$conn_w,
|
|
|
|
'SELECT * FROM %T WHERE keyIndex = %s AND id < %d',
|
|
|
|
$table->getTableName(),
|
|
|
|
$hash,
|
|
|
|
$key->getID());
|
|
|
|
if ($collision) {
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Key is a duplicate! Removing key.')."\n";
|
2014-11-08 00:34:44 +01:00
|
|
|
queryfx(
|
|
|
|
$conn_w,
|
|
|
|
'DELETE FROM %T WHERE id = %d',
|
|
|
|
$table->getTableName(),
|
|
|
|
$id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
queryfx(
|
|
|
|
$conn_w,
|
|
|
|
'UPDATE %T SET keyIndex = %s WHERE id = %d',
|
|
|
|
$table->getTableName(),
|
|
|
|
$hash,
|
|
|
|
$key->getID());
|
|
|
|
}
|
|
|
|
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Done.')."\n";
|