2015-12-27 06:45:53 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectEditController
|
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
2015-12-27 05:16:36 -08:00
|
|
|
private $engine;
|
|
|
|
|
|
|
|
public function setEngine(PhabricatorProjectEditEngine $engine) {
|
|
|
|
$this->engine = $engine;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEngine() {
|
|
|
|
return $this->engine;
|
|
|
|
}
|
|
|
|
|
2015-12-27 06:45:53 -08:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2015-12-27 05:16:36 -08:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$engine = id(new PhabricatorProjectEditEngine())
|
|
|
|
->setController($this);
|
|
|
|
|
|
|
|
$this->setEngine($engine);
|
|
|
|
|
|
|
|
$id = $request->getURIData('id');
|
|
|
|
if (!$id) {
|
2016-02-15 07:20:29 -08:00
|
|
|
// This capability is checked again later, but checking it here
|
|
|
|
// explicitly gives us a better error message.
|
|
|
|
$this->requireApplicationCapability(
|
|
|
|
ProjectCreateProjectsCapability::CAPABILITY);
|
|
|
|
|
2015-12-27 05:16:36 -08:00
|
|
|
$parent_id = head($request->getArr('parent'));
|
|
|
|
if (!$parent_id) {
|
|
|
|
$parent_id = $request->getStr('parent');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($parent_id) {
|
|
|
|
$is_milestone = false;
|
|
|
|
} else {
|
|
|
|
$parent_id = head($request->getArr('milestone'));
|
|
|
|
if (!$parent_id) {
|
|
|
|
$parent_id = $request->getStr('milestone');
|
|
|
|
}
|
|
|
|
$is_milestone = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($parent_id) {
|
|
|
|
$query = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
2016-02-01 07:04:19 -08:00
|
|
|
->needImages(true)
|
2015-12-27 05:16:36 -08:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
));
|
|
|
|
|
|
|
|
if (ctype_digit($parent_id)) {
|
|
|
|
$query->withIDs(array($parent_id));
|
|
|
|
} else {
|
|
|
|
$query->withPHIDs(array($parent_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
$parent = $query->executeOne();
|
|
|
|
|
|
|
|
if ($is_milestone) {
|
|
|
|
if (!$parent->supportsMilestones()) {
|
2016-02-01 07:04:19 -08:00
|
|
|
$cancel_uri = "/project/subprojects/{$parent_id}/";
|
2015-12-27 05:16:36 -08:00
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('No Milestones'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht('You can not add milestones to this project.'))
|
|
|
|
->addCancelButton($cancel_uri);
|
|
|
|
}
|
|
|
|
$engine->setMilestoneProject($parent);
|
|
|
|
} else {
|
|
|
|
if (!$parent->supportsSubprojects()) {
|
|
|
|
$cancel_uri = "/project/subprojects/{$parent_id}/";
|
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('No Subprojects'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht('You can not add subprojects to this project.'))
|
|
|
|
->addCancelButton($cancel_uri);
|
|
|
|
}
|
|
|
|
$engine->setParentProject($parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->setProject($parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $engine->buildResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildApplicationCrumbs() {
|
|
|
|
$crumbs = parent::buildApplicationCrumbs();
|
|
|
|
|
|
|
|
$engine = $this->getEngine();
|
|
|
|
if ($engine) {
|
|
|
|
$parent = $engine->getParentProject();
|
2016-02-01 07:04:19 -08:00
|
|
|
$milestone = $engine->getMilestoneProject();
|
|
|
|
if ($parent || $milestone) {
|
|
|
|
$id = nonempty($parent, $milestone)->getID();
|
2015-12-27 05:16:36 -08:00
|
|
|
$crumbs->addTextCrumb(
|
|
|
|
pht('Subprojects'),
|
|
|
|
$this->getApplicationURI("subprojects/{$id}/"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $crumbs;
|
2015-12-27 06:45:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|