Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngine.php
| Show First 20 Lines • Show All 873 Lines • ▼ Show 20 Lines | /* -( Responding to Web Requests )----------------------------------------- */ | ||||
| final public function buildEditEngineCommentView($object) { | final public function buildEditEngineCommentView($object) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $object_phid = $object->getPHID(); | $object_phid = $object->getPHID(); | ||||
| $header_text = $this->getCommentViewHeaderText($object); | $header_text = $this->getCommentViewHeaderText($object); | ||||
| $button_text = $this->getCommentViewButtonText($object); | $button_text = $this->getCommentViewButtonText($object); | ||||
| // TODO: Drafts. | |||||
| // $draft = PhabricatorDraft::newFromUserAndKey( | |||||
| // $viewer, | |||||
| // $object_phid); | |||||
| $comment_uri = $this->getEditURI($object, 'comment/'); | $comment_uri = $this->getEditURI($object, 'comment/'); | ||||
| return id(new PhabricatorApplicationTransactionCommentView()) | $view = id(new PhabricatorApplicationTransactionCommentView()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setObjectPHID($object_phid) | ->setObjectPHID($object_phid) | ||||
| ->setHeaderText($header_text) | ->setHeaderText($header_text) | ||||
| ->setAction($comment_uri) | ->setAction($comment_uri) | ||||
| ->setSubmitButtonName($button_text); | ->setSubmitButtonName($button_text); | ||||
| $draft = PhabricatorVersionedDraft::loadDraft( | |||||
| $object_phid, | |||||
| $viewer->getPHID()); | |||||
| if ($draft) { | |||||
| $view->setVersionedDraft($draft); | |||||
| } | } | ||||
| $view->setCurrentVersion($this->loadDraftVersion($object)); | |||||
| return $view; | |||||
| } | |||||
| protected function loadDraftVersion($object) { | |||||
| $viewer = $this->getViewer(); | |||||
| if (!$viewer->isLoggedIn()) { | |||||
| return null; | |||||
| } | |||||
| $template = $object->getApplicationTransactionTemplate(); | |||||
| $conn_r = $template->establishConnection('r'); | |||||
| // Find the most recent transaction the user has written. We'll use this | |||||
| // as a version number to make sure that out-of-date drafts get discarded. | |||||
| $result = queryfx_one( | |||||
| $conn_r, | |||||
| 'SELECT id AS version FROM %T | |||||
| WHERE objectPHID = %s AND authorPHID = %s | |||||
| ORDER BY id DESC LIMIT 1', | |||||
| $template->getTableName(), | |||||
| $object->getPHID(), | |||||
| $viewer->getPHID()); | |||||
| if ($result) { | |||||
| return (int)$result['version']; | |||||
| } else { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| /* -( Responding to HTTP Parameter Requests )------------------------------ */ | /* -( Responding to HTTP Parameter Requests )------------------------------ */ | ||||
| /** | /** | ||||
| * Respond to a request for documentation on HTTP parameters. | * Respond to a request for documentation on HTTP parameters. | ||||
| * | * | ||||
| * @param object Editable object. | * @param object Editable object. | ||||
| * @return AphrontResponse Response object. | * @return AphrontResponse Response object. | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | private function buildCommentResponse($object) { | ||||
| } | } | ||||
| $is_preview = $request->isPreviewRequest(); | $is_preview = $request->isPreviewRequest(); | ||||
| $view_uri = $this->getObjectViewURI($object); | $view_uri = $this->getObjectViewURI($object); | ||||
| $template = $object->getApplicationTransactionTemplate(); | $template = $object->getApplicationTransactionTemplate(); | ||||
| $comment_template = $template->getApplicationTransactionCommentObject(); | $comment_template = $template->getApplicationTransactionCommentObject(); | ||||
| $comment_text = $request->getStr('comment'); | |||||
| if ($is_preview) { | |||||
| $version_key = PhabricatorVersionedDraft::KEY_VERSION; | |||||
| $request_version = $request->getInt($version_key); | |||||
| $current_version = $this->loadDraftVersion($object); | |||||
| if ($request_version >= $current_version) { | |||||
| $draft = PhabricatorVersionedDraft::loadOrCreateDraft( | |||||
| $object->getPHID(), | |||||
| $viewer->getPHID(), | |||||
| $current_version); | |||||
| // TODO: This is just a proof of concept. | |||||
| $draft->setProperty('temporary.comment', $comment_text); | |||||
| $draft->save(); | |||||
| } | |||||
| } | |||||
| $xactions = array(); | $xactions = array(); | ||||
| $xactions[] = id(clone $template) | $xactions[] = id(clone $template) | ||||
| ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) | ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) | ||||
| ->attachComment( | ->attachComment( | ||||
| id(clone $comment_template) | id(clone $comment_template) | ||||
| ->setContent($request->getStr('comment'))); | ->setContent($comment_text)); | ||||
| $editor = $object->getApplicationTransactionEditor() | $editor = $object->getApplicationTransactionEditor() | ||||
| ->setActor($viewer) | ->setActor($viewer) | ||||
| ->setContinueOnNoEffect($request->isContinueRequest()) | ->setContinueOnNoEffect($request->isContinueRequest()) | ||||
| ->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
| ->setIsPreview($is_preview); | ->setIsPreview($is_preview); | ||||
| try { | try { | ||||
| $xactions = $editor->applyTransactions($object, $xactions); | $xactions = $editor->applyTransactions($object, $xactions); | ||||
| } catch (PhabricatorApplicationTransactionNoEffectException $ex) { | } catch (PhabricatorApplicationTransactionNoEffectException $ex) { | ||||
| return id(new PhabricatorApplicationTransactionNoEffectResponse()) | return id(new PhabricatorApplicationTransactionNoEffectResponse()) | ||||
| ->setCancelURI($view_uri) | ->setCancelURI($view_uri) | ||||
| ->setException($ex); | ->setException($ex); | ||||
| } | } | ||||
| if (!$is_preview) { | |||||
| PhabricatorVersionedDraft::purgeDrafts( | |||||
| $object->getPHID(), | |||||
| $viewer->getPHID(), | |||||
| $this->loadDraftVersion($object)); | |||||
| } | |||||
| if ($request->isAjax() && $is_preview) { | if ($request->isAjax() && $is_preview) { | ||||
| return id(new PhabricatorApplicationTransactionResponse()) | return id(new PhabricatorApplicationTransactionResponse()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->setTransactions($xactions) | ->setTransactions($xactions) | ||||
| ->setIsPreview($is_preview); | ->setIsPreview($is_preview); | ||||
| } else { | } else { | ||||
| return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
| ->setURI($view_uri); | ->setURI($view_uri); | ||||
| ▲ Show 20 Lines • Show All 217 Lines • Show Last 20 Lines | |||||