From 3d804bf14d5dbf7501d5abc75e70932a89456e41 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 10 Jul 2014 10:18:32 -0700 Subject: [PATCH] Fix some transaction issues when retitling projects Summary: Fixes T5530. - We currently fail if you rename a project so it has the same slug (e.g., "Example" -> "ExAmPlE"). - We currently fail if you rename a project so one of its secondary hashtags becomes the primary hashtag. Instead, succeed in these cases. Test Plan: Successfully performed the renames described above. Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T5458, T5530 Differential Revision: https://secure.phabricator.com/D9829 --- .../PhabricatorProjectTransactionEditor.php | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/applications/project/editor/PhabricatorProjectTransactionEditor.php b/src/applications/project/editor/PhabricatorProjectTransactionEditor.php index a60c15b232..73cbcbd168 100644 --- a/src/applications/project/editor/PhabricatorProjectTransactionEditor.php +++ b/src/applications/project/editor/PhabricatorProjectTransactionEditor.php @@ -106,24 +106,25 @@ final class PhabricatorProjectTransactionEditor PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { + $old = $xaction->getOldValue(); + $new = $xaction->getNewValue(); + switch ($xaction->getTransactionType()) { case PhabricatorProjectTransaction::TYPE_NAME: + // First, remove the old and new slugs. Removing the old slug is + // important when changing the project's capitalization or puctuation. + // Removing the new slug is important when changing the project's name + // so that one of its secondary slugs is now the primary slug. + if ($old !== null) { + $this->removeSlug($object, $old); + } + $this->removeSlug($object, $new); + $new_slug = id(new PhabricatorProjectSlug()) ->setSlug($object->getPrimarySlug()) ->setProjectPHID($object->getPHID()) ->save(); - if ($xaction->getOldValue() !== null) { - $clone_object = clone $object; - $clone_object->setPhrictionSlug($xaction->getOldValue()); - $old_slug = $clone_object->getPrimarySlug(); - $old_slug = id(new PhabricatorProjectSlug()) - ->loadOneWhere('slug = %s', $old_slug); - if ($old_slug) { - $old_slug->delete(); - } - } - // TODO -- delete all of the below once we sever automagical project // to phriction stuff if ($xaction->getOldValue() === null) { @@ -429,4 +430,28 @@ final class PhabricatorProjectTransactionEditor return parent::extractFilePHIDsFromCustomTransaction($object, $xaction); } + private function removeSlug( + PhabricatorLiskDAO $object, + $name) { + + $object = (clone $object); + $object->setPhrictionSlug($name); + $slug = $object->getPrimarySlug(); + + $slug_object = id(new PhabricatorProjectSlug())->loadOneWhere( + 'slug = %s', + $slug); + + if (!$slug_object) { + return; + } + + if ($slug_object->getProjectPHID() != $object->getPHID()) { + throw new Exception( + pht('Trying to remove slug owned by another project!')); + } + + $slug_object->delete(); + } + }