protected function loadPage()
 {
     $table = new PhabricatorAuthSSHKey();
     $conn_r = $table->establishConnection('r');
     $data = queryfx_all($conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r));
     return $table->loadAllFromArray($data);
 }
 private function buildPropertySection(PhabricatorAuthSSHKey $ssh_key)
 {
     $viewer = $this->getViewer();
     $properties = id(new PHUIPropertyListView())->setUser($viewer);
     $properties->addProperty(pht('SSH Key Type'), $ssh_key->getKeyType());
     $properties->addProperty(pht('Created'), phabricator_datetime($ssh_key->getDateCreated(), $viewer));
     return id(new PHUIObjectBoxView())->setHeaderText(pht('Details'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->appendChild($properties);
 }
 public static function newFromStoredKey(PhabricatorAuthSSHKey $key)
 {
     $public_key = new PhabricatorAuthSSHPublicKey();
     $public_key->type = $key->getKeyType();
     $public_key->body = $key->getKeyBody();
     $public_key->comment = $key->getKeyComment();
     return $public_key;
 }
 protected function newKeyForObjectPHID($object_phid)
 {
     $viewer = $this->getViewer();
     $object = $this->loadSSHKeyObject($object_phid, true);
     if (!$object) {
         return null;
     }
     return PhabricatorAuthSSHKey::initializeNewSSHKey($viewer, $object);
 }
<?php

$table = new PhabricatorAuthSSHKey();
$conn_w = $table->establishConnection('w');
echo pht('Updating SSH public key indexes...') . "\n";
$keys = new LiskMigrationIterator($table);
foreach ($keys as $key) {
    $id = $key->getID();
    echo pht('Updating key %d...', $id) . "\n";
    try {
        $hash = $key->toPublicKey()->getHash();
    } catch (Exception $ex) {
        echo pht('Key has bad format! Removing key.') . "\n";
        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) {
        echo pht('Key is a duplicate! Removing key.') . "\n";
        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());
}
echo pht('Done.') . "\n";
<?php

$table = new PhabricatorAuthSSHKey();
$conn_w = $table->establishConnection('w');
foreach (new LiskMigrationIterator($table) as $cursor) {
    if (strlen($cursor->getPHID())) {
        continue;
    }
    queryfx($conn_w, 'UPDATE %T SET phid = %s WHERE id = %d', $table->getTableName(), $table->generatePHID(), $cursor->getID());
}