From 7c5f0250a667d1f16253d3d4f91ac1d8c44f382b Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Tue, 29 Jan 2013 16:53:57 -0800 Subject: [PATCH] Conpherence - make empty comment submission behave like other apps Summary: now we get a "you can't submit no text" error. Also puts the participant status updating inside the editor. Test Plan: made empty comments and got the right error dialogue. made legit comments and they went through. made a new conpherence - work. edited title + picture on old conpherence - worked. tried to submit non-updates to title and image - correct error. Reviewers: epriestley, chad Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2419 Differential Revision: https://secure.phabricator.com/D4734 --- .../ConpherenceUpdateController.php | 49 ++++++------------- .../controller/ConpherenceViewController.php | 1 + .../conpherence/editor/ConpherenceEditor.php | 21 ++++++++ 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/applications/conpherence/controller/ConpherenceUpdateController.php b/src/applications/conpherence/controller/ConpherenceUpdateController.php index cf193f4419..1f984529c2 100644 --- a/src/applications/conpherence/controller/ConpherenceUpdateController.php +++ b/src/applications/conpherence/controller/ConpherenceUpdateController.php @@ -44,6 +44,7 @@ final class ConpherenceUpdateController extends 'ip' => $request->getRemoteAddr() )); $editor = id(new ConpherenceEditor()) + ->setContinueOnNoEffect($request->isContinueRequest()) ->setContentSource($content_source) ->setActor($user); @@ -55,28 +56,6 @@ final class ConpherenceUpdateController extends $conpherence, $message ); - $time = time(); - $conpherence->openTransaction(); - $xactions = $editor->applyTransactions($conpherence, $xactions); - $last_xaction = end($xactions); - $xaction_phid = $last_xaction->getPHID(); - $behind = ConpherenceParticipationStatus::BEHIND; - $up_to_date = ConpherenceParticipationStatus::UP_TO_DATE; - $participants = $conpherence->getParticipants(); - foreach ($participants as $phid => $participant) { - if ($phid != $user->getPHID()) { - if ($participant->getParticipationStatus() != $behind) { - $participant->setBehindTransactionPHID($xaction_phid); - } - $participant->setParticipationStatus($behind); - $participant->setDateTouched($time); - } else { - $participant->setParticipationStatus($up_to_date); - $participant->setDateTouched($time); - } - $participant->save(); - } - $updated = $conpherence->saveTransaction(); break; case 'metadata': $xactions = array(); @@ -112,23 +91,25 @@ final class ConpherenceUpdateController extends ->setTransactionType(ConpherenceTransactionType::TYPE_TITLE) ->setNewValue($title); } - - if ($xactions) { - $conpherence->openTransaction(); - $xactions = $editor - ->setContinueOnNoEffect(true) - ->applyTransactions($conpherence, $xactions); - $updated = $conpherence->saveTransaction(); - } else if (empty($errors)) { - $errors[] = pht( - 'That was a non-update. Try cancel.' - ); - } break; default: throw new Exception('Unknown action: '.$action); break; } + if ($xactions) { + try { + $xactions = $editor->applyTransactions($conpherence, $xactions); + $updated = true; + } catch (PhabricatorApplicationTransactionNoEffectException $ex) { + return id(new PhabricatorApplicationTransactionNoEffectResponse()) + ->setCancelURI($this->getApplicationURI($conpherence_id.'/')) + ->setException($ex); + } + } else if (empty($errors)) { + $errors[] = pht( + 'That was a non-update. Try cancel.' + ); + } } if ($updated) { diff --git a/src/applications/conpherence/controller/ConpherenceViewController.php b/src/applications/conpherence/controller/ConpherenceViewController.php index d615edac50..11cdc8d586 100644 --- a/src/applications/conpherence/controller/ConpherenceViewController.php +++ b/src/applications/conpherence/controller/ConpherenceViewController.php @@ -128,6 +128,7 @@ final class ConpherenceViewController extends $form = id(new AphrontFormView()) + ->setWorkflow(true) ->setAction($this->getApplicationURI('update/'.$conpherence->getID().'/')) ->setFlexible(true) ->setUser($user) diff --git a/src/applications/conpherence/editor/ConpherenceEditor.php b/src/applications/conpherence/editor/ConpherenceEditor.php index 9304e0f14e..a5b42b93ce 100644 --- a/src/applications/conpherence/editor/ConpherenceEditor.php +++ b/src/applications/conpherence/editor/ConpherenceEditor.php @@ -118,6 +118,27 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor { ); } $editor->save(); + // fallthrough + case PhabricatorTransactions::TYPE_COMMENT: + $xaction_phid = $xaction->getPHID(); + $behind = ConpherenceParticipationStatus::BEHIND; + $up_to_date = ConpherenceParticipationStatus::UP_TO_DATE; + $participants = $object->getParticipants(); + $user = $this->getActor(); + $time = time(); + foreach ($participants as $phid => $participant) { + if ($phid != $user->getPHID()) { + if ($participant->getParticipationStatus() != $behind) { + $participant->setBehindTransactionPHID($xaction_phid); + } + $participant->setParticipationStatus($behind); + $participant->setDateTouched($time); + } else { + $participant->setParticipationStatus($up_to_date); + $participant->setDateTouched($time); + } + $participant->save(); + } break; case ConpherenceTransactionType::TYPE_PARTICIPANTS: foreach ($xaction->getNewValue() as $participant) {