From b2b677d4460fecf5c519e44825f7d7087168465a Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 31 Aug 2011 12:00:34 -0700 Subject: [PATCH] Fix some sloppiness with definition of $slug. --- .../edit/PhrictionEditController.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/applications/phriction/controller/edit/PhrictionEditController.php b/src/applications/phriction/controller/edit/PhrictionEditController.php index 6d333c3499..1646db29cd 100644 --- a/src/applications/phriction/controller/edit/PhrictionEditController.php +++ b/src/applications/phriction/controller/edit/PhrictionEditController.php @@ -30,9 +30,6 @@ class PhrictionEditController $request = $this->getRequest(); $user = $request->getUser(); - $slug = $request->getStr('slug'); - $slug = PhrictionDocument::normalizeSlug($slug); - if ($this->id) { $document = id(new PhrictionDocument())->load($this->id); if (!$document) { @@ -51,7 +48,14 @@ class PhrictionEditController } else { $content = id(new PhrictionContent())->load($document->getContentID()); } - } else if ($slug) { + + } else { + $slug = $request->getStr('slug'); + $slug = PhrictionDocument::normalizeSlug($slug); + if (!$slug) { + return new Aphront404Response(); + } + $document = id(new PhrictionDocument())->loadOneWhere( 'slug = %s', $slug); @@ -68,8 +72,6 @@ class PhrictionEditController $default_title = PhrictionDocument::getDefaultSlugTitle($slug); $content->setTitle($default_title); } - } else { - return new Aphront404Response(); } require_celerity_resource('phriction-document-css'); @@ -88,7 +90,7 @@ class PhrictionEditController } if (!count($errors)) { - $editor = id(PhrictionDocumentEditor::newForSlug($slug)) + $editor = id(PhrictionDocumentEditor::newForSlug($document->getSlug())) ->setUser($user) ->setTitle($title) ->setContent($request->getStr('content')) @@ -96,7 +98,7 @@ class PhrictionEditController $editor->save(); - $uri = PhrictionDocument::getSlugURI($slug); + $uri = PhrictionDocument::getSlugURI($document->getSlug()); return id(new AphrontRedirectResponse())->setURI($uri); } } @@ -132,7 +134,7 @@ class PhrictionEditController $form = id(new AphrontFormView()) ->setUser($user) ->setAction($request->getRequestURI()->getPath()) - ->addHiddenInput('slug', $slug) + ->addHiddenInput('slug', $document->getSlug()) ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Title')