Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/releeph/controller/ReleephProjectController.php b/src/applications/releeph/controller/ReleephProjectController.php
index c7530e1d79..cc3fc54bcc 100644
--- a/src/applications/releeph/controller/ReleephProjectController.php
+++ b/src/applications/releeph/controller/ReleephProjectController.php
@@ -1,136 +1,139 @@
<?php
abstract class ReleephProjectController extends ReleephController {
private $releephProject;
private $releephBranch;
private $releephRequest;
/**
* ReleephController will take care of loading any Releeph* objects
* referenced in the URL.
*/
public function willProcessRequest(array $data) {
// Project
$project = null;
$project_id = idx($data, 'projectID');
$project_name = idx($data, 'projectName');
if ($project_id) {
- $project = id(new ReleephProject())->load($project_id);
+ $project = id(new ReleephProjectQuery())
+ ->setViewer($this->getRequest()->getUser())
+ ->withIDs(array($project_id))
+ ->executeOne();
if (!$project) {
throw new Exception(
"ReleephProject with id '{$project_id}' not found!");
}
} elseif ($project_name) {
$project = id(new ReleephProject())
->loadOneWhere('name = %s', $project_name);
if (!$project) {
throw new Exception(
"ReleephProject with name '{$project_name}' not found!");
}
}
// Branch
$branch = null;
$branch_id = idx($data, 'branchID');
$branch_name = idx($data, 'branchName');
if ($branch_id) {
$branch = id(new ReleephBranch())->load($branch_id);
if (!$branch) {
throw new Exception("Branch with id '{$branch_id}' not found!");
}
} elseif ($branch_name) {
if (!$project) {
throw new Exception(
"You cannot refer to a branch by name without also referring ".
"to a ReleephProject (branch names are only unique in projects).");
}
$branch = id(new ReleephBranch())->loadOneWhere(
'basename = %s AND releephProjectID = %d',
$branch_name,
$project->getID());
if (!$branch) {
throw new Exception(
"ReleephBranch with basename '{$branch_name}' not found ".
"in project '{$project->getName()}'!");
}
}
// Request
$request = null;
$request_id = idx($data, 'requestID');
if ($request_id) {
$request = id(new ReleephRequest())->load($request_id);
if (!$request) {
throw new Exception(
"ReleephRequest with id '{$request_id}' not found!");
}
}
// Fill in the gaps
if ($request && !$branch) {
$branch = $request->loadReleephBranch();
}
if ($branch && !$project) {
$project = $branch->loadReleephProject();
}
// Set!
$this->releephProject = $project;
$this->releephBranch = $branch;
$this->releephRequest = $request;
}
protected function getReleephProject() {
if (!$this->releephProject) {
throw new Exception(
'This controller did not load a ReleephProject from the URL $data.');
}
return $this->releephProject;
}
protected function getReleephBranch() {
if (!$this->releephBranch) {
throw new Exception(
'This controller did not load a ReleephBranch from the URL $data.');
}
return $this->releephBranch;
}
protected function getReleephRequest() {
if (!$this->releephRequest) {
throw new Exception(
'This controller did not load a ReleephRequest from the URL $data.');
}
return $this->releephRequest;
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$project = $this->getReleephProject();
$project_id = $project->getID();
$project_uri = $this->getApplicationURI("project/{$project_id}/");
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setHref($project_uri)
->setName($project->getName()));
try {
$branch = $this->getReleephBranch();
$branch_uri = $branch->getURI();
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setHref($branch_uri)
->setName($branch->getDisplayNameWithDetail()));
} catch (Exception $ex) {
// TODO: This is kind of derps.
}
return $crumbs;
}
}
diff --git a/src/applications/releeph/controller/project/ReleephProjectActionController.php b/src/applications/releeph/controller/project/ReleephProjectActionController.php
index dfe20763f2..40e47f4b4b 100644
--- a/src/applications/releeph/controller/project/ReleephProjectActionController.php
+++ b/src/applications/releeph/controller/project/ReleephProjectActionController.php
@@ -1,70 +1,58 @@
<?php
final class ReleephProjectActionController extends ReleephProjectController {
private $action;
public function willProcessRequest(array $data) {
parent::willProcessRequest($data);
$this->action = $data['action'];
}
public function processRequest() {
$request = $this->getRequest();
+ $viewer = $request->getUser();
$action = $this->action;
- $rph_project = $this->getReleephProject();
+
+ $project = id(new ReleephProjectQuery())
+ ->withIDs(array($this->getReleephProject()->getID()))
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->setViewer($viewer)
+ ->executeOne();
+ if (!$project) {
+ return new Aphront404Response();
+ }
+
+ $project_id = $project->getID();
+ $project_uri = $this->getApplicationURI("project/{$project_id}/");
switch ($action) {
case 'deactivate':
if ($request->isDialogFormPost()) {
- $rph_project->deactivate($request->getUser())->save();
- return id(new AphrontRedirectResponse())->setURI('/releeph');
+ $project->deactivate($viewer)->save();
+ return id(new AphrontRedirectResponse())->setURI($project_uri);
}
$dialog = id(new AphrontDialogView())
->setUser($request->getUser())
->setTitle(pht('Really deactivate Releeph Project?'))
->appendChild(phutil_tag(
'p',
array(),
pht('Really deactivate the Releeph project: %s?',
- $rph_project->getName())))
- ->appendChild(phutil_tag(
- 'p',
- array(),
- pht('It will still exist, but '.
- 'will be hidden from the list of active projects.')))
- ->addSubmitButton(pht('Deactivate Releeph Project'))
- ->addCancelButton($request->getRequestURI());
+ $project->getName())))
+ ->addSubmitButton(pht('Deactivate Project'))
+ ->addCancelButton($project_uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
-
case 'activate':
- $rph_project->setIsActive(1)->save();
- return id(new AphrontRedirectResponse())->setURI('/releeph');
-
- case 'delete':
- if ($request->isDialogFormPost()) {
- $rph_project->delete();
- return id(new AphrontRedirectResponse())
- ->setURI('/releeph/project/inactive');
- }
-
- $dialog = id(new AphrontDialogView())
- ->setUser($request->getUser())
- ->setTitle(pht('Really delete Releeph Project?'))
- ->appendChild(phutil_tag(
- 'p',
- array(),
- pht('Really delete the Releeph project: %s? '.
- 'This cannot be undone!'),
- $rph_project->getName()))
- ->setHeaderColor(PhabricatorActionHeaderView::HEADER_RED)
- ->addSubmitButton(pht('Delete'))
- ->addCancelButton($request->getRequestURI());
- return id(new AphrontDialogResponse())->setDialog($dialog);
-
+ $project->setIsActive(1)->save();
+ return id(new AphrontRedirectResponse())->setURI($project_uri);
}
}
}
diff --git a/src/applications/releeph/controller/project/ReleephProjectListController.php b/src/applications/releeph/controller/project/ReleephProjectListController.php
index 93a491a1f8..a8caf83401 100644
--- a/src/applications/releeph/controller/project/ReleephProjectListController.php
+++ b/src/applications/releeph/controller/project/ReleephProjectListController.php
@@ -1,104 +1,79 @@
<?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/");
-
+ if (!$project->getIsActive()) {
$item->setDisabled(true);
$item->addIcon('none', pht('Inactive'));
- $item->addAction(
- id(new PHUIListItemView())
- ->setIcon('new')
- ->setName(pht('Reactivate'))
- ->setWorkflow(true)
- ->setHref($enable_uri));
}
$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/controller/project/ReleephProjectViewController.php b/src/applications/releeph/controller/project/ReleephProjectViewController.php
index 5941c7400c..12db331632 100644
--- a/src/applications/releeph/controller/project/ReleephProjectViewController.php
+++ b/src/applications/releeph/controller/project/ReleephProjectViewController.php
@@ -1,168 +1,257 @@
<?php
final class ReleephProjectViewController extends ReleephProjectController
implements PhabricatorApplicationSearchResultsControllerInterface {
private $queryKey;
public function shouldAllowPublic() {
return true;
}
public function willProcessRequest(array $data) {
parent::willProcessRequest($data);
$this->queryKey = idx($data, 'queryKey');
}
public function processRequest() {
$request = $this->getRequest();
$controller = id(new PhabricatorApplicationSearchController($request))
->setQueryKey($this->queryKey)
+ ->setPreface($this->renderPreface())
->setSearchEngine(
id(new ReleephBranchSearchEngine())
->setProjectID($this->getReleephProject()->getID()))
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
}
public function renderResultsList(
array $branches,
PhabricatorSavedQuery $saved) {
assert_instances_of($branches, 'ReleephBranch');
$viewer = $this->getRequest()->getUser();
$projects = mpull($branches, 'getProject');
$repo_phids = mpull($projects, 'getRepositoryPHID');
$repos = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withPHIDs($repo_phids)
->execute();
$repos = mpull($repos, null, 'getPHID');
$phids = mpull($branches, 'getCreatedByUserPHID');
$this->loadHandles($phids);
$requests = array();
if ($branches) {
$requests = id(new ReleephRequestQuery())
->setViewer($viewer)
->withBranchIDs(mpull($branches, 'getID'))
->withStatus(ReleephRequestQuery::STATUS_OPEN)
->execute();
$requests = mgroup($requests, 'getBranchID');
}
$list = id(new PhabricatorObjectItemListView())
->setUser($viewer);
foreach ($branches as $branch) {
$diffusion_href = null;
$repo = idx($repos, $branch->getProject()->getRepositoryPHID());
if ($repo) {
$drequest = DiffusionRequest::newFromDictionary(
array(
'user' => $viewer,
'repository' => $repo,
));
$diffusion_href = $drequest->generateURI(
array(
'action' => 'branch',
'branch' => $branch->getName(),
));
}
$branch_link = $branch->getName();
if ($diffusion_href) {
$branch_link = phutil_tag(
'a',
array(
'href' => $diffusion_href,
),
$branch_link);
}
$item = id(new PhabricatorObjectItemView())
->setHeader($branch->getDisplayName())
->setHref($branch->getURI())
->addAttribute($branch_link);
$item->addAction(
id(new PHUIListItemView())
->setIcon('edit')
->setHref($branch->getURI('edit/')));
if ($branch->getIsActive()) {
$item->setBarColor('blue');
$item->addAction(
id(new PHUIListItemView())
->setIcon('delete')
->setWorkflow(true)
->setHref($branch->getURI('close/')));
} else {
$item->setDisabled(true);
$item->addAction(
id(new PHUIListItemView())
->setIcon('enable')
->setWorkflow(true)
->setHref($branch->getURI('re-open/')));
}
$commit = $branch->getCutPointCommit();
if ($commit) {
$item->addIcon(
'none',
phabricator_datetime($commit->getEpoch(), $viewer));
}
$open_count = count(idx($requests, $branch->getID(), array()));
if ($open_count) {
$item->setBarColor('orange');
$item->addIcon(
'fork',
pht('%d Open Pull Request(s)', new PhutilNumber($open_count)));
}
$list->addItem($item);
}
return $list;
}
public function buildSideNavView($for_app = false) {
$user = $this->getRequest()->getUser();
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
if ($for_app) {
$nav->addFilter('project/create/', pht('Create Project'));
}
id(new ReleephBranchSearchEngine())
->setProjectID($this->getReleephProject()->getID())
->setViewer($user)
->addNavigationItems($nav->getMenu());
$nav->selectFilter(null);
return $nav;
}
public function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$project = $this->getReleephProject();
$crumbs->addAction(
id(new PHUIListItemView())
->setHref($project->getURI('cutbranch'))
->setName(pht('Cut New Branch'))
->setIcon('create'));
return $crumbs;
}
+ private function renderPreface() {
+ $project = $this->getReleephProject();
+ $viewer = $this->getRequest()->getUser();
+
+ $id = $project->getID();
+
+ $header = id(new PhabricatorHeaderView())
+ ->setHeader($project->getName());
+
+ if (!$project->getIsActive()) {
+ $header->addTag(
+ id(new PhabricatorTagView())
+ ->setType(PhabricatorTagView::TYPE_STATE)
+ ->setBackgroundColor(PhabricatorTagView::COLOR_BLACK)
+ ->setName(pht('Deactivated')));
+ }
+
+ $actions = id(new PhabricatorActionListView())
+ ->setUser($viewer)
+ ->setObject($project)
+ ->setObjectURI($this->getRequest()->getRequestURI());
+
+ $can_edit = PhabricatorPolicyFilter::hasCapability(
+ $viewer,
+ $project,
+ PhabricatorPolicyCapability::CAN_EDIT);
+
+ $edit_uri = $this->getApplicationURI("project/{$id}/edit/");
+
+ $deactivate_uri = "project/{$id}/action/deactivate/";
+ $deactivate_uri = $this->getApplicationURI($deactivate_uri);
+
+ $reactivate_uri = "project/{$id}/action/activate/";
+ $reactivate_uri = $this->getApplicationURI($reactivate_uri);
+
+ $actions->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Edit Project'))
+ ->setHref($edit_uri)
+ ->setIcon('edit')
+ ->setDisabled(!$can_edit)
+ ->setWorkflow(!$can_edit));
+
+ if ($project->getIsActive()) {
+ $actions->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Deactivate Project'))
+ ->setHref($deactivate_uri)
+ ->setIcon('delete')
+ ->setDisabled(!$can_edit)
+ ->setWorkflow(true));
+ } else {
+ $actions->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Reactivate Project'))
+ ->setHref($reactivate_uri)
+ ->setIcon('new')
+ ->setUser($viewer)
+ ->setRenderAsForm(true)
+ ->setDisabled(!$can_edit)
+ ->setWorkflow(true));
+ }
+
+
+ $properties = id(new PhabricatorPropertyListView())
+ ->setUser($viewer)
+ ->setObject($project);
+
+ $properties->addProperty(
+ pht('Repository'),
+ $project->getRepository()->getName());
+
+ $pushers = $project->getPushers();
+ if ($pushers) {
+ $this->loadHandles($pushers);
+ $properties->addProperty(
+ pht('Pushers'),
+ $this->renderHandlesForPHIDs($pushers));
+ }
+
+ return array(
+ $header,
+ $actions,
+ $properties,
+ );
+
+ }
+
}
diff --git a/src/applications/releeph/storage/ReleephProject.php b/src/applications/releeph/storage/ReleephProject.php
index 668aef79c0..8f31a038a4 100644
--- a/src/applications/releeph/storage/ReleephProject.php
+++ b/src/applications/releeph/storage/ReleephProject.php
@@ -1,195 +1,196 @@
<?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 $repositoryPHID;
protected $isActive;
protected $createdByUserPHID;
protected $arcanistProjectID;
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 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(),
'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() {
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,
+ PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
return PhabricatorPolicies::POLICY_USER;
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
}
diff --git a/src/applications/search/controller/PhabricatorApplicationSearchController.php b/src/applications/search/controller/PhabricatorApplicationSearchController.php
index e79c14afef..969bb7c244 100644
--- a/src/applications/search/controller/PhabricatorApplicationSearchController.php
+++ b/src/applications/search/controller/PhabricatorApplicationSearchController.php
@@ -1,322 +1,336 @@
<?php
final class PhabricatorApplicationSearchController
extends PhabricatorSearchBaseController {
private $searchEngine;
private $navigation;
private $queryKey;
+ private $preface;
+
+ public function setPreface($preface) {
+ $this->preface = $preface;
+ return $this;
+ }
+
+ public function getPreface() {
+ return $this->preface;
+ }
public function setQueryKey($query_key) {
$this->queryKey = $query_key;
return $this;
}
protected function getQueryKey() {
return $this->queryKey;
}
public function setNavigation(AphrontSideNavFilterView $navigation) {
$this->navigation = $navigation;
return $this;
}
protected function getNavigation() {
return $this->navigation;
}
public function setSearchEngine(
PhabricatorApplicationSearchEngine $search_engine) {
$this->searchEngine = $search_engine;
return $this;
}
protected function getSearchEngine() {
return $this->searchEngine;
}
protected function validateDelegatingController() {
$parent = $this->getDelegatingController();
if (!$parent) {
throw new Exception(
"You must delegate to this controller, not invoke it directly.");
}
$engine = $this->getSearchEngine();
if (!$engine) {
throw new Exception(
"Call setEngine() before delegating to this controller!");
}
$nav = $this->getNavigation();
if (!$nav) {
throw new Exception(
"Call setNavigation() before delegating to this controller!");
}
$engine->setViewer($this->getRequest()->getUser());
$parent = $this->getDelegatingController();
$interface = 'PhabricatorApplicationSearchResultsControllerInterface';
if (!$parent instanceof $interface) {
throw new Exception(
"Delegating controller must implement '{$interface}'.");
}
}
public function processRequest() {
$this->validateDelegatingController();
$key = $this->getQueryKey();
if ($key == 'edit') {
return $this->processEditRequest();
} else {
return $this->processSearchRequest();
}
}
private function processSearchRequest() {
$parent = $this->getDelegatingController();
$request = $this->getRequest();
$user = $request->getUser();
$engine = $this->getSearchEngine();
$nav = $this->getNavigation();
if ($request->isFormPost()) {
$saved_query = $engine->buildSavedQueryFromRequest($request);
$this->saveQuery($saved_query);
return id(new AphrontRedirectResponse())->setURI(
$engine->getQueryResultsPageURI($saved_query->getQueryKey()));
}
$named_query = null;
$run_query = true;
$query_key = $this->queryKey;
if ($this->queryKey == 'advanced') {
$run_query = false;
$query_key = $request->getStr('query');
} else if (!strlen($this->queryKey)) {
$query_key = head_key($engine->loadEnabledNamedQueries());
}
if ($engine->isBuiltinQuery($query_key)) {
$saved_query = $engine->buildSavedQueryFromBuiltin($query_key);
$named_query = idx($engine->loadEnabledNamedQueries(), $query_key);
} else if ($query_key) {
$saved_query = id(new PhabricatorSavedQueryQuery())
->setViewer($user)
->withQueryKeys(array($query_key))
->executeOne();
if (!$saved_query) {
return new Aphront404Response();
}
$named_query = idx($engine->loadEnabledNamedQueries(), $query_key);
} else {
$saved_query = $engine->buildSavedQueryFromRequest($request);
}
$nav->selectFilter(
'query/'.$saved_query->getQueryKey(),
'query/advanced');
$form = id(new AphrontFormView())
->setNoShading(true)
->setUser($user);
$engine->buildSearchForm($form, $saved_query);
$errors = $engine->getErrors();
if ($errors) {
$run_query = false;
$errors = id(new AphrontErrorView())
->setTitle(pht('Query Errors'))
->setErrors($errors);
}
$submit = id(new AphrontFormSubmitControl())
->setValue(pht('Execute Query'));
if ($run_query && !$named_query && $user->isLoggedIn()) {
$submit->addCancelButton(
'/search/edit/'.$saved_query->getQueryKey().'/',
pht('Save Custom Query...'));
}
$form->appendChild($submit);
$filter_view = id(new AphrontListFilterView())->appendChild($form);
if ($run_query && $named_query) {
if ($named_query->getIsBuiltin()) {
$description = pht(
'Showing results for query "%s".',
$named_query->getQueryName());
} else {
$description = pht(
'Showing results for saved query "%s".',
$named_query->getQueryName());
}
$filter_view->setCollapsed(
pht('Edit Query...'),
pht('Hide Query'),
$description,
$this->getApplicationURI('query/advanced/?query='.$query_key));
}
+ if ($this->getPreface()) {
+ $nav->appendChild($this->getPreface());
+ }
+
$nav->appendChild($filter_view);
if ($run_query) {
$query = $engine->buildQueryFromSavedQuery($saved_query);
$pager = new AphrontCursorPagerView();
$pager->readFromRequest($request);
$pager->setPageSize($engine->getPageSize($saved_query));
$objects = $query->setViewer($request->getUser())
->executeWithCursorPager($pager);
$list = $parent->renderResultsList($objects, $saved_query);
$nav->appendChild($list);
// TODO: This is a bit hacky.
if ($list instanceof PhabricatorObjectItemListView) {
$list->setNoDataString(pht("No results found for this query."));
$list->setPager($pager);
} else {
$nav->appendChild($pager);
}
}
if ($errors) {
$nav->appendChild($errors);
}
if ($named_query) {
$title = pht('Query: %s', $named_query->getQueryName());
} else {
$title = pht('Advanced Search');
}
$crumbs = $parent
->buildApplicationCrumbs()
->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht("Search")));
$nav->setCrumbs($crumbs);
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
'device' => true,
));
}
private function processEditRequest() {
$parent = $this->getDelegatingController();
$request = $this->getRequest();
$user = $request->getUser();
$engine = $this->getSearchEngine();
$nav = $this->getNavigation();
$named_queries = $engine->loadAllNamedQueries();
$list_id = celerity_generate_unique_node_id();
$list = new PhabricatorObjectItemListView();
$list->setUser($user);
$list->setID($list_id);
Javelin::initBehavior(
'search-reorder-queries',
array(
'listID' => $list_id,
'orderURI' => '/search/order/'.get_class($engine).'/',
));
foreach ($named_queries as $named_query) {
$class = get_class($engine);
$key = $named_query->getQueryKey();
$item = id(new PhabricatorObjectItemView())
->setHeader($named_query->getQueryName())
->setHref($engine->getQueryResultsPageURI($key));
if ($named_query->getIsBuiltin() && $named_query->getIsDisabled()) {
$icon = 'new';
} else {
$icon = 'delete';
}
$item->addAction(
id(new PHUIListItemView())
->setIcon($icon)
->setHref('/search/delete/'.$key.'/'.$class.'/')
->setWorkflow(true));
if ($named_query->getIsBuiltin()) {
if ($named_query->getIsDisabled()) {
$item->addIcon('delete-grey', pht('Disabled'));
$item->setDisabled(true);
} else {
$item->addIcon('lock-grey', pht('Builtin'));
}
} else {
$item->addAction(
id(new PHUIListItemView())
->setIcon('edit')
->setHref('/search/edit/'.$key.'/'));
}
$item->setGrippable(true);
$item->addSigil('named-query');
$item->setMetadata(
array(
'queryKey' => $named_query->getQueryKey(),
));
$list->addItem($item);
}
$list->setNoDataString(pht('No saved queries.'));
$crumbs = $parent
->buildApplicationCrumbs()
->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht("Saved Queries"))
->setHref($engine->getQueryManagementURI()));
$nav->selectFilter('query/edit');
$nav->setCrumbs($crumbs);
$nav->appendChild($list);
return $parent->buildApplicationPage(
$nav,
array(
'title' => pht("Saved Queries"),
'device' => true,
));
}
private function saveQuery(PhabricatorSavedQuery $query) {
$query->setEngineClassName(get_class($this->getSearchEngine()));
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
try {
$query->save();
} catch (AphrontQueryDuplicateKeyException $ex) {
// Ignore, this is just a repeated search.
}
unset($unguarded);
}
protected function buildApplicationMenu() {
return $this->getDelegatingController()->buildApplicationMenu();
}
}

File Metadata

Mime Type
text/x-diff
Expires
Wed, Feb 4, 7:04 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
738984
Default Alt Text
(33 KB)

Event Timeline