2014-03-18 18:40:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectBoardDeleteController
|
2014-03-26 22:40:47 +01:00
|
|
|
extends PhabricatorProjectBoardController {
|
2014-03-18 18:40:31 +01:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
private $projectID;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->projectID = $data['projectID'];
|
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->withIDs(array($this->projectID))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2014-03-26 22:40:47 +01:00
|
|
|
$this->setProject($project);
|
2014-03-18 18:40:31 +01:00
|
|
|
|
2014-03-26 22:40:47 +01:00
|
|
|
$column = id(new PhabricatorProjectColumnQuery())
|
2014-03-18 18:40:31 +01:00
|
|
|
->setViewer($viewer)
|
2014-03-26 22:40:47 +01:00
|
|
|
->withIDs(array($this->id))
|
2014-03-18 18:40:31 +01:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT))
|
2014-03-26 22:40:47 +01:00
|
|
|
->executeOne();
|
|
|
|
if (!$column) {
|
2014-03-18 18:40:31 +01:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$error_view = null;
|
2014-03-26 22:40:47 +01:00
|
|
|
$column_phid = $column->getPHID();
|
|
|
|
$has_task_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
|
|
|
$column_phid,
|
|
|
|
PhabricatorEdgeConfig::TYPE_COLUMN_HAS_OBJECT);
|
|
|
|
|
|
|
|
if ($has_task_phids) {
|
|
|
|
$error_view = id(new AphrontErrorView())
|
|
|
|
->setTitle(pht('Column has Tasks!'));
|
|
|
|
if ($column->isDeleted()) {
|
|
|
|
$error_view->setErrors(array(pht(
|
|
|
|
'A column can not be activated if it has tasks '.
|
|
|
|
'in it. Please remove the tasks and try again.')));
|
2014-03-18 18:40:31 +01:00
|
|
|
} else {
|
2014-03-26 22:40:47 +01:00
|
|
|
$error_view->setErrors(array(pht(
|
|
|
|
'A column can not be deleted if it has tasks '.
|
|
|
|
'in it. Please remove the tasks and try again.')));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$view_uri = $this->getApplicationURI(
|
|
|
|
'/board/'.$this->projectID.'/column/'.$this->id.'/');
|
2014-03-18 18:40:31 +01:00
|
|
|
|
2014-03-26 22:40:47 +01:00
|
|
|
if ($request->isFormPost() && !$error_view) {
|
|
|
|
if ($column->isDeleted()) {
|
|
|
|
$new_status = PhabricatorProjectColumn::STATUS_ACTIVE;
|
|
|
|
} else {
|
|
|
|
$new_status = PhabricatorProjectColumn::STATUS_DELETED;
|
2014-03-18 18:40:31 +01:00
|
|
|
}
|
2014-03-26 22:40:47 +01:00
|
|
|
|
|
|
|
$type_status = PhabricatorProjectColumnTransaction::TYPE_STATUS;
|
|
|
|
$xactions = array(id(new PhabricatorProjectColumnTransaction())
|
|
|
|
->setTransactionType($type_status)
|
|
|
|
->setNewValue($new_status));
|
|
|
|
|
|
|
|
$editor = id(new PhabricatorProjectColumnTransactionEditor())
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->applyTransactions($column, $xactions);
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
2014-03-18 18:40:31 +01:00
|
|
|
}
|
|
|
|
|
2014-03-26 22:40:47 +01:00
|
|
|
if ($column->isDeleted()) {
|
|
|
|
$title = pht('Activate Column');
|
|
|
|
} else {
|
|
|
|
$title = pht('Delete Column');
|
|
|
|
}
|
2014-03-18 18:40:31 +01:00
|
|
|
$submit = $title;
|
2014-03-26 22:40:47 +01:00
|
|
|
if ($error_view) {
|
|
|
|
$body = $error_view;
|
|
|
|
} else if ($column->isDeleted()) {
|
|
|
|
$body = pht('Are you sure you want to activate this column?');
|
|
|
|
} else {
|
|
|
|
$body = pht('Are you sure you want to delete this column?');
|
|
|
|
}
|
|
|
|
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
|
|
|
->setTitle($title)
|
|
|
|
->appendChild($body)
|
|
|
|
->setDisableWorkflowOnCancel(true)
|
|
|
|
->addSubmitButton($title)
|
|
|
|
->addCancelButton($view_uri);
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())
|
|
|
|
->setDialog($dialog);
|
2014-03-18 18:40:31 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|