1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

Remove several "loadArcanistProject()" methods

Summary:
Ref T3551. Releeph has old-style `loadX()` methods; get rid of one of them.

Differential has a couple of copies of this too, clean them up.

Test Plan:
  - Viewed various differential revisions (with and without projects).
  - Viewed and edited Releeph products.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T3551

Differential Revision: https://secure.phabricator.com/D8768
This commit is contained in:
epriestley 2014-04-14 12:07:32 -07:00
parent 05e30a024d
commit f4c8a34abe
7 changed files with 57 additions and 31 deletions

View file

@ -33,6 +33,7 @@ final class DifferentialRevisionViewController extends DifferentialController {
$diffs = id(new DifferentialDiffQuery()) $diffs = id(new DifferentialDiffQuery())
->setViewer($request->getUser()) ->setViewer($request->getUser())
->withRevisionIDs(array($this->revisionID)) ->withRevisionIDs(array($this->revisionID))
->needArcanistProjects(true)
->execute(); ->execute();
$diffs = array_reverse($diffs, $preserve_keys = true); $diffs = array_reverse($diffs, $preserve_keys = true);
@ -61,8 +62,18 @@ final class DifferentialRevisionViewController extends DifferentialController {
$diff_vs = null; $diff_vs = null;
} }
$arc_project = $target->loadArcanistProject(); $repository = null;
$repository = ($arc_project ? $arc_project->loadRepository() : null); $repository_phid = $target->getRepositoryPHID();
if ($repository_phid) {
if ($repository_phid == $revision->getRepositoryPHID()) {
$repository = $revision->getRepository();
} else {
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($user)
->withPHIDs(array($repository_phid))
->executeOne();
}
}
list($changesets, $vs_map, $vs_changesets, $rendering_references) = list($changesets, $vs_map, $vs_changesets, $rendering_references) =
$this->loadChangesetsAndVsMap( $this->loadChangesetsAndVsMap(
@ -219,6 +230,7 @@ final class DifferentialRevisionViewController extends DifferentialController {
'whitespace', 'whitespace',
DifferentialChangesetParser::WHITESPACE_IGNORE_ALL); DifferentialChangesetParser::WHITESPACE_IGNORE_ALL);
$arc_project = $target->getArcanistProject();
if ($arc_project) { if ($arc_project) {
list($symbol_indexes, $project_phids) = $this->buildSymbolIndexes( list($symbol_indexes, $project_phids) = $this->buildSymbolIndexes(
$arc_project, $arc_project,

View file

@ -95,27 +95,6 @@ final class DifferentialDiff
return $name; return $name;
} }
public function loadArcanistProject() {
if (!$this->getArcanistProjectPHID()) {
return null;
}
return id(new PhabricatorRepositoryArcanistProject())->loadOneWhere(
'phid = %s',
$this->getArcanistProjectPHID());
}
public function getBackingVersionControlSystem() {
$arcanist_project = $this->loadArcanistProject();
if (!$arcanist_project) {
return null;
}
$repository = $arcanist_project->loadRepository();
if (!$repository) {
return null;
}
return $repository->getVersionControlSystem();
}
public function save() { public function save() {
$this->openTransaction(); $this->openTransaction();
$ret = parent::save(); $ret = parent::save();

View file

@ -15,6 +15,7 @@ final class ReleephProductEditController extends ReleephProductController {
$product = id(new ReleephProjectQuery()) $product = id(new ReleephProjectQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($this->productID)) ->withIDs(array($this->productID))
->needArcanistProjects(true)
->requireCapabilities( ->requireCapabilities(
array( array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
@ -145,7 +146,7 @@ final class ReleephProductEditController extends ReleephProductController {
id(new AphrontFormStaticControl()) id(new AphrontFormStaticControl())
->setLabel(pht('Arc Project')) ->setLabel(pht('Arc Project'))
->setValue( ->setValue(
$product->loadArcanistProject()->getName())) $product->getArcanistProject()->getName()))
->appendChild( ->appendChild(
id(new AphrontFormStaticControl()) id(new AphrontFormStaticControl())
->setLabel(pht('Releeph Project PHID')) ->setLabel(pht('Releeph Project PHID'))

View file

@ -53,7 +53,7 @@ final class ReleephProductListController extends ReleephController
), ),
'r'.$repo->getCallsign())); 'r'.$repo->getCallsign()));
$arc = $product->loadArcanistProject(); $arc = $product->getArcanistProject();
if ($arc) { if ($arc) {
$item->addAttribute($arc->getName()); $item->addAttribute($arc->getName());
} }

View file

@ -13,7 +13,8 @@ final class ReleephProductSearchEngine
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new ReleephProjectQuery()) $query = id(new ReleephProjectQuery())
->setOrder(ReleephProjectQuery::ORDER_NAME); ->setOrder(ReleephProjectQuery::ORDER_NAME)
->needArcanistProjects(true);
$active = $saved->getParameter('active'); $active = $saved->getParameter('active');
$value = idx($this->getActiveValues(), $active); $value = idx($this->getActiveValues(), $active);

View file

@ -8,6 +8,7 @@ final class ReleephProjectQuery
private $phids; private $phids;
private $needRepositories; private $needRepositories;
private $needArcanistProjects;
private $order = 'order-id'; private $order = 'order-id';
const ORDER_ID = 'order-id'; const ORDER_ID = 'order-id';
@ -33,6 +34,11 @@ final class ReleephProjectQuery
return $this; return $this;
} }
public function needArcanistProjects($need) {
$this->needArcanistProjects = $need;
return $this;
}
public function loadPage() { public function loadPage() {
$table = new ReleephProject(); $table = new ReleephProject();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');
@ -71,6 +77,29 @@ final class ReleephProjectQuery
return $projects; return $projects;
} }
public function didFilterPage(array $products) {
if ($this->needArcanistProjects) {
$project_ids = array_filter(mpull($products, 'getArcanistProjectID'));
if ($project_ids) {
$projects = id(new PhabricatorRepositoryArcanistProject())
->loadAllWhere('id IN (%Ld)', $project_ids);
$projects = mpull($projects, null, 'getID');
} else {
$projects = array();
}
foreach ($products as $product) {
$project_id = $product->getArcanistProjectID();
$project = idx($projects, $project_id);
$product->attachArcanistProject($project);
}
}
return $products;
}
private function buildWhereClause(AphrontDatabaseConnection $conn_r) { private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array(); $where = array();

View file

@ -21,6 +21,7 @@ final class ReleephProject extends ReleephDAO
protected $details = array(); protected $details = array();
private $repository = self::ATTACHABLE; private $repository = self::ATTACHABLE;
private $arcanistProject = self::ATTACHABLE;
public function getConfiguration() { public function getConfiguration() {
return array( return array(
@ -53,11 +54,14 @@ final class ReleephProject extends ReleephDAO
return $this; return $this;
} }
public function loadArcanistProject() { public function getArcanistProject() {
return $this->loadOneRelative( return $this->assertAttached($this->arcanistProject);
new PhabricatorRepositoryArcanistProject(), }
'id',
'getArcanistProjectID'); public function attachArcanistProject(
PhabricatorRepositoryArcanistProject $arcanist_project = null) {
$this->arcanistProject = $arcanist_project;
return $this;
} }
public function getPushers() { public function getPushers() {