Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/releeph/conduit/ConduitAPI_releeph_getbranches_Method.php b/src/applications/releeph/conduit/ConduitAPI_releeph_getbranches_Method.php
index d7a76e842c..861e69eb81 100644
--- a/src/applications/releeph/conduit/ConduitAPI_releeph_getbranches_Method.php
+++ b/src/applications/releeph/conduit/ConduitAPI_releeph_getbranches_Method.php
@@ -1,62 +1,62 @@
<?php
final class ConduitAPI_releeph_getbranches_Method
extends ConduitAPI_releeph_Method {
public function getMethodDescription() {
return "Return information about all active Releeph branches.";
}
public function defineParamTypes() {
return array(
);
}
public function defineReturnType() {
return 'nonempty list<dict<string, wild>>';
}
public function defineErrorTypes() {
return array(
);
}
protected function execute(ConduitAPIRequest $request) {
$results = array();
- $projects = id(new ReleephProject())->loadAllWhere('isActive = 1');
+ $projects = id(new ReleephProjectQuery())
+ ->setViewer($request->getUser())
+ ->withActive(1)
+ ->execute();
foreach ($projects as $project) {
- $repository = $project->loadOneRelative(
- id(new PhabricatorRepository()),
- 'id',
- 'getRepositoryID');
+ $repository = $project->getRepository();
$branches = $project->loadRelatives(
id(new ReleephBranch()),
'releephProjectID',
'getID',
'isActive = 1');
foreach ($branches as $branch) {
$full_branch_name = $branch->getName();
$cut_point_commit = $branch->loadOneRelative(
id(new PhabricatorRepositoryCommit()),
'phid',
'getCutPointCommitPHID');
$results[] = array(
'project' => $project->getName(),
'repository' => $repository->getCallsign(),
'branch' => $branch->getBasename(),
'fullBranchName' => $full_branch_name,
'symbolicName' => $branch->getSymbolicName(),
'cutPoint' => $branch->getCutPointCommitIdentifier(),
);
}
}
return $results;
}
}
diff --git a/src/applications/releeph/controller/project/ReleephProjectListController.php b/src/applications/releeph/controller/project/ReleephProjectListController.php
index 33537dd101..66c5e263cd 100644
--- a/src/applications/releeph/controller/project/ReleephProjectListController.php
+++ b/src/applications/releeph/controller/project/ReleephProjectListController.php
@@ -1,109 +1,105 @@
<?php
final class ReleephProjectListController extends ReleephController
implements PhabricatorApplicationSearchResultsControllerInterface {
private $queryKey;
public function shouldAllowPublic() {
return true;
}
public function willProcessRequest(array $data) {
$this->queryKey = idx($data, 'queryKey');
}
public function processRequest() {
$request = $this->getRequest();
$controller = id(new PhabricatorApplicationSearchController($request))
->setQueryKey($this->queryKey)
->setSearchEngine(new ReleephProjectSearchEngine())
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
}
public function renderResultsList(
array $projects,
PhabricatorSavedQuery $query) {
assert_instances_of($projects, 'ReleephProject');
$viewer = $this->getRequest()->getUser();
$list = id(new PhabricatorObjectItemListView())
->setUser($viewer);
foreach ($projects as $project) {
$id = $project->getID();
$item = id(new PhabricatorObjectItemView())
->setHeader($project->getName())
->setHref($this->getApplicationURI("project/{$id}/"));
$edit_uri = $this->getApplicationURI("project/{$id}/edit/");
$item->addAction(
id(new PHUIListItemView())
->setIcon('edit')
->setHref($edit_uri));
if ($project->getIsActive()) {
$disable_uri = $this->getApplicationURI(
"project/{$id}/action/deactivate/");
$item->addAction(
id(new PHUIListItemView())
->setIcon('delete')
->setName(pht('Deactivate'))
->setWorkflow(true)
->setHref($disable_uri));
} else {
$enable_uri = $this->getApplicationURI(
"project/{$id}/action/activate/");
$item->setDisabled(true);
$item->addIcon('none', pht('Inactive'));
$item->addAction(
id(new PHUIListItemView())
->setIcon('new')
->setName(pht('Reactivate'))
->setWorkflow(true)
->setHref($enable_uri));
}
- // TODO: See T3551.
-
- $repo = $project->loadPhabricatorRepository();
- if ($repo) {
- $item->addAttribute(
- phutil_tag(
- 'a',
- array(
- 'href' => '/diffusion/'.$repo->getCallsign().'/',
- ),
- 'r'.$repo->getCallsign()));
- }
+ $repo = $project->getRepository();
+ $item->addAttribute(
+ phutil_tag(
+ 'a',
+ array(
+ 'href' => '/diffusion/'.$repo->getCallsign().'/',
+ ),
+ 'r'.$repo->getCallsign()));
$arc = $project->loadArcanistProject();
if ($arc) {
$item->addAttribute($arc->getName());
}
$list->addItem($item);
}
return $list;
}
public function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('Create Project'))
->setHref($this->getApplicationURI('project/create/'))
->setIcon('create'));
return $crumbs;
}
}
diff --git a/src/applications/releeph/query/ReleephProjectQuery.php b/src/applications/releeph/query/ReleephProjectQuery.php
index 2104fde217..5a1b09bf4a 100644
--- a/src/applications/releeph/query/ReleephProjectQuery.php
+++ b/src/applications/releeph/query/ReleephProjectQuery.php
@@ -1,105 +1,130 @@
<?php
final class ReleephProjectQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $active;
private $ids;
private $phids;
+ private $needRepositories;
+
private $order = 'order-id';
const ORDER_ID = 'order-id';
const ORDER_NAME = 'order-name';
public function withActive($active) {
$this->active = $active;
return $this;
}
public function setOrder($order) {
$this->order = $order;
return $this;
}
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function loadPage() {
$table = new ReleephProject();
$conn_r = $table->establishConnection('r');
$rows = 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($rows);
}
+ public function willFilterPage(array $projects) {
+ assert_instances_of($projects, 'ReleephProject');
+
+ $repository_phids = mpull($projects, 'getRepositoryPHID');
+
+ $repositories = id(new PhabricatorRepositoryQuery())
+ ->setViewer($this->getViewer())
+ ->withPHIDs($repository_phids)
+ ->execute();
+ $repositories = mpull($repositories, null, 'getPHID');
+
+ foreach ($projects as $key => $project) {
+ $repo = idx($repositories, $project->getRepositoryPHID());
+ if (!$repo) {
+ unset($projects[$key]);
+ continue;
+ }
+ $project->attachRepository($repo);
+ }
+
+ return $projects;
+ }
+
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
if ($this->active !== null) {
$where[] = qsprintf(
$conn_r,
'isActive = %d',
- $this->active);
+ (int)$this->active);
}
if ($this->ids) {
$where[] = qsprintf(
$conn_r,
'id IN (%Ls)',
$this->ids);
}
if ($this->phids) {
$where[] = qsprintf(
$conn_r,
'phid IN (%Ls)',
$this->phids);
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
}
protected function getReversePaging() {
switch ($this->order) {
case self::ORDER_NAME:
return true;
}
return parent::getReversePaging();
}
protected function getPagingValue($result) {
switch ($this->order) {
case self::ORDER_NAME:
return $result->getName();
}
return parent::getPagingValue();
}
protected function getPagingColumn() {
switch ($this->order) {
case self::ORDER_NAME:
return 'name';
case self::ORDER_ID:
return parent::getPagingColumn();
default:
throw new Exception("Uknown order '{$this->order}'!");
}
}
}
diff --git a/src/applications/releeph/storage/ReleephProject.php b/src/applications/releeph/storage/ReleephProject.php
index 3d6b88b7a2..7d9c238e89 100644
--- a/src/applications/releeph/storage/ReleephProject.php
+++ b/src/applications/releeph/storage/ReleephProject.php
@@ -1,202 +1,214 @@
<?php
final class ReleephProject extends ReleephDAO
implements PhabricatorPolicyInterface {
const DEFAULT_BRANCH_NAMESPACE = 'releeph-releases';
const SYSTEM_AGENT_USERNAME_PREFIX = 'releeph-agent-';
const COMMIT_AUTHOR_NONE = 'commit-author-none';
const COMMIT_AUTHOR_FROM_DIFF = 'commit-author-is-from-diff';
const COMMIT_AUTHOR_REQUESTOR = 'commit-author-is-requestor';
protected $phid;
protected $name;
// Specifying the place to pick from is a requirement for svn, though not
// for git. It's always useful though for reasoning about what revs have
// been picked and which haven't.
protected $trunkBranch;
protected $repositoryID;
protected $repositoryPHID;
protected $isActive;
protected $createdByUserPHID;
protected $arcanistProjectID;
protected $projectID;
protected $details = array();
+ private $repository = self::ATTACHABLE;
+
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_SERIALIZATION => array(
'details' => self::SERIALIZATION_JSON,
),
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(ReleephPHIDTypeProject::TYPECONST);
}
public function getDetail($key, $default = null) {
return idx($this->details, $key, $default);
}
public function getURI($path = null) {
$components = array(
'/releeph/project',
$this->getID(),
$path
);
return implode('/', $components);
}
public function setDetail($key, $value) {
$this->details[$key] = $value;
return $this;
}
public function willSaveObject() {
// Do this first, to generate the PHID
parent::willSaveObject();
$banned_names = $this->getBannedNames();
if (in_array($this->name, $banned_names)) {
throw new Exception(sprintf(
"The name '%s' is in the list of banned project names!",
$this->name,
implode(', ', $banned_names)));
}
if (!$this->getDetail('releaseCounter')) {
$this->setDetail('releaseCounter', 0);
}
}
public function loadPhabricatorProject() {
if ($id = $this->getProjectID()) {
return id(new PhabricatorProject())->load($id);
}
return id(new PhabricatorProject())->makeEphemeral(); // dummy
}
public function loadArcanistProject() {
return $this->loadOneRelative(
new PhabricatorRepositoryArcanistProject(),
'id',
'getArcanistProjectID');
}
public function getPushers() {
return $this->getDetail('pushers', array());
}
public function isPusher(PhabricatorUser $user) {
// TODO Deprecate this once `isPusher` is out of the Facebook codebase.
return $this->isAuthoritative($user);
}
public function isAuthoritative(PhabricatorUser $user) {
return $this->isAuthoritativePHID($user->getPHID());
}
public function isAuthoritativePHID($phid) {
$pushers = $this->getPushers();
if (!$pushers) {
return true;
} else {
return in_array($phid, $pushers);
}
}
+ public function attachRepository(PhabricatorRepository $repository) {
+ $this->repository = $repository;
+ return $this;
+ }
+
+ public function getRepository() {
+ return $this->assertAttached($this->repository);
+ }
+
+ // TODO: Remove once everything uses ProjectQuery.
public function loadPhabricatorRepository() {
return $this->loadOneRelative(
new PhabricatorRepository(),
- 'id',
- 'getRepositoryID');
+ 'phid',
+ 'getRepositoryPHID');
}
public function getCurrentReleaseNumber() {
$current_release_numbers = array();
// From the project...
$current_release_numbers[] = $this->getDetail('releaseCounter', 0);
// From any branches...
$branches = id(new ReleephBranch())->loadAllWhere(
'releephProjectID = %d', $this->getID());
if ($branches) {
$release_numbers = array();
foreach ($branches as $branch) {
$current_release_numbers[] = $branch->getDetail('releaseNumber', 0);
}
}
return max($current_release_numbers);
}
public function getReleephFieldSelector() {
$class = $this->getDetail('field_selector');
if (!$class) {
$key = 'releeph.field-selector';
$class = PhabricatorEnv::getEnvConfig($key);
}
if ($class) {
return newv($class, array());
} else {
return new ReleephDefaultFieldSelector();
}
}
/**
* Wrapper to setIsActive() that logs who deactivated a project
*/
public function deactivate(PhabricatorUser $actor) {
return $this
->setIsActive(0)
->setDetail('last_deactivated_user', $actor->getPHID())
->setDetail('last_deactivated_time', time());
}
// Hide this from the public
private function setIsActive($v) {
return parent::setIsActive($v);
}
private function getBannedNames() {
return array(
'branch', // no one's tried this... yet!
);
}
public function isTestFile($filename) {
$test_paths = $this->getDetail('testPaths', array());
foreach ($test_paths as $test_path) {
if (preg_match($test_path, $filename)) {
return true;
}
}
return false;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
return PhabricatorPolicies::POLICY_USER;
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Nov 14, 12:47 PM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
337039
Default Alt Text
(14 KB)

Event Timeline