From 69523d30cca6ea956ce399308ac1f2589796954f Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 23 Sep 2013 14:31:47 -0700 Subject: [PATCH] Add new-style transaction editor to Maniphest and switch priority edits to it Summary: Ref T2217. All the reads route through new code already, start swapping writes over. This is the simplest writer, used when the user drag-and-drops stuff on the task list. Test Plan: Dragged and dropped stuff across priorities. Got a transaction and some email. Verified the email and transaction looked OK, threaded properly, etc. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2217 Differential Revision: https://secure.phabricator.com/D7080 --- src/__phutil_library_map__.php | 2 + .../ManiphestSubpriorityController.php | 31 ++--- .../editor/ManiphestTransactionEditorPro.php | 113 ++++++++++++++++++ ...habricatorApplicationTransactionEditor.php | 6 +- 4 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 src/applications/maniphest/editor/ManiphestTransactionEditorPro.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3adcbb6c32..aa5ffffb08 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -734,6 +734,7 @@ phutil_register_library_map(array( 'ManiphestTransaction' => 'applications/maniphest/storage/ManiphestTransaction.php', 'ManiphestTransactionComment' => 'applications/maniphest/storage/ManiphestTransactionComment.php', 'ManiphestTransactionEditor' => 'applications/maniphest/editor/ManiphestTransactionEditor.php', + 'ManiphestTransactionEditorPro' => 'applications/maniphest/editor/ManiphestTransactionEditorPro.php', 'ManiphestTransactionPreviewController' => 'applications/maniphest/controller/ManiphestTransactionPreviewController.php', 'ManiphestTransactionPro' => 'applications/maniphest/storage/ManiphestTransactionPro.php', 'ManiphestTransactionQuery' => 'applications/maniphest/query/ManiphestTransactionQuery.php', @@ -2824,6 +2825,7 @@ phutil_register_library_map(array( 'ManiphestTaskSubscriber' => 'ManiphestDAO', 'ManiphestTransactionComment' => 'PhabricatorApplicationTransactionComment', 'ManiphestTransactionEditor' => 'PhabricatorEditor', + 'ManiphestTransactionEditorPro' => 'PhabricatorApplicationTransactionEditor', 'ManiphestTransactionPreviewController' => 'ManiphestController', 'ManiphestTransactionPro' => 'PhabricatorApplicationTransaction', 'ManiphestTransactionQuery' => 'PhabricatorApplicationTransactionQuery', diff --git a/src/applications/maniphest/controller/ManiphestSubpriorityController.php b/src/applications/maniphest/controller/ManiphestSubpriorityController.php index 4208dacce8..d1e707924f 100644 --- a/src/applications/maniphest/controller/ManiphestSubpriorityController.php +++ b/src/applications/maniphest/controller/ManiphestSubpriorityController.php @@ -34,22 +34,23 @@ final class ManiphestSubpriorityController extends ManiphestController { $after_pri, $after_sub); - if ($after_pri != $task->getPriority()) { - $xaction = new ManiphestTransaction(); - $xaction->setAuthorPHID($request->getUser()->getPHID()); - - // TODO: Content source? - - $xaction->setTransactionType(ManiphestTransactionType::TYPE_PRIORITY); - $xaction->setNewValue($after_pri); - - $editor = new ManiphestTransactionEditor(); - $editor->setActor($request->getUser()); - $editor->applyTransactions($task, array($xaction)); - } - $task->setSubpriority($new_sub); - $task->save(); + + if ($after_pri != $task->getPriority()) { + $xactions = array(); + $xactions[] = id(new ManiphestTransactionPro()) + ->setTransactionType(ManiphestTransactionPro::TYPE_PRIORITY) + ->setNewValue($after_pri); + + $editor = id(new ManiphestTransactionEditorPro()) + ->setActor($user) + ->setContinueOnNoEffect($request->isContinueRequest()) + ->setContentSourceFromRequest($request); + + $editor->applyTransactions($task, $xactions); + } else { + $task->save(); + } return id(new AphrontAjaxResponse())->setContent( array( diff --git a/src/applications/maniphest/editor/ManiphestTransactionEditorPro.php b/src/applications/maniphest/editor/ManiphestTransactionEditorPro.php new file mode 100644 index 0000000000..cea7325f87 --- /dev/null +++ b/src/applications/maniphest/editor/ManiphestTransactionEditorPro.php @@ -0,0 +1,113 @@ +getTransactionType()) { + case ManiphestTransactionPro::TYPE_PRIORITY: + return $object->getPriority(); + } + + } + + protected function getCustomTransactionNewValue( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + + switch ($xaction->getTransactionType()) { + case ManiphestTransactionPro::TYPE_PRIORITY: + return $xaction->getNewValue(); + } + + } + + protected function applyCustomInternalTransaction( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + + switch ($xaction->getTransactionType()) { + case ManiphestTransactionPro::TYPE_PRIORITY: + return $object->setPriority($xaction->getNewValue()); + } + + } + + protected function applyCustomExternalTransaction( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + } + + protected function shouldSendMail( + PhabricatorLiskDAO $object, + array $xactions) { + return true; + } + + protected function getMailSubjectPrefix() { + return PhabricatorEnv::getEnvConfig('metamta.maniphest.subject-prefix'); + } + + protected function getMailThreadID(PhabricatorLiskDAO $object) { + return 'maniphest-task-'.$object->getPHID(); + } + + protected function getMailTo(PhabricatorLiskDAO $object) { + return array( + $object->getOwnerPHID(), + $this->requireActor()->getPHID(), + ); + } + + protected function getMailCC(PhabricatorLiskDAO $object) { + return $object->getCCPHIDs(); + } + + protected function buildReplyHandler(PhabricatorLiskDAO $object) { + return id(new ManiphestReplyHandler()) + ->setMailReceiver($object); + } + + protected function buildMailTemplate(PhabricatorLiskDAO $object) { + $id = $object->getID(); + $title = $object->getTitle(); + + return id(new PhabricatorMetaMTAMail()) + ->setSubject("T{$id}: {$title}") + ->addHeader('Thread-Topic', "T{$id}: ".$object->getOriginalTitle()); + } + + protected function buildMailBody( + PhabricatorLiskDAO $object, + array $xactions) { + + $body = parent::buildMailBody($object, $xactions); + + $body->addTextSection( + pht('TASK DETAIL'), + PhabricatorEnv::getProductionURI('/T'.$object->getID())); + + return $body; + } + + protected function supportsFeed() { + return true; + } + + protected function supportsSearch() { + return true; + } + +} diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php index cb2b4dbeb6..38fb82a17a 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -1176,7 +1176,7 @@ abstract class PhabricatorApplicationTransactionEditor ->setFrom($this->requireActor()->getPHID()) ->setSubjectPrefix($this->getMailSubjectPrefix()) ->setVarySubjectPrefix('['.$action.']') - ->setThreadID($object->getPHID(), $this->getIsNewObject()) + ->setThreadID($this->getMailThreadID($object), $this->getIsNewObject()) ->setRelatedPHID($object->getPHID()) ->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs()) ->setMailTags($mail_tags) @@ -1204,6 +1204,10 @@ abstract class PhabricatorApplicationTransactionEditor return $template; } + protected function getMailThreadID(PhabricatorLiskDAO $object) { + return $object->getPHID(); + } + /** * @task mail