diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6c4b66d962..425a97fb69 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -126,6 +126,7 @@ phutil_register_library_map(array( 'ConduitAPI_maniphest_createtask_Method' => 'applications/conduit/method/maniphest/createtask', 'ConduitAPI_maniphest_find_Method' => 'applications/conduit/method/maniphest/find', 'ConduitAPI_maniphest_info_Method' => 'applications/conduit/method/maniphest/info', + 'ConduitAPI_maniphest_update_Method' => 'applications/conduit/method/maniphest/update', 'ConduitAPI_paste_Method' => 'applications/conduit/method/paste/base', 'ConduitAPI_paste_create_Method' => 'applications/conduit/method/paste/create', 'ConduitAPI_paste_info_Method' => 'applications/conduit/method/paste/info', @@ -880,6 +881,7 @@ phutil_register_library_map(array( 'ConduitAPI_maniphest_createtask_Method' => 'ConduitAPI_maniphest_Method', 'ConduitAPI_maniphest_find_Method' => 'ConduitAPI_maniphest_Method', 'ConduitAPI_maniphest_info_Method' => 'ConduitAPI_maniphest_Method', + 'ConduitAPI_maniphest_update_Method' => 'ConduitAPI_maniphest_Method', 'ConduitAPI_paste_Method' => 'ConduitAPIMethod', 'ConduitAPI_paste_create_Method' => 'ConduitAPI_paste_Method', 'ConduitAPI_paste_info_Method' => 'ConduitAPI_paste_Method', diff --git a/src/applications/conduit/method/maniphest/base/ConduitAPI_maniphest_Method.php b/src/applications/conduit/method/maniphest/base/ConduitAPI_maniphest_Method.php index 81779ea9e5..48c7d947a6 100644 --- a/src/applications/conduit/method/maniphest/base/ConduitAPI_maniphest_Method.php +++ b/src/applications/conduit/method/maniphest/base/ConduitAPI_maniphest_Method.php @@ -1,7 +1,7 @@ getPHID()); } + protected function getTaskFields($is_new) { + $fields = array(); + + if (!$is_new) { + $fields += array( + 'id' => 'optional int', + 'phid' => 'optional int', + ); + } + + $fields += array( + 'title' => $is_new ? 'required string' : 'optional string', + 'description' => 'optional string', + 'ownerPHID' => 'optional phid', + 'ccPHIDs' => 'optional list', + 'priority' => 'optional int', + 'projectPHIDs' => 'optional list', + 'filePHIDs' => 'optional list', + 'auxiliary' => 'optional dict', + ); + + if (!$is_new) { + $fields += array( + 'status' => 'optional int', + 'comments' => 'optional string', + ); + } + + return $fields; + } + + protected function applyRequest( + ManiphestTask $task, + ConduitAPIRequest $request, + $is_new) { + + $changes = array(); + + if ($is_new) { + $task->setTitle((string)$request->getValue('title')); + $task->setDescription((string)$request->getValue('description')); + $changes[ManiphestTransactionType::TYPE_STATUS] = + ManiphestTaskStatus::STATUS_OPEN; + } else { + + $comments = $request->getValue('comments'); + if (!$is_new && $comments !== null) { + $changes[ManiphestTransactionType::TYPE_NONE] = null; + } + + $title = $request->getValue('title'); + if ($title !== null) { + $changes[ManiphestTransactionType::TYPE_TITLE] = $title; + } + + $desc = $request->getValue('description'); + if ($desc !== null) { + $changes[ManiphestTransactionType::TYPE_DESCRIPTION] = $desc; + } + + $status = $request->getValue('status'); + if ($status !== null) { + $changes[ManiphestTransactionType::TYPE_STATUS] = $status; + } + } + + $priority = $request->getValue('priority'); + if ($priority !== null) { + $changes[ManiphestTransactionType::TYPE_PRIORITY] = $priority; + } + + $owner_phid = $request->getValue('ownerPHID'); + if ($owner_phid !== null) { + $changes[ManiphestTransactionType::TYPE_OWNER] = $owner_phid; + } + + $ccs = $request->getValue('ccPHIDs'); + if ($ccs !== null) { + $changes[ManiphestTransactionType::TYPE_CCS] = $ccs; + } + + $project_phids = $request->getValue('projectPHIDs'); + if ($project_phids !== null) { + $changes[ManiphestTransactionType::TYPE_PROJECTS] = $project_phids; + } + + $file_phids = $request->getValue('filePHIDs'); + if ($file_phids !== null) { + $file_map = array_fill_keys($file_phids, true); + $attached = $task->getAttached(); + $attached[PhabricatorPHIDConstants::PHID_TYPE_FILE] = $file_map; + + $changes[ManiphestTransactionType::TYPE_ATTACH] = $attached; + } + + $content_source = PhabricatorContentSource::newForSource( + PhabricatorContentSource::SOURCE_CONDUIT, + array()); + + $template = new ManiphestTransaction(); + $template->setContentSource($content_source); + $template->setAuthorPHID($request->getUser()->getPHID()); + + $transactions = array(); + foreach ($changes as $type => $value) { + $transaction = clone $template; + $transaction->setTransactionType($type); + $transaction->setNewValue($value); + if ($type == ManiphestTransactionType::TYPE_NONE) { + $transaction->setComments($comments); + } + $transactions[] = $transaction; + } + + $auxiliary = $request->getValue('auxiliary'); + if ($auxiliary) { + $task->loadAndAttachAuxiliaryAttributes(); + foreach ($auxiliary as $aux_key => $aux_value) { + $transaction = clone $template; + $transaction->setTransactionType( + ManiphestTransactionType::TYPE_AUXILIARY); + $transaction->setMetadataValue('aux:key', $aux_key); + $transaction->setNewValue($aux_value); + $transactions[] = $transaction; + } + } + + $event = new PhabricatorEvent( + PhabricatorEventType::TYPE_MANIPHEST_WILLEDITTASK, + array( + 'task' => $task, + 'new' => $is_new, + 'transactions' => $transactions, + )); + $event->setUser($request->getUser()); + $event->setConduitRequest($request); + PhutilEventEngine::dispatchEvent($event); + + $task = $event->getValue('task'); + $transactions = $event->getValue('transactions'); + + $editor = new ManiphestTransactionEditor(); + $editor->applyTransactions($task, $transactions); + } + protected function buildTaskInfoDictionaries(array $tasks) { if (!$tasks) { return array(); diff --git a/src/applications/conduit/method/maniphest/base/__init__.php b/src/applications/conduit/method/maniphest/base/__init__.php index f32f22aff8..31771cefab 100644 --- a/src/applications/conduit/method/maniphest/base/__init__.php +++ b/src/applications/conduit/method/maniphest/base/__init__.php @@ -8,9 +8,18 @@ phutil_require_module('phabricator', 'applications/conduit/method/base'); phutil_require_module('phabricator', 'applications/maniphest/constants/priority'); +phutil_require_module('phabricator', 'applications/maniphest/constants/status'); +phutil_require_module('phabricator', 'applications/maniphest/constants/transactiontype'); +phutil_require_module('phabricator', 'applications/maniphest/editor/transaction'); phutil_require_module('phabricator', 'applications/maniphest/storage/auxiliary'); +phutil_require_module('phabricator', 'applications/maniphest/storage/transaction'); +phutil_require_module('phabricator', 'applications/metamta/contentsource/source'); +phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'infrastructure/env'); +phutil_require_module('phabricator', 'infrastructure/events/constant/type'); +phutil_require_module('phabricator', 'infrastructure/events/event'); +phutil_require_module('phutil', 'events/engine'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/conduit/method/maniphest/createtask/ConduitAPI_maniphest_createtask_Method.php b/src/applications/conduit/method/maniphest/createtask/ConduitAPI_maniphest_createtask_Method.php index f19f635e08..b8f988fdd2 100644 --- a/src/applications/conduit/method/maniphest/createtask/ConduitAPI_maniphest_createtask_Method.php +++ b/src/applications/conduit/method/maniphest/createtask/ConduitAPI_maniphest_createtask_Method.php @@ -1,7 +1,7 @@ 'required string', - 'description' => 'optional string', - 'ownerPHID' => 'optional phid', - 'ccPHIDs' => 'optional list', - 'priority' => 'optional int', - 'projectPHIDs' => 'optional list', - 'filePHIDs' => 'optional list', - ); + return $this->getTaskFields($is_new = true); } public function defineReturnType() { @@ -52,73 +44,7 @@ final class ConduitAPI_maniphest_createtask_Method $task->setPriority(ManiphestTaskPriority::PRIORITY_TRIAGE); $task->setAuthorPHID($request->getUser()->getPHID()); - $task->setTitle((string)$request->getValue('title')); - $task->setDescription((string)$request->getValue('description')); - - $changes = array(); - $changes[ManiphestTransactionType::TYPE_STATUS] = - ManiphestTaskStatus::STATUS_OPEN; - - $priority = $request->getValue('priority'); - if ($priority !== null) { - $changes[ManiphestTransactionType::TYPE_PRIORITY] = $priority; - } - - $owner_phid = $request->getValue('ownerPHID'); - if ($owner_phid !== null) { - $changes[ManiphestTransactionType::TYPE_OWNER] = $owner_phid; - } - - $ccs = $request->getValue('ccPHIDs'); - if ($ccs !== null) { - $changes[ManiphestTransactionType::TYPE_CCS] = $ccs; - } - - $project_phids = $request->getValue('projectPHIDs'); - if ($project_phids !== null) { - $changes[ManiphestTransactionType::TYPE_PROJECTS] = $project_phids; - } - - $file_phids = $request->getValue('filePHIDs'); - if ($file_phids !== null) { - $file_map = array_fill_keys($file_phids, true); - $changes[ManiphestTransactionType::TYPE_ATTACH] = array( - PhabricatorPHIDConstants::PHID_TYPE_FILE => $file_map, - ); - } - - $content_source = PhabricatorContentSource::newForSource( - PhabricatorContentSource::SOURCE_CONDUIT, - array()); - - $template = new ManiphestTransaction(); - $template->setContentSource($content_source); - $template->setAuthorPHID($request->getUser()->getPHID()); - - $transactions = array(); - foreach ($changes as $type => $value) { - $transaction = clone $template; - $transaction->setTransactionType($type); - $transaction->setNewValue($value); - $transactions[] = $transaction; - } - - $event = new PhabricatorEvent( - PhabricatorEventType::TYPE_MANIPHEST_WILLEDITTASK, - array( - 'task' => $task, - 'new' => true, - 'transactions' => $transactions, - )); - $event->setUser($request->getUser()); - $event->setConduitRequest($request); - PhutilEventEngine::dispatchEvent($event); - - $task = $event->getValue('task'); - $transactions = $event->getValue('transactions'); - - $editor = new ManiphestTransactionEditor(); - $editor->applyTransactions($task, $transactions); + $this->applyRequest($task, $request, $is_new = true); return $this->buildTaskInfoDictionary($task); } diff --git a/src/applications/conduit/method/maniphest/createtask/__init__.php b/src/applications/conduit/method/maniphest/createtask/__init__.php index ecd820aefb..977d7d7c84 100644 --- a/src/applications/conduit/method/maniphest/createtask/__init__.php +++ b/src/applications/conduit/method/maniphest/createtask/__init__.php @@ -8,17 +8,7 @@ phutil_require_module('phabricator', 'applications/conduit/method/maniphest/base'); phutil_require_module('phabricator', 'applications/maniphest/constants/priority'); -phutil_require_module('phabricator', 'applications/maniphest/constants/status'); -phutil_require_module('phabricator', 'applications/maniphest/constants/transactiontype'); -phutil_require_module('phabricator', 'applications/maniphest/editor/transaction'); phutil_require_module('phabricator', 'applications/maniphest/storage/task'); -phutil_require_module('phabricator', 'applications/maniphest/storage/transaction'); -phutil_require_module('phabricator', 'applications/metamta/contentsource/source'); -phutil_require_module('phabricator', 'applications/phid/constants'); -phutil_require_module('phabricator', 'infrastructure/events/constant/type'); -phutil_require_module('phabricator', 'infrastructure/events/event'); - -phutil_require_module('phutil', 'events/engine'); phutil_require_source('ConduitAPI_maniphest_createtask_Method.php'); diff --git a/src/applications/conduit/method/maniphest/update/ConduitAPI_maniphest_update_Method.php b/src/applications/conduit/method/maniphest/update/ConduitAPI_maniphest_update_Method.php new file mode 100644 index 0000000000..4e8bae0d0e --- /dev/null +++ b/src/applications/conduit/method/maniphest/update/ConduitAPI_maniphest_update_Method.php @@ -0,0 +1,68 @@ +getTaskFields($is_new = false); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + public function defineErrorTypes() { + return array( + 'ERR-BAD-TASK' => 'No such task exists.', + ); + } + + protected function execute(ConduitAPIRequest $request) { + $id = $request->getValue('id'); + $phid = $request->getValue('phid'); + + if (($id && $phid) || (!$id && !$phid)) { + throw new Exception("Specify exactly one of 'id' and 'phid'."); + } + + if ($id) { + $task = id(new ManiphestTask())->load($id); + } else { + $task = id(new ManiphestTask())->loadOneWhere( + 'phid = %s', + $phid); + } + + if (!$task) { + throw new ConduitException('ERR-BAD-TASK'); + } + + $this->applyRequest($task, $request, $is_new = false); + + return $this->buildTaskInfoDictionary($task); + } + +} diff --git a/src/applications/conduit/method/maniphest/update/__init__.php b/src/applications/conduit/method/maniphest/update/__init__.php new file mode 100644 index 0000000000..58d05b245e --- /dev/null +++ b/src/applications/conduit/method/maniphest/update/__init__.php @@ -0,0 +1,16 @@ +aphrontRequest; } - public function setConduitRequest(ConduitRequest $conduit_request) { + public function setConduitRequest(ConduitAPIRequest $conduit_request) { $this->conduitRequest = $conduit_request; return $this; }