mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-17 20:32:41 +01:00
Add proper PHIDs to RefCursors
Summary: Ref T9952. See discussion there. This change is primarily aimed at letting me build a typeahead of branches in a repository so that we can land to arbitrary branches a few diffs from now. Test Plan: - Ran migrations. - Verified database populated properly with PHIDs (`SELECT * FROM repository_refcursor;`). - Ran `bin/repository update`. - Viewed a Git repository in Diffusion. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9952 Differential Revision: https://secure.phabricator.com/D14731
This commit is contained in:
parent
6985643f58
commit
2a203fbab1
6 changed files with 109 additions and 24 deletions
2
resources/sql/autopatches/20151210.land.1.refphid.sql
Normal file
2
resources/sql/autopatches/20151210.land.1.refphid.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_repository.repository_refcursor
|
||||
ADD phid VARBINARY(64) NOT NULL AFTER id;
|
17
resources/sql/autopatches/20151210.land.2.refphid.php
Normal file
17
resources/sql/autopatches/20151210.land.2.refphid.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
$table = new PhabricatorRepositoryRefCursor();
|
||||
$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());
|
||||
}
|
|
@ -2907,6 +2907,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositoryPushReplyHandler' => 'applications/repository/mail/PhabricatorRepositoryPushReplyHandler.php',
|
||||
'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php',
|
||||
'PhabricatorRepositoryRefCursor' => 'applications/repository/storage/PhabricatorRepositoryRefCursor.php',
|
||||
'PhabricatorRepositoryRefCursorPHIDType' => 'applications/repository/phid/PhabricatorRepositoryRefCursorPHIDType.php',
|
||||
'PhabricatorRepositoryRefCursorQuery' => 'applications/repository/query/PhabricatorRepositoryRefCursorQuery.php',
|
||||
'PhabricatorRepositoryRefEngine' => 'applications/repository/engine/PhabricatorRepositoryRefEngine.php',
|
||||
'PhabricatorRepositoryRepositoryPHIDType' => 'applications/repository/phid/PhabricatorRepositoryRepositoryPHIDType.php',
|
||||
|
@ -7199,6 +7200,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositoryDAO',
|
||||
'PhabricatorPolicyInterface',
|
||||
),
|
||||
'PhabricatorRepositoryRefCursorPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhabricatorRepositoryRefCursorQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorRepositoryRefEngine' => 'PhabricatorRepositoryEngine',
|
||||
'PhabricatorRepositoryRepositoryPHIDType' => 'PhabricatorPHIDType',
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorRepositoryRefCursorPHIDType
|
||||
extends PhabricatorPHIDType {
|
||||
|
||||
const TYPECONST = 'RREF';
|
||||
|
||||
public function getTypeName() {
|
||||
return pht('Repository Ref');
|
||||
}
|
||||
|
||||
public function newObject() {
|
||||
return new PhabricatorRepositoryRefCursor();
|
||||
}
|
||||
|
||||
public function getPHIDTypeApplicationClass() {
|
||||
return 'PhabricatorDiffusionApplication';
|
||||
}
|
||||
|
||||
protected function buildQueryForObjects(
|
||||
PhabricatorObjectQuery $query,
|
||||
array $phids) {
|
||||
|
||||
return id(new PhabricatorRepositoryRefCursorQuery())
|
||||
->withPHIDs($phids);
|
||||
}
|
||||
|
||||
public function loadHandles(
|
||||
PhabricatorHandleQuery $query,
|
||||
array $handles,
|
||||
array $objects) {
|
||||
|
||||
foreach ($handles as $phid => $handle) {
|
||||
$ref = $objects[$phid];
|
||||
|
||||
$name = $ref->getRefName();
|
||||
|
||||
$handle->setName($name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -3,10 +3,22 @@
|
|||
final class PhabricatorRepositoryRefCursorQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
private $ids;
|
||||
private $phids;
|
||||
private $repositoryPHIDs;
|
||||
private $refTypes;
|
||||
private $refNames;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withPHIDs(array $phids) {
|
||||
$this->phids = $phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withRepositoryPHIDs(array $phids) {
|
||||
$this->repositoryPHIDs = $phids;
|
||||
return $this;
|
||||
|
@ -22,19 +34,12 @@ final class PhabricatorRepositoryRefCursorQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function newResultObject() {
|
||||
return new PhabricatorRepositoryRefCursor();
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$table = new PhabricatorRepositoryRefCursor();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T r %Q %Q %Q',
|
||||
$table->getTableName(),
|
||||
$this->buildWhereClause($conn_r),
|
||||
$this->buildOrderClause($conn_r),
|
||||
$this->buildLimitClause($conn_r));
|
||||
|
||||
return $table->loadAllFromArray($data);
|
||||
return $this->loadStandardPage($this->newResultObject());
|
||||
}
|
||||
|
||||
protected function willFilterPage(array $refs) {
|
||||
|
@ -50,6 +55,7 @@ final class PhabricatorRepositoryRefCursorQuery
|
|||
foreach ($refs as $key => $ref) {
|
||||
$repository = idx($repositories, $ref->getRepositoryPHID());
|
||||
if (!$repository) {
|
||||
$this->didRejectResult($ref);
|
||||
unset($refs[$key]);
|
||||
continue;
|
||||
}
|
||||
|
@ -59,19 +65,33 @@ final class PhabricatorRepositoryRefCursorQuery
|
|||
return $refs;
|
||||
}
|
||||
|
||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||
$where = parent::buildWhereClauseParts($conn);
|
||||
|
||||
if ($this->ids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->repositoryPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'repositoryPHID IN (%Ls)',
|
||||
$this->repositoryPHIDs);
|
||||
}
|
||||
|
||||
if ($this->refTypes !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'refType IN (%Ls)',
|
||||
$this->refTypes);
|
||||
}
|
||||
|
@ -83,14 +103,12 @@ final class PhabricatorRepositoryRefCursorQuery
|
|||
}
|
||||
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'refNameHash IN (%Ls)',
|
||||
$name_hashes);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
return $where;
|
||||
}
|
||||
|
||||
public function getQueryApplicationClass() {
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* out how a repository has changed when we discover new commits or branch
|
||||
* heads.
|
||||
*/
|
||||
final class PhabricatorRepositoryRefCursor extends PhabricatorRepositoryDAO
|
||||
final class PhabricatorRepositoryRefCursor
|
||||
extends PhabricatorRepositoryDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
|
||||
const TYPE_BRANCH = 'branch';
|
||||
|
@ -25,6 +26,7 @@ final class PhabricatorRepositoryRefCursor extends PhabricatorRepositoryDAO
|
|||
protected function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_TIMESTAMPS => false,
|
||||
self::CONFIG_AUX_PHID => true,
|
||||
self::CONFIG_BINARY => array(
|
||||
'refNameRaw' => true,
|
||||
),
|
||||
|
@ -32,9 +34,6 @@ final class PhabricatorRepositoryRefCursor extends PhabricatorRepositoryDAO
|
|||
'refType' => 'text32',
|
||||
'refNameHash' => 'bytes12',
|
||||
'commitIdentifier' => 'text40',
|
||||
|
||||
// T6203/NULLABILITY
|
||||
// This probably should not be nullable; refNameRaw is not nullable.
|
||||
'refNameEncoding' => 'text16?',
|
||||
'isClosed' => 'bool',
|
||||
),
|
||||
|
@ -46,6 +45,11 @@ final class PhabricatorRepositoryRefCursor extends PhabricatorRepositoryDAO
|
|||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
public function generatePHID() {
|
||||
return PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorRepositoryRefCursorPHIDType::TYPECONST);
|
||||
}
|
||||
|
||||
public function getRefName() {
|
||||
return $this->getUTF8StringFromStorage(
|
||||
$this->getRefNameRaw(),
|
||||
|
|
Loading…
Reference in a new issue