From 3a01d6dae51686acf5103c46b587d057bfe40609 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 11 Feb 2014 11:30:38 -0800 Subject: [PATCH] Fix project editing issue with moving wikis Summary: Fixes T4409. I didn't get this quite right when I updated it to ApplicationTransactions. Test Plan: Renamed a project, saw wiki move. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4409 Differential Revision: https://secure.phabricator.com/D8198 --- .../PhabricatorProjectTransactionEditor.php | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/applications/project/editor/PhabricatorProjectTransactionEditor.php b/src/applications/project/editor/PhabricatorProjectTransactionEditor.php index 4af23f781e..dba6403757 100644 --- a/src/applications/project/editor/PhabricatorProjectTransactionEditor.php +++ b/src/applications/project/editor/PhabricatorProjectTransactionEditor.php @@ -55,6 +55,7 @@ final class PhabricatorProjectTransactionEditor switch ($xaction->getTransactionType()) { case PhabricatorProjectTransaction::TYPE_NAME: $object->setName($xaction->getNewValue()); + $object->setPhrictionSlug($xaction->getNewValue()); return; case PhabricatorProjectTransaction::TYPE_STATUS: $object->setStatus($xaction->getNewValue()); @@ -84,35 +85,37 @@ final class PhabricatorProjectTransactionEditor switch ($xaction->getTransactionType()) { case PhabricatorProjectTransaction::TYPE_NAME: - $old_slug = $object->getFullPhrictionSlug(); - $object->setPhrictionSlug($xaction->getNewValue()); - $changed_slug = $old_slug != $object->getFullPhrictionSlug(); - if ($xaction->getOldValue() && $changed_slug) { - $old_document = id(new PhrictionDocument()) - ->loadOneWhere( - 'slug = %s', - $old_slug); - if ($old_document && $old_document->getStatus() == - PhrictionDocumentStatus::STATUS_EXISTS) { - $content = id(new PhrictionContent()) - ->load($old_document->getContentID()); - $from_editor = id(PhrictionDocumentEditor::newForSlug($old_slug)) - ->setActor($this->getActor()) - ->setTitle($content->getTitle()) - ->setContent($content->getContent()) - ->setDescription($content->getDescription()); + if ($xaction->getOldValue() === null) { + // Project was just created, we don't need to move anything. + return; + } - $target_editor = id(PhrictionDocumentEditor::newForSlug( - $object->getFullPhrictionSlug())) - ->setActor($this->getActor()) - ->setTitle($content->getTitle()) - ->setContent($content->getContent()) - ->setDescription($content->getDescription()) - ->moveHere($old_document->getID(), $old_document->getPHID()); + $clone_object = clone $object; + $clone_object->setPhrictionSlug($xaction->getOldValue()); + $old_slug = $clone_object->getFullPhrictionSlug(); - $target_document = $target_editor->getDocument(); - $from_editor->moveAway($target_document->getID()); - } + $old_document = id(new PhrictionDocument()) + ->loadOneWhere('slug = %s', $old_slug); + if ($old_document && $old_document->getStatus() == + PhrictionDocumentStatus::STATUS_EXISTS) { + $content = id(new PhrictionContent()) + ->load($old_document->getContentID()); + $from_editor = id(PhrictionDocumentEditor::newForSlug($old_slug)) + ->setActor($this->getActor()) + ->setTitle($content->getTitle()) + ->setContent($content->getContent()) + ->setDescription($content->getDescription()); + + $target_editor = id(PhrictionDocumentEditor::newForSlug( + $object->getFullPhrictionSlug())) + ->setActor($this->getActor()) + ->setTitle($content->getTitle()) + ->setContent($content->getContent()) + ->setDescription($content->getDescription()) + ->moveHere($old_document->getID(), $old_document->getPHID()); + + $target_document = $target_editor->getDocument(); + $from_editor->moveAway($target_document->getID()); } return; case PhabricatorTransactions::TYPE_VIEW_POLICY: