2014-01-13 21:24:36 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectMoveController
|
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
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-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,
|
|
|
|
))
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2014-01-13 21:24:50 +01:00
|
|
|
$object = id(new PhabricatorObjectQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($object_phid))
|
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();
|
|
|
|
}
|
|
|
|
|
2014-08-07 00:09:09 +02:00
|
|
|
$positions = id(new PhabricatorProjectColumnPositionQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withColumns($columns)
|
|
|
|
->withObjectPHIDs(array($object_phid))
|
|
|
|
->execute();
|
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-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(),
|
|
|
|
))
|
|
|
|
->setOldValue(
|
|
|
|
array(
|
|
|
|
'columnPHIDs' => mpull($positions, 'getColumnPHID'),
|
|
|
|
'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-03-27 18:50:54 +01:00
|
|
|
if ($task_phids) {
|
|
|
|
$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)
|
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');
|
|
|
|
|
|
|
|
$a_task = idx($tasks, $after_phid);
|
|
|
|
$b_task = idx($tasks, $before_phid);
|
|
|
|
|
|
|
|
if ($a_task &&
|
|
|
|
(($a_task->getPriority() < $object->getPriority()) ||
|
|
|
|
($a_task->getPriority() == $object->getPriority() &&
|
|
|
|
$a_task->getSubpriority() >= $object->getSubpriority()))) {
|
|
|
|
|
|
|
|
$after_pri = $a_task->getPriority();
|
|
|
|
$after_sub = $a_task->getSubpriority();
|
|
|
|
|
|
|
|
$xactions[] = id(new ManiphestTransaction())
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_SUBPRIORITY)
|
|
|
|
->setNewValue(array(
|
|
|
|
'newPriority' => $after_pri,
|
|
|
|
'newSubpriorityBase' => $after_sub,
|
|
|
|
'direction' => '>'));
|
|
|
|
|
|
|
|
} else if ($b_task &&
|
|
|
|
(($b_task->getPriority() > $object->getPriority()) ||
|
|
|
|
($b_task->getPriority() == $object->getPriority() &&
|
|
|
|
$b_task->getSubpriority() <= $object->getSubpriority()))) {
|
|
|
|
|
|
|
|
$before_pri = $b_task->getPriority();
|
|
|
|
$before_sub = $b_task->getSubpriority();
|
|
|
|
|
|
|
|
$xactions[] = id(new ManiphestTransaction())
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_SUBPRIORITY)
|
|
|
|
->setNewValue(array(
|
|
|
|
'newPriority' => $before_pri,
|
|
|
|
'newSubpriorityBase' => $before_sub,
|
|
|
|
'direction' => '<'));
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2014-03-05 02:01:33 +01:00
|
|
|
$owner = null;
|
|
|
|
if ($object->getOwnerPHID()) {
|
|
|
|
$owner = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($object->getOwnerPHID()))
|
|
|
|
->executeOne();
|
|
|
|
}
|
|
|
|
$card = id(new ProjectBoardTaskCard())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->setTask($object)
|
|
|
|
->setOwner($owner)
|
|
|
|
->setCanEdit(true)
|
|
|
|
->getItem();
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())->setContent(
|
|
|
|
array('task' => $card));
|
|
|
|
}
|
2014-01-13 21:24:50 +01:00
|
|
|
|
2014-01-13 21:24:36 +01:00
|
|
|
}
|