Differential D25066 Diff 390 src/applications/project/controller/PhabricatorProjectColumnEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/controller/PhabricatorProjectColumnEditController.php
Show All 39 Lines | if (!$is_new) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
} else { | } else { | ||||
$column = PhabricatorProjectColumn::initializeNewColumn($viewer); | $column = PhabricatorProjectColumn::initializeNewColumn($viewer); | ||||
} | } | ||||
$e_name = null; | $e_name = null; | ||||
$e_limit = null; | $e_limit = null; | ||||
$e_milestone_name = null; | |||||
$v_limit = $column->getPointLimit(); | $v_limit = $column->getPointLimit(); | ||||
$v_name = $column->getName(); | $v_name = $column->getName(); | ||||
$proxy = $column->getProxy(); | $proxy = $column->getProxy(); | ||||
$is_column = !$proxy; | $is_column = !$proxy; | ||||
$is_milestone = $proxy && $proxy->isMilestone(); | |||||
$v_milestone_name = null; | |||||
if ($is_milestone) { | |||||
$v_milestone_name = $proxy->getName(); | |||||
} | |||||
$validation_exception = null; | $validation_exception = null; | ||||
$view_uri = $project->getWorkboardURI(); | $view_uri = $project->getWorkboardURI(); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$v_name = $request->getStr('name'); | $v_name = $request->getStr('name'); | ||||
$v_limit = $request->getStr('limit'); | $v_limit = $request->getStr('limit'); | ||||
$v_milestone_name = $request->getStr('milestone.name'); | |||||
if ($is_new) { | if ($is_new) { | ||||
$column->setProjectPHID($project->getPHID()); | $column->setProjectPHID($project->getPHID()); | ||||
$column->attachProject($project); | $column->attachProject($project); | ||||
$columns = id(new PhabricatorProjectColumnQuery()) | $columns = id(new PhabricatorProjectColumnQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withProjectPHIDs(array($project->getPHID())) | ->withProjectPHIDs(array($project->getPHID())) | ||||
->execute(); | ->execute(); | ||||
$new_sequence = 1; | $new_sequence = 1; | ||||
if ($columns) { | if ($columns) { | ||||
$values = mpull($columns, 'getSequence'); | $values = mpull($columns, 'getSequence'); | ||||
$new_sequence = max($values) + 1; | $new_sequence = max($values) + 1; | ||||
} | } | ||||
$column->setSequence($new_sequence); | $column->setSequence($new_sequence); | ||||
} | } | ||||
$xactions = array(); | $xactions = array(); | ||||
$xactions_milestone = array(); | |||||
$type_name = PhabricatorProjectColumnNameTransaction::TRANSACTIONTYPE; | $type_name = PhabricatorProjectColumnNameTransaction::TRANSACTIONTYPE; | ||||
$type_limit = PhabricatorProjectColumnLimitTransaction::TRANSACTIONTYPE; | $type_limit = PhabricatorProjectColumnLimitTransaction::TRANSACTIONTYPE; | ||||
if ($is_column) { | if ($is_column) { | ||||
$xactions[] = id(new PhabricatorProjectColumnTransaction()) | $xactions[] = id(new PhabricatorProjectColumnTransaction()) | ||||
->setTransactionType($type_name) | ->setTransactionType($type_name) | ||||
->setNewValue($v_name); | ->setNewValue($v_name); | ||||
} else if ($is_milestone) { | |||||
// Save Milestone name | |||||
$type_project_name = PhabricatorProjectNameTransaction::TRANSACTIONTYPE; | |||||
$xactions_milestone[] = id(new PhabricatorProjectTransaction()) | |||||
->setTransactionType($type_project_name) | |||||
->setNewValue($v_milestone_name); | |||||
} | } | ||||
// Column Points | // Column Points | ||||
$xactions[] = id(new PhabricatorProjectColumnTransaction()) | $xactions[] = id(new PhabricatorProjectColumnTransaction()) | ||||
->setTransactionType($type_limit) | ->setTransactionType($type_limit) | ||||
->setNewValue($v_limit); | ->setNewValue($v_limit); | ||||
$saved_everything = false; | $saved_everything = false; | ||||
try { | try { | ||||
$editor = id(new PhabricatorProjectColumnTransactionEditor()) | $editor = id(new PhabricatorProjectColumnTransactionEditor()) | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->applyTransactions($column, $xactions); | ->applyTransactions($column, $xactions); | ||||
$saved_everything = true; | $saved_everything = true; | ||||
} catch (PhabricatorApplicationTransactionValidationException $ex) { | } catch (PhabricatorApplicationTransactionValidationException $ex) { | ||||
$e_name = $ex->getShortMessage($type_name); | $e_name = $ex->getShortMessage($type_name); | ||||
$e_limit = $ex->getShortMessage($type_limit); | $e_limit = $ex->getShortMessage($type_limit); | ||||
$validation_exception = $ex; | $validation_exception = $ex; | ||||
} | } | ||||
// Eventually save Milestone-related stuff | |||||
if ($saved_everything && $xactions_milestone) { | |||||
// Be pessimist, again. | |||||
$saved_everything = false; | |||||
try { | |||||
$editor_milestone = id(new PhabricatorProjectTransactionEditor()) | |||||
->setActor($viewer) | |||||
->setContinueOnNoEffect(true) | |||||
->setContentSourceFromRequest($request) | |||||
->applyTransactions($proxy, $xactions_milestone); | |||||
$saved_everything = true; | |||||
} catch (PhabricatorApplicationTransactionValidationException $ex) { | |||||
$e_milestone_name = $ex->getShortMessage($type_project_name); | |||||
$validation_exception = $ex; | |||||
} | |||||
} | |||||
if ($saved_everything) { | if ($saved_everything) { | ||||
return id(new AphrontRedirectResponse())->setURI($view_uri); | return id(new AphrontRedirectResponse())->setURI($view_uri); | ||||
} | } | ||||
} | } | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($request->getUser()); | ->setUser($request->getUser()); | ||||
if ($is_column) { | if ($is_column) { | ||||
// Project Column name field | // Project Column name field | ||||
$form->appendChild( | $form->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setValue($v_name) | ->setValue($v_name) | ||||
->setLabel(pht('Name')) | ->setLabel(pht('Name')) | ||||
->setName('name') | ->setName('name') | ||||
->setError($e_name)); | ->setError($e_name)); | ||||
} else if ($is_milestone) { | |||||
$form->appendChild( | |||||
id(new AphrontFormTextControl()) | |||||
->setValue($v_milestone_name) | |||||
->setLabel(pht('Milestone Name')) | |||||
->setName('milestone.name') | |||||
->setError($e_milestone_name)); | |||||
} | } | ||||
$form->appendChild( | $form->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setValue($v_limit) | ->setValue($v_limit) | ||||
->setLabel(pht('Point Limit')) | ->setLabel(pht('Point Limit')) | ||||
->setName('limit') | ->setName('limit') | ||||
->setError($e_limit) | ->setError($e_limit) | ||||
Show All 21 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0