From 890ae77a9a4718e1ad81135f8898c304be32e53f Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 22 May 2014 10:39:48 -0700 Subject: [PATCH] Don't fatal when viewing a moved document if the target does not exist or isn't visible Summary: Fixes T5156. If a document has been moved but the new one does not exist or can't be seen by the viewer, render a generic message. Test Plan: Viewed moved-plus-visible and moved-plus-nonvisible documents. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5156 Differential Revision: https://secure.phabricator.com/D9254 --- .../PhrictionDocumentController.php | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/applications/phriction/controller/PhrictionDocumentController.php b/src/applications/phriction/controller/PhrictionDocumentController.php index c4b1d03cb3..bf09700796 100644 --- a/src/applications/phriction/controller/PhrictionDocumentController.php +++ b/src/applications/phriction/controller/PhrictionDocumentController.php @@ -112,20 +112,45 @@ final class PhrictionDocumentController $core_content = $notice->render(); } else if ($current_status == PhrictionChangeType::CHANGE_MOVE_AWAY) { $new_doc_id = $content->getChangeRef(); - $new_doc = id(new PhrictionDocumentQuery()) + + $slug_uri = null; + + // If the new document exists and the viewer can see it, provide a link + // to it. Otherwise, render a generic message. + $new_docs = id(new PhrictionDocumentQuery()) ->setViewer($user) ->withIDs(array($new_doc_id)) - ->executeOne(); - - $slug_uri = PhrictionDocument::getSlugURI($new_doc->getSlug()); + ->execute(); + if ($new_docs) { + $new_doc = head($new_docs); + $slug_uri = PhrictionDocument::getSlugURI($new_doc->getSlug()); + } $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setTitle(pht('Document Moved')); - $notice->appendChild(phutil_tag('p', array(), - pht('This document has been moved to %s. You can edit it to put new '. - 'content here, or use history to revert to an earlier version.', - phutil_tag('a', array('href' => $slug_uri), $slug_uri)))); + + if ($slug_uri) { + $notice->appendChild( + phutil_tag( + 'p', + array(), + pht( + 'This document has been moved to %s. You can edit it to put '. + 'new content here, or use history to revert to an earlier '. + 'version.', + phutil_tag('a', array('href' => $slug_uri), $slug_uri)))); + } else { + $notice->appendChild( + phutil_tag( + 'p', + array(), + pht( + 'This document has been moved. You can edit it to put new '. + 'contne here, or use history to revert to an earlier '. + 'version.'))); + } + $core_content = $notice->render(); } else { throw new Exception("Unknown document status '{$doc_status}'!");