[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorProjectMoveController 4 extends PhabricatorProjectController { 5 6 private $id; 7 8 public function willProcessRequest(array $data) { 9 $this->id = $data['id']; 10 } 11 12 public function processRequest() { 13 $request = $this->getRequest(); 14 $viewer = $request->getUser(); 15 16 $column_phid = $request->getStr('columnPHID'); 17 $object_phid = $request->getStr('objectPHID'); 18 $after_phid = $request->getStr('afterPHID'); 19 $before_phid = $request->getStr('beforePHID'); 20 $order = $request->getStr('order', PhabricatorProjectColumn::DEFAULT_ORDER); 21 22 23 $project = id(new PhabricatorProjectQuery()) 24 ->setViewer($viewer) 25 ->requireCapabilities( 26 array( 27 PhabricatorPolicyCapability::CAN_VIEW, 28 )) 29 ->withIDs(array($this->id)) 30 ->executeOne(); 31 if (!$project) { 32 return new Aphront404Response(); 33 } 34 35 $object = id(new PhabricatorObjectQuery()) 36 ->setViewer($viewer) 37 ->withPHIDs(array($object_phid)) 38 ->requireCapabilities( 39 array( 40 PhabricatorPolicyCapability::CAN_VIEW, 41 PhabricatorPolicyCapability::CAN_EDIT, 42 )) 43 ->executeOne(); 44 45 if (!$object) { 46 return new Aphront404Response(); 47 } 48 49 $columns = id(new PhabricatorProjectColumnQuery()) 50 ->setViewer($viewer) 51 ->withProjectPHIDs(array($project->getPHID())) 52 ->execute(); 53 54 $columns = mpull($columns, null, 'getPHID'); 55 $column = idx($columns, $column_phid); 56 if (!$column) { 57 // User is trying to drop this object into a nonexistent column, just kick 58 // them out. 59 return new Aphront404Response(); 60 } 61 62 $positions = id(new PhabricatorProjectColumnPositionQuery()) 63 ->setViewer($viewer) 64 ->withColumns($columns) 65 ->withObjectPHIDs(array($object_phid)) 66 ->execute(); 67 68 $xactions = array(); 69 70 if ($order == PhabricatorProjectColumn::ORDER_NATURAL) { 71 $order_params = array( 72 'afterPHID' => $after_phid, 73 'beforePHID' => $before_phid, 74 ); 75 } else { 76 $order_params = array(); 77 } 78 79 $xactions[] = id(new ManiphestTransaction()) 80 ->setTransactionType(ManiphestTransaction::TYPE_PROJECT_COLUMN) 81 ->setNewValue( 82 array( 83 'columnPHIDs' => array($column->getPHID()), 84 'projectPHID' => $column->getProjectPHID(), 85 ) + $order_params) 86 ->setOldValue( 87 array( 88 'columnPHIDs' => mpull($positions, 'getColumnPHID'), 89 'projectPHID' => $column->getProjectPHID(), 90 )); 91 92 $task_phids = array(); 93 if ($after_phid) { 94 $task_phids[] = $after_phid; 95 } 96 if ($before_phid) { 97 $task_phids[] = $before_phid; 98 } 99 100 if ($task_phids && ($order == PhabricatorProjectColumn::ORDER_PRIORITY)) { 101 $tasks = id(new ManiphestTaskQuery()) 102 ->setViewer($viewer) 103 ->withPHIDs($task_phids) 104 ->requireCapabilities( 105 array( 106 PhabricatorPolicyCapability::CAN_VIEW, 107 PhabricatorPolicyCapability::CAN_EDIT, 108 )) 109 ->execute(); 110 if (count($tasks) != count($task_phids)) { 111 return new Aphront404Response(); 112 } 113 $tasks = mpull($tasks, null, 'getPHID'); 114 115 $a_task = idx($tasks, $after_phid); 116 $b_task = idx($tasks, $before_phid); 117 118 if ($a_task && 119 (($a_task->getPriority() < $object->getPriority()) || 120 ($a_task->getPriority() == $object->getPriority() && 121 $a_task->getSubpriority() >= $object->getSubpriority()))) { 122 123 $after_pri = $a_task->getPriority(); 124 $after_sub = $a_task->getSubpriority(); 125 126 $xactions[] = id(new ManiphestTransaction()) 127 ->setTransactionType(ManiphestTransaction::TYPE_SUBPRIORITY) 128 ->setNewValue(array( 129 'newPriority' => $after_pri, 130 'newSubpriorityBase' => $after_sub, 131 'direction' => '>', 132 )); 133 134 } else if ($b_task && 135 (($b_task->getPriority() > $object->getPriority()) || 136 ($b_task->getPriority() == $object->getPriority() && 137 $b_task->getSubpriority() <= $object->getSubpriority()))) { 138 139 $before_pri = $b_task->getPriority(); 140 $before_sub = $b_task->getSubpriority(); 141 142 $xactions[] = id(new ManiphestTransaction()) 143 ->setTransactionType(ManiphestTransaction::TYPE_SUBPRIORITY) 144 ->setNewValue(array( 145 'newPriority' => $before_pri, 146 'newSubpriorityBase' => $before_sub, 147 'direction' => '<', 148 )); 149 } 150 } 151 152 $editor = id(new ManiphestTransactionEditor()) 153 ->setActor($viewer) 154 ->setContinueOnMissingFields(true) 155 ->setContinueOnNoEffect(true) 156 ->setContentSourceFromRequest($request); 157 158 $editor->applyTransactions($object, $xactions); 159 160 $owner = null; 161 if ($object->getOwnerPHID()) { 162 $owner = id(new PhabricatorHandleQuery()) 163 ->setViewer($viewer) 164 ->withPHIDs(array($object->getOwnerPHID())) 165 ->executeOne(); 166 } 167 $card = id(new ProjectBoardTaskCard()) 168 ->setViewer($viewer) 169 ->setTask($object) 170 ->setOwner($owner) 171 ->setCanEdit(true) 172 ->getItem(); 173 174 return id(new AphrontAjaxResponse())->setContent( 175 array('task' => $card)); 176 } 177 178 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |