1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +01:00

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
This commit is contained in:
epriestley 2014-05-22 10:39:48 -07:00
parent 38b17157fa
commit 890ae77a9a

View file

@ -112,20 +112,45 @@ final class PhrictionDocumentController
$core_content = $notice->render(); $core_content = $notice->render();
} else if ($current_status == PhrictionChangeType::CHANGE_MOVE_AWAY) { } else if ($current_status == PhrictionChangeType::CHANGE_MOVE_AWAY) {
$new_doc_id = $content->getChangeRef(); $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) ->setViewer($user)
->withIDs(array($new_doc_id)) ->withIDs(array($new_doc_id))
->executeOne(); ->execute();
if ($new_docs) {
$slug_uri = PhrictionDocument::getSlugURI($new_doc->getSlug()); $new_doc = head($new_docs);
$slug_uri = PhrictionDocument::getSlugURI($new_doc->getSlug());
}
$notice = new AphrontErrorView(); $notice = new AphrontErrorView();
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
$notice->setTitle(pht('Document Moved')); $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 '. if ($slug_uri) {
'content here, or use history to revert to an earlier version.', $notice->appendChild(
phutil_tag('a', array('href' => $slug_uri), $slug_uri)))); 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(); $core_content = $notice->render();
} else { } else {
throw new Exception("Unknown document status '{$doc_status}'!"); throw new Exception("Unknown document status '{$doc_status}'!");