From 47d497aa604580d8b3a6d54e13602f505434394b Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 31 Jul 2019 11:37:02 -0700 Subject: [PATCH] When users visit a Phame post URI with an old blog ID, canonicalize the URI instead of 404'ing Summary: Fixes T13353. If you: - Visit a blog post and save the URI. - Move the blog post to a different blog. - Revisit the old URI. ...we currently 404. We know what you're trying to do and should just redirect you to the new URI instead. We already do this if you visit a URI with a noncanonical slug. Test Plan: - Created post A. - Copied the live URI. - Moved it to a different blog. - Visited the saved URI from the earlier step. - Before: 404. - After: Redirect to the canonical URI. Maniphest Tasks: T13353 Differential Revision: https://secure.phabricator.com/D20688 --- .../phame/controller/PhameLiveController.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/applications/phame/controller/PhameLiveController.php b/src/applications/phame/controller/PhameLiveController.php index b5b1984816..472f73c8c1 100644 --- a/src/applications/phame/controller/PhameLiveController.php +++ b/src/applications/phame/controller/PhameLiveController.php @@ -93,10 +93,6 @@ abstract class PhameLiveController extends PhameController { ->needHeaderImage(true) ->withIDs(array($post_id)); - if ($blog) { - $post_query->withBlogPHIDs(array($blog->getPHID())); - } - // Only show published posts on external domains. if ($is_external) { $post_query->withVisibility( @@ -123,10 +119,15 @@ abstract class PhameLiveController extends PhameController { $this->post = $post; // If we have a post, canonicalize the URI to the post's current slug and - // redirect the user if it isn't correct. + // redirect the user if it isn't correct. Likewise, canonicalize the URI + // if the blog ID is wrong. See T13353. if ($post) { $slug = $request->getURIData('slug'); - if ($post->getSlug() != $slug) { + + $wrong_slug = ($post->getSlug() !== $slug); + $wrong_blog = ($post->getBlog()->getID() !== $blog->getID()); + + if ($wrong_slug || $wrong_blog) { if ($is_live) { if ($is_external) { $uri = $post->getExternalLiveURI();