[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ManiphestTransactionPreviewController extends ManiphestController { 4 5 private $id; 6 7 public function willProcessRequest(array $data) { 8 $this->id = $data['id']; 9 } 10 11 public function processRequest() { 12 13 $request = $this->getRequest(); 14 $user = $request->getUser(); 15 16 $comments = $request->getStr('comments'); 17 18 $task = id(new ManiphestTaskQuery()) 19 ->setViewer($user) 20 ->withIDs(array($this->id)) 21 ->executeOne(); 22 if (!$task) { 23 return new Aphront404Response(); 24 } 25 26 id(new PhabricatorDraft()) 27 ->setAuthorPHID($user->getPHID()) 28 ->setDraftKey($task->getPHID()) 29 ->setDraft($comments) 30 ->replaceOrDelete(); 31 32 $action = $request->getStr('action'); 33 34 $transaction = new ManiphestTransaction(); 35 $transaction->setAuthorPHID($user->getPHID()); 36 $transaction->setTransactionType($action); 37 38 // This should really be split into a separate transaction, but it should 39 // all come out in the wash once we fully move to modern stuff. 40 $transaction->attachComment( 41 id(new ManiphestTransactionComment()) 42 ->setContent($comments)); 43 44 $value = $request->getStr('value'); 45 // grab phids for handles and set transaction values based on action and 46 // value (empty or control-specific format) coming in from the wire 47 switch ($action) { 48 case ManiphestTransaction::TYPE_PRIORITY: 49 $transaction->setOldValue($task->getPriority()); 50 $transaction->setNewValue($value); 51 break; 52 case ManiphestTransaction::TYPE_OWNER: 53 if ($value) { 54 $value = current(json_decode($value)); 55 $phids = array($value); 56 } else { 57 $phids = array(); 58 } 59 $transaction->setNewValue($value); 60 break; 61 case ManiphestTransaction::TYPE_CCS: 62 if ($value) { 63 $value = json_decode($value); 64 } 65 if (!$value) { 66 $value = array(); 67 } 68 $phids = $value; 69 70 foreach ($task->getCCPHIDs() as $cc_phid) { 71 $phids[] = $cc_phid; 72 $value[] = $cc_phid; 73 } 74 75 $transaction->setOldValue($task->getCCPHIDs()); 76 $transaction->setNewValue($value); 77 break; 78 case ManiphestTransaction::TYPE_PROJECTS: 79 if ($value) { 80 $value = json_decode($value); 81 } 82 if (!$value) { 83 $value = array(); 84 } 85 86 $phids = array(); 87 $value = array_fuse($value); 88 foreach ($value as $project_phid) { 89 $phids[] = $project_phid; 90 $value[$project_phid] = array('dst' => $project_phid); 91 } 92 93 $project_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 94 $transaction 95 ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 96 ->setMetadataValue('edge:type', $project_type) 97 ->setOldValue(array()) 98 ->setNewValue($value); 99 break; 100 case ManiphestTransaction::TYPE_STATUS: 101 $phids = array(); 102 $transaction->setOldValue($task->getStatus()); 103 $transaction->setNewValue($value); 104 break; 105 default: 106 $phids = array(); 107 $transaction->setNewValue($value); 108 break; 109 } 110 $phids[] = $user->getPHID(); 111 112 $handles = $this->loadViewerHandles($phids); 113 114 $transactions = array(); 115 $transactions[] = $transaction; 116 117 $engine = new PhabricatorMarkupEngine(); 118 $engine->setViewer($user); 119 if ($transaction->hasComment()) { 120 $engine->addObject( 121 $transaction->getComment(), 122 PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); 123 } 124 $engine->process(); 125 126 $transaction->setHandles($handles); 127 128 $view = id(new PhabricatorApplicationTransactionView()) 129 ->setUser($user) 130 ->setTransactions($transactions) 131 ->setIsPreview(true); 132 133 return id(new AphrontAjaxResponse()) 134 ->setContent((string)phutil_implode_html('', $view->buildEvents())); 135 } 136 137 }
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 |