1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 08:12:40 +01:00
phorge-phorge/src/applications/releeph/controller/request/ReleephRequestDifferentialCreateController.php

100 lines
3.1 KiB
PHP
Raw Normal View History

<?php
final class ReleephRequestDifferentialCreateController
extends ReleephProjectController {
private $revision;
Made declaration of ReleephRequestDifferentialCreateController::willProcessRequest() consistent with AphrontController::willProcessRequest(array $uri_data) Summary: When submitting a diff I noticed that the unit test `testEverythingImplemented` threw an error that did not fail a test. ``` [2013-03-18 16:35:16] ERROR 2048: Declaration of ReleephRequestDifferentialCreateController::willProcessRequest() should be compatible with AphrontController::willProcessRequest(array $uri_data) at [/home/anhnhan/dev/vanilla/phabricator/src/applications/releeph/controller/request/ReleephRequestDifferentialCreateController.php:99] #0 PhutilBootloader::executeInclude called at [/home/anhnhan/dev/vanilla/libphutil/src/__phutil_library_init__.php:203] #1 PhutilBootloader::executeInclude(/home/anhnhan/dev/vanilla/phabricator/src/applications/releeph/controller/request/ReleephRequestDifferentialCreateController.php) called at [/home/anhnhan/dev/vanilla/libphutil/src/__phutil_library_init__.php:193] #2 PhutilBootloader::loadLibrarySource(phabricator, applications/releeph/controller/request/ReleephRequestDifferentialCreateController.php) called at [/home/anhnhan/dev/vanilla/libphutil/src/symbols/PhutilSymbolLoader.php:341] #3 PhutilSymbolLoader::loadSymbol(Array of size 4 starting with: { type => class }) called at [/home/anhnhan/dev/vanilla/libphutil/src/symbols/PhutilSymbolLoader.php:246] #4 PhutilSymbolLoader::selectAndLoadSymbols() called at [/home/anhnhan/dev/vanilla/phabricator/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php:15] #5 PhabricatorInfrastructureTestCase::testEverythingImplemented() #6 call_user_func_array(Array of size 2 starting with: { 0 => Object PhabricatorInfrastructureTestCase }, Array ) called at [/home/anhnhan/dev/vanilla/arcanist/src/unit/engine/phutil/ArcanistPhutilTestCase.php:441] #7 ArcanistPhutilTestCase::run() called at [/home/anhnhan/dev/vanilla/arcanist/src/unit/engine/PhutilUnitTestEngine.php:60] #8 PhutilUnitTestEngine::run() called at [/home/anhnhan/dev/vanilla/arcanist/src/workflow/ArcanistUnitWorkflow.php:160] #9 ArcanistUnitWorkflow::run() called at [/home/anhnhan/dev/vanilla/arcanist/scripts/arcanist.php:271] ``` Test Plan: `arc unit --everything` before this change gave error. applied this change. Re-ran `arc unit --everything`, no error. Reviewers: edward Reviewed By: edward CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D5373
2013-03-19 14:04:43 +01:00
public function willProcessRequest(array $data) {
$diff_rev_id = $data['diffRevID'];
$diff_rev = id(new DifferentialRevision())->load($diff_rev_id);
if (!$diff_rev) {
throw new Exception(sprintf('D%d not found!', $diff_rev_id));
}
$this->revision = $diff_rev;
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$arc_project = id(new PhabricatorRepositoryArcanistProject())
->loadOneWhere('phid = %s', $this->revision->getArcanistProjectPHID());
$projects = id(new ReleephProject())->loadAllWhere(
'arcanistProjectID = %d AND isActive = 1',
$arc_project->getID());
if (!$projects) {
throw new ReleephRequestException(sprintf(
"D%d belongs to the '%s' Arcanist project, ".
"which is not part of any Releeph project!",
$this->revision->getID(),
$arc_project->getName()));
}
$branches = id(new ReleephBranch())->loadAllWhere(
'releephProjectID IN (%Ld) AND isActive = 1',
mpull($projects, 'getID'));
if (!$branches) {
throw new ReleephRequestException(sprintf(
"D%d could be in the Releeph project(s) %s, ".
"but this project / none of these projects have open branches.",
$this->revision->getID(),
implode(', ', mpull($projects, 'getName'))));
}
if (count($branches) === 1) {
return id(new AphrontRedirectResponse())
->setURI($this->buildReleephRequestURI(head($branches)));
}
$projects = msort(
mpull($projects, null, 'getID'),
'getName');
$branch_groups = mgroup($branches, 'getReleephProjectID');
require_celerity_resource('releeph-request-differential-create-dialog');
$dialog = id(new AphrontDialogView())
->setUser($user)
->setTitle(pht('Choose Releeph Branch'))
->setClass('releeph-request-differential-create-dialog')
->addCancelButton('/D'.$request->getStr('D'));
$dialog->appendChild(
pht("This differential revision changes code that is associated ".
"with multiple Releeph branches. ".
"Please select the branch where you would like this code to be picked."));
foreach ($branch_groups as $project_id => $branches) {
$project = idx($projects, $project_id);
$dialog->appendChild(
phutil_tag(
'h1',
array(),
$project->getName()));
$branches = msort($branches, 'getBasename');
foreach ($branches as $branch) {
$uri = $this->buildReleephRequestURI($branch);
$dialog->appendChild(
phutil_tag(
'a',
array(
'href' => $uri,
),
$branch->getDisplayNameWithDetail()));
}
}
return id(new AphrontDialogResponse)
->setDialog($dialog);
}
private function buildReleephRequestURI(ReleephBranch $branch) {
$uri = $branch->getURI('request/');
return id(new PhutilURI($uri))
->setQueryParam('D', $this->revision->getID());
}
}