Differential D20248 Diff 48377 src/applications/project/controller/PhabricatorProjectMoveController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/controller/PhabricatorProjectMoveController.php
| Show All 9 Lines | public function handleRequest(AphrontRequest $request) { | ||||
| $request->validateCSRF(); | $request->validateCSRF(); | ||||
| $column_phid = $request->getStr('columnPHID'); | $column_phid = $request->getStr('columnPHID'); | ||||
| $object_phid = $request->getStr('objectPHID'); | $object_phid = $request->getStr('objectPHID'); | ||||
| $after_phid = $request->getStr('afterPHID'); | $after_phid = $request->getStr('afterPHID'); | ||||
| $before_phid = $request->getStr('beforePHID'); | $before_phid = $request->getStr('beforePHID'); | ||||
| $order = $request->getStr('order', PhabricatorProjectColumn::DEFAULT_ORDER); | $order = $request->getStr('order', PhabricatorProjectColumn::DEFAULT_ORDER); | ||||
| $edit_header = null; | |||||
| $raw_header = $request->getStr('header'); | |||||
| if (strlen($raw_header)) { | |||||
| $edit_header = phutil_json_decode($raw_header); | |||||
| } else { | |||||
| $edit_header = array(); | |||||
| } | |||||
| $project = id(new PhabricatorProjectQuery()) | $project = id(new PhabricatorProjectQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->requireCapabilities( | ->requireCapabilities( | ||||
| array( | array( | ||||
| PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
| )) | )) | ||||
| ->withIDs(array($id)) | ->withIDs(array($id)) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | $xactions[] = id(new ManiphestTransaction()) | ||||
| ->setNewValue( | ->setNewValue( | ||||
| array( | array( | ||||
| array( | array( | ||||
| 'columnPHID' => $column->getPHID(), | 'columnPHID' => $column->getPHID(), | ||||
| ) + $order_params, | ) + $order_params, | ||||
| )); | )); | ||||
| if ($order == PhabricatorProjectColumn::ORDER_PRIORITY) { | if ($order == PhabricatorProjectColumn::ORDER_PRIORITY) { | ||||
| $header_priority = idx( | |||||
| $edit_header, | |||||
| PhabricatorProjectColumn::ORDER_PRIORITY); | |||||
| $priority_xactions = $this->getPriorityTransactions( | $priority_xactions = $this->getPriorityTransactions( | ||||
| $object, | $object, | ||||
| $after_phid, | $after_phid, | ||||
| $before_phid); | $before_phid, | ||||
| $header_priority); | |||||
| foreach ($priority_xactions as $xaction) { | foreach ($priority_xactions as $xaction) { | ||||
| $xactions[] = $xaction; | $xactions[] = $xaction; | ||||
| } | } | ||||
| } | } | ||||
| $editor = id(new ManiphestTransactionEditor()) | $editor = id(new ManiphestTransactionEditor()) | ||||
| ->setActor($viewer) | ->setActor($viewer) | ||||
| ->setContinueOnMissingFields(true) | ->setContinueOnMissingFields(true) | ||||
| ->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
| ->setContentSourceFromRequest($request); | ->setContentSourceFromRequest($request); | ||||
| $editor->applyTransactions($object, $xactions); | $editor->applyTransactions($object, $xactions); | ||||
| return $this->newCardResponse($board_phid, $object_phid); | return $this->newCardResponse($board_phid, $object_phid); | ||||
| } | } | ||||
| private function getPriorityTransactions( | private function getPriorityTransactions( | ||||
| ManiphestTask $task, | ManiphestTask $task, | ||||
| $after_phid, | $after_phid, | ||||
| $before_phid) { | $before_phid, | ||||
| $header_priority) { | |||||
| $xactions = array(); | |||||
| $must_move = false; | |||||
| if ($header_priority !== null) { | |||||
| if ($task->getPriority() !== $header_priority) { | |||||
| $task = id(clone $task) | |||||
| ->setPriority($header_priority); | |||||
| $keyword_map = ManiphestTaskPriority::getTaskPriorityKeywordsMap(); | |||||
| $keyword = head(idx($keyword_map, $header_priority)); | |||||
| $xactions[] = id(new ManiphestTransaction()) | |||||
| ->setTransactionType( | |||||
| ManiphestTaskPriorityTransaction::TRANSACTIONTYPE) | |||||
| ->setNewValue($keyword); | |||||
| $must_move = true; | |||||
| } | |||||
| } | |||||
| list($after_task, $before_task) = $this->loadPriorityTasks( | list($after_task, $before_task) = $this->loadPriorityTasks( | ||||
| $after_phid, | $after_phid, | ||||
| $before_phid); | $before_phid); | ||||
| $must_move = false; | |||||
| if ($after_task && !$task->isLowerPriorityThan($after_task)) { | if ($after_task && !$task->isLowerPriorityThan($after_task)) { | ||||
| $must_move = true; | $must_move = true; | ||||
| } | } | ||||
| if ($before_task && !$task->isHigherPriorityThan($before_task)) { | if ($before_task && !$task->isHigherPriorityThan($before_task)) { | ||||
| $must_move = true; | $must_move = true; | ||||
| } | } | ||||
| // The move doesn't require a priority change to be valid, so don't | // The move doesn't require a subpriority change to be valid, so don't | ||||
| // change the priority since we are not being forced to. | // change the subpriority since we are not being forced to. | ||||
| if (!$must_move) { | if (!$must_move) { | ||||
| return array(); | return $xactions; | ||||
| } | } | ||||
| $try = array( | $try = array( | ||||
| array($after_task, true), | array($after_task, true), | ||||
| array($before_task, false), | array($before_task, false), | ||||
| ); | ); | ||||
| $pri = null; | $pri = null; | ||||
| $sub = null; | $sub = null; | ||||
| foreach ($try as $spec) { | foreach ($try as $spec) { | ||||
| list($task, $is_after) = $spec; | list($nearby_task, $is_after) = $spec; | ||||
| if (!$task) { | if (!$nearby_task) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| list($pri, $sub) = ManiphestTransactionEditor::getAdjacentSubpriority( | list($pri, $sub) = ManiphestTransactionEditor::getAdjacentSubpriority( | ||||
| $task, | $nearby_task, | ||||
| $is_after); | $is_after); | ||||
| // If we drag under a "Low" header between a "Normal" task and a "Low" | |||||
| // task, we don't want to accept a subpriority assignment which changes | |||||
| // our priority to "Normal". Only accept a subpriority that keeps us in | |||||
| // the right primary priority. | |||||
| if ($header_priority !== null) { | |||||
| if ($pri !== $header_priority) { | |||||
| continue; | |||||
| } | |||||
| } | |||||
| // If we find a priority on the first try, don't keep going. | // If we find a priority on the first try, don't keep going. | ||||
| break; | break; | ||||
| } | } | ||||
| if ($pri !== null) { | |||||
| if ($header_priority === null) { | |||||
| $keyword_map = ManiphestTaskPriority::getTaskPriorityKeywordsMap(); | $keyword_map = ManiphestTaskPriority::getTaskPriorityKeywordsMap(); | ||||
| $keyword = head(idx($keyword_map, $pri)); | $keyword = head(idx($keyword_map, $pri)); | ||||
| $xactions = array(); | |||||
| if ($pri !== null) { | |||||
| $xactions[] = id(new ManiphestTransaction()) | $xactions[] = id(new ManiphestTransaction()) | ||||
| ->setTransactionType(ManiphestTaskPriorityTransaction::TRANSACTIONTYPE) | ->setTransactionType( | ||||
| ManiphestTaskPriorityTransaction::TRANSACTIONTYPE) | |||||
| ->setNewValue($keyword); | ->setNewValue($keyword); | ||||
| } | |||||
| $xactions[] = id(new ManiphestTransaction()) | $xactions[] = id(new ManiphestTransaction()) | ||||
| ->setTransactionType( | ->setTransactionType( | ||||
| ManiphestTaskSubpriorityTransaction::TRANSACTIONTYPE) | ManiphestTaskSubpriorityTransaction::TRANSACTIONTYPE) | ||||
| ->setNewValue($sub); | ->setNewValue($sub); | ||||
| } | } | ||||
| return $xactions; | return $xactions; | ||||
| } | } | ||||
| Show All 39 Lines | |||||