2014-01-13 21:24:36 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectMoveController
|
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
2015-08-08 19:34:55 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2014-01-13 21:24:36 +01:00
|
|
|
|
2014-01-13 21:24:50 +01:00
|
|
|
$column_phid = $request->getStr('columnPHID');
|
|
|
|
$object_phid = $request->getStr('objectPHID');
|
|
|
|
$after_phid = $request->getStr('afterPHID');
|
2014-03-27 18:50:54 +01:00
|
|
|
$before_phid = $request->getStr('beforePHID');
|
2014-08-08 17:11:00 +02:00
|
|
|
$order = $request->getStr('order', PhabricatorProjectColumn::DEFAULT_ORDER);
|
|
|
|
|
2014-01-13 21:24:50 +01:00
|
|
|
|
2014-01-13 21:24:36 +01:00
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
))
|
2015-08-08 19:34:55 +02:00
|
|
|
->withIDs(array($id))
|
2014-01-13 21:24:36 +01:00
|
|
|
->executeOne();
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
Begin lifting column layout logic out of ColumnPositionQuery
Summary:
Ref T10010. This is a precursor to D15171, which I'll eventually rebuild on top of these changes.
Currently, ColumnPositionQuery does a lot of "column layout" stuff that's very similar to the Milestone/Subproject stuff that needs to happen in D15171. The current approach there ended up splitting this layout stuff across two unrelated classes (ColumnPositionQuery + BoardViewController), neither of which is a particularly great place to do it -- the Query is too low-level, and the Controller is too high-level.
Instead, introduce a new "LayoutEngine" which does all this layout stuff. Swap two of the four places that we query this stuff over to the new engine:
- "Project (Column)" on tasks.
- Transaction generation when moving cards.
These sites aren't swapped by this diff, but will be by the next one:
- Actually applying transactions.
- Main layout for boards (this could swap easily now, but applying transactions currently relies on position writes having taken place, so it can't swap until the other one swaps).
Once everything is swapped over, I should be able to add the D15171 logic to LayoutEngine instead of BoardViewController and end up with a cleaner approach overall.
One particularly benefit is that //looking// at a board won't do a bunch of position writes anymore, which wasn't a big deal, but which I was a bit uneasy with.
Test Plan:
- Viewed tasks that are on boards, saw column annotations in project list.
- Moved cards between columns on a board.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10010
Differential Revision: https://secure.phabricator.com/D15174
2016-02-03 18:39:17 +01:00
|
|
|
$board_phid = $project->getPHID();
|
|
|
|
|
2016-01-30 03:44:47 +01:00
|
|
|
$object = id(new ManiphestTaskQuery())
|
2014-01-13 21:24:50 +01:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($object_phid))
|
2016-01-30 03:44:47 +01:00
|
|
|
->needProjectPHIDs(true)
|
2014-06-25 14:33:32 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
2014-01-13 21:24:50 +01:00
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$object) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$columns = id(new PhabricatorProjectColumnQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withProjectPHIDs(array($project->getPHID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$columns = mpull($columns, null, 'getPHID');
|
2014-03-04 00:58:00 +01:00
|
|
|
$column = idx($columns, $column_phid);
|
|
|
|
if (!$column) {
|
2014-01-13 21:24:50 +01:00
|
|
|
// User is trying to drop this object into a nonexistent column, just kick
|
|
|
|
// them out.
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
Begin lifting column layout logic out of ColumnPositionQuery
Summary:
Ref T10010. This is a precursor to D15171, which I'll eventually rebuild on top of these changes.
Currently, ColumnPositionQuery does a lot of "column layout" stuff that's very similar to the Milestone/Subproject stuff that needs to happen in D15171. The current approach there ended up splitting this layout stuff across two unrelated classes (ColumnPositionQuery + BoardViewController), neither of which is a particularly great place to do it -- the Query is too low-level, and the Controller is too high-level.
Instead, introduce a new "LayoutEngine" which does all this layout stuff. Swap two of the four places that we query this stuff over to the new engine:
- "Project (Column)" on tasks.
- Transaction generation when moving cards.
These sites aren't swapped by this diff, but will be by the next one:
- Actually applying transactions.
- Main layout for boards (this could swap easily now, but applying transactions currently relies on position writes having taken place, so it can't swap until the other one swaps).
Once everything is swapped over, I should be able to add the D15171 logic to LayoutEngine instead of BoardViewController and end up with a cleaner approach overall.
One particularly benefit is that //looking// at a board won't do a bunch of position writes anymore, which wasn't a big deal, but which I was a bit uneasy with.
Test Plan:
- Viewed tasks that are on boards, saw column annotations in project list.
- Moved cards between columns on a board.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10010
Differential Revision: https://secure.phabricator.com/D15174
2016-02-03 18:39:17 +01:00
|
|
|
$engine = id(new PhabricatorBoardLayoutEngine())
|
2014-08-07 00:09:09 +02:00
|
|
|
->setViewer($viewer)
|
Begin lifting column layout logic out of ColumnPositionQuery
Summary:
Ref T10010. This is a precursor to D15171, which I'll eventually rebuild on top of these changes.
Currently, ColumnPositionQuery does a lot of "column layout" stuff that's very similar to the Milestone/Subproject stuff that needs to happen in D15171. The current approach there ended up splitting this layout stuff across two unrelated classes (ColumnPositionQuery + BoardViewController), neither of which is a particularly great place to do it -- the Query is too low-level, and the Controller is too high-level.
Instead, introduce a new "LayoutEngine" which does all this layout stuff. Swap two of the four places that we query this stuff over to the new engine:
- "Project (Column)" on tasks.
- Transaction generation when moving cards.
These sites aren't swapped by this diff, but will be by the next one:
- Actually applying transactions.
- Main layout for boards (this could swap easily now, but applying transactions currently relies on position writes having taken place, so it can't swap until the other one swaps).
Once everything is swapped over, I should be able to add the D15171 logic to LayoutEngine instead of BoardViewController and end up with a cleaner approach overall.
One particularly benefit is that //looking// at a board won't do a bunch of position writes anymore, which wasn't a big deal, but which I was a bit uneasy with.
Test Plan:
- Viewed tasks that are on boards, saw column annotations in project list.
- Moved cards between columns on a board.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10010
Differential Revision: https://secure.phabricator.com/D15174
2016-02-03 18:39:17 +01:00
|
|
|
->setBoardPHIDs(array($board_phid))
|
|
|
|
->setObjectPHIDs(array($object_phid))
|
|
|
|
->executeLayout();
|
|
|
|
|
|
|
|
$columns = $engine->getObjectColumns($board_phid, $object_phid);
|
|
|
|
$old_column_phids = mpull($columns, 'getPHID');
|
2014-01-13 21:24:50 +01:00
|
|
|
|
2014-08-07 00:09:09 +02:00
|
|
|
$xactions = array();
|
2014-01-13 21:24:50 +01:00
|
|
|
|
2014-08-08 17:11:00 +02:00
|
|
|
if ($order == PhabricatorProjectColumn::ORDER_NATURAL) {
|
|
|
|
$order_params = array(
|
|
|
|
'afterPHID' => $after_phid,
|
|
|
|
'beforePHID' => $before_phid,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$order_params = array();
|
|
|
|
}
|
|
|
|
|
2014-03-04 00:58:00 +01:00
|
|
|
$xactions[] = id(new ManiphestTransaction())
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_PROJECT_COLUMN)
|
2014-08-07 00:09:09 +02:00
|
|
|
->setNewValue(
|
|
|
|
array(
|
|
|
|
'columnPHIDs' => array($column->getPHID()),
|
|
|
|
'projectPHID' => $column->getProjectPHID(),
|
2014-08-08 17:11:00 +02:00
|
|
|
) + $order_params)
|
2014-08-07 00:09:09 +02:00
|
|
|
->setOldValue(
|
|
|
|
array(
|
Begin lifting column layout logic out of ColumnPositionQuery
Summary:
Ref T10010. This is a precursor to D15171, which I'll eventually rebuild on top of these changes.
Currently, ColumnPositionQuery does a lot of "column layout" stuff that's very similar to the Milestone/Subproject stuff that needs to happen in D15171. The current approach there ended up splitting this layout stuff across two unrelated classes (ColumnPositionQuery + BoardViewController), neither of which is a particularly great place to do it -- the Query is too low-level, and the Controller is too high-level.
Instead, introduce a new "LayoutEngine" which does all this layout stuff. Swap two of the four places that we query this stuff over to the new engine:
- "Project (Column)" on tasks.
- Transaction generation when moving cards.
These sites aren't swapped by this diff, but will be by the next one:
- Actually applying transactions.
- Main layout for boards (this could swap easily now, but applying transactions currently relies on position writes having taken place, so it can't swap until the other one swaps).
Once everything is swapped over, I should be able to add the D15171 logic to LayoutEngine instead of BoardViewController and end up with a cleaner approach overall.
One particularly benefit is that //looking// at a board won't do a bunch of position writes anymore, which wasn't a big deal, but which I was a bit uneasy with.
Test Plan:
- Viewed tasks that are on boards, saw column annotations in project list.
- Moved cards between columns on a board.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10010
Differential Revision: https://secure.phabricator.com/D15174
2016-02-03 18:39:17 +01:00
|
|
|
'columnPHIDs' => $old_column_phids,
|
2014-08-07 00:09:09 +02:00
|
|
|
'projectPHID' => $column->getProjectPHID(),
|
|
|
|
));
|
2014-01-13 21:24:50 +01:00
|
|
|
|
2014-03-27 18:50:54 +01:00
|
|
|
$task_phids = array();
|
2014-02-27 18:39:59 +01:00
|
|
|
if ($after_phid) {
|
2014-03-27 18:50:54 +01:00
|
|
|
$task_phids[] = $after_phid;
|
|
|
|
}
|
|
|
|
if ($before_phid) {
|
|
|
|
$task_phids[] = $before_phid;
|
|
|
|
}
|
2014-08-07 00:09:09 +02:00
|
|
|
|
2014-08-08 17:11:00 +02:00
|
|
|
if ($task_phids && ($order == PhabricatorProjectColumn::ORDER_PRIORITY)) {
|
2014-03-27 18:50:54 +01:00
|
|
|
$tasks = id(new ManiphestTaskQuery())
|
2014-02-27 18:39:59 +01:00
|
|
|
->setViewer($viewer)
|
2014-03-27 18:50:54 +01:00
|
|
|
->withPHIDs($task_phids)
|
2016-01-30 03:44:47 +01:00
|
|
|
->needProjectPHIDs(true)
|
2014-06-25 14:33:32 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
2014-03-27 18:50:54 +01:00
|
|
|
->execute();
|
|
|
|
if (count($tasks) != count($task_phids)) {
|
2014-02-27 18:39:59 +01:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2014-03-27 18:50:54 +01:00
|
|
|
$tasks = mpull($tasks, null, 'getPHID');
|
|
|
|
|
2015-03-21 01:38:25 +01:00
|
|
|
$try = array(
|
|
|
|
array($after_phid, true),
|
|
|
|
array($before_phid, false),
|
|
|
|
);
|
2014-03-27 18:50:54 +01:00
|
|
|
|
2015-03-21 01:38:25 +01:00
|
|
|
$pri = null;
|
|
|
|
$sub = null;
|
|
|
|
foreach ($try as $spec) {
|
|
|
|
list($task_phid, $is_after) = $spec;
|
|
|
|
$task = idx($tasks, $task_phid);
|
|
|
|
if ($task) {
|
|
|
|
list($pri, $sub) = ManiphestTransactionEditor::getAdjacentSubpriority(
|
|
|
|
$task,
|
|
|
|
$is_after);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-03-27 18:50:54 +01:00
|
|
|
|
2015-03-21 01:38:25 +01:00
|
|
|
if ($pri !== null) {
|
2014-03-27 18:50:54 +01:00
|
|
|
$xactions[] = id(new ManiphestTransaction())
|
2015-03-21 01:38:25 +01:00
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_PRIORITY)
|
|
|
|
->setNewValue($pri);
|
2014-03-27 18:50:54 +01:00
|
|
|
$xactions[] = id(new ManiphestTransaction())
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_SUBPRIORITY)
|
2015-03-21 01:38:25 +01:00
|
|
|
->setNewValue($sub);
|
2014-03-27 18:50:54 +01:00
|
|
|
}
|
2016-02-02 18:53:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$proxy = $column->getProxy();
|
|
|
|
if ($proxy) {
|
|
|
|
// We're moving the task into a subproject or milestone column, so add
|
|
|
|
// the subproject or milestone.
|
|
|
|
$add_projects = array($proxy->getPHID());
|
|
|
|
} else if ($project->getHasSubprojects() || $project->getHasMilestones()) {
|
|
|
|
// We're moving the task into the "Backlog" column on the parent project,
|
|
|
|
// so add the parent explicitly. This gets rid of any subproject or
|
|
|
|
// milestone tags.
|
|
|
|
$add_projects = array($project->getPHID());
|
|
|
|
} else {
|
|
|
|
$add_projects = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($add_projects) {
|
|
|
|
$project_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
|
|
|
|
|
|
|
|
$xactions[] = id(new ManiphestTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
|
|
|
->setMetadataValue('edge:type', $project_type)
|
|
|
|
->setNewValue(
|
|
|
|
array(
|
|
|
|
'+' => array_fuse($add_projects),
|
|
|
|
));
|
|
|
|
}
|
2014-01-13 21:24:50 +01:00
|
|
|
|
2014-03-04 00:58:00 +01:00
|
|
|
$editor = id(new ManiphestTransactionEditor())
|
2014-01-13 21:24:50 +01:00
|
|
|
->setActor($viewer)
|
2014-03-04 00:58:00 +01:00
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSourceFromRequest($request);
|
2014-01-13 21:24:50 +01:00
|
|
|
|
2014-03-04 00:58:00 +01:00
|
|
|
$editor->applyTransactions($object, $xactions);
|
2014-01-13 21:24:50 +01:00
|
|
|
|
2016-02-02 18:53:18 +01:00
|
|
|
// Reload the object so it reflects edits which have been applied.
|
|
|
|
$object = id(new ManiphestTaskQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($object_phid))
|
|
|
|
->needProjectPHIDs(true)
|
|
|
|
->executeOne();
|
|
|
|
|
2016-02-04 02:21:38 +01:00
|
|
|
$except_phids = array($board_phid);
|
|
|
|
if ($project->getHasSubprojects() || $project->getHasMilestones()) {
|
|
|
|
$descendants = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withAncestorProjectPHIDs($except_phids)
|
|
|
|
->execute();
|
|
|
|
foreach ($descendants as $descendant) {
|
|
|
|
$except_phids[] = $descendant->getPHID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-06 22:02:13 +01:00
|
|
|
$rendering_engine = id(new PhabricatorBoardRenderingEngine())
|
2014-03-05 02:01:33 +01:00
|
|
|
->setViewer($viewer)
|
2016-02-06 22:02:13 +01:00
|
|
|
->setObjects(array($object))
|
|
|
|
->setExcludedProjectPHIDs($except_phids);
|
2014-03-05 02:01:33 +01:00
|
|
|
|
2016-02-06 22:02:13 +01:00
|
|
|
$card = $rendering_engine->renderCard($object->getPHID());
|
2016-02-02 15:26:42 +01:00
|
|
|
|
2016-02-06 22:02:13 +01:00
|
|
|
$item = $card->getItem();
|
|
|
|
$item->addClass('phui-workcard');
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent(
|
|
|
|
array(
|
|
|
|
'task' => $item,
|
|
|
|
));
|
2016-02-02 18:53:18 +01:00
|
|
|
}
|
2014-01-13 21:24:50 +01:00
|
|
|
|
2014-01-13 21:24:36 +01:00
|
|
|
}
|