@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

Projects - smooth out scenarios around renaming a project and slugs

Summary:
Fixes T7092. When you name project "Foo" which has primary hashtag "foo" to "Foobar", post this patch the hashtag "foo" gets added as a secondary hashtag. Also makes sure we don't normalize the hashtags in the query function as the wikimedia folks were hitting an issue around capitalization on the hashtag.

Note that T6909 remains "broken" in that you get an error that you can't do that, though if you just omit the additional hashtag it would work fine. I think if a fix is necessary here the best bet would be to simply detect this particular scenario and let things proceed; its a bit tricky though since its about two transactions about to be applied and how they interact with one another...

Test Plan: Made project "Foo" which has primary hashtag "foo". Renamed it to "Foobar" and verified "foo" was added as a secondary hashtag and "foobar" was the primary hashtag. Renamed it again to "Foo" and noted that the hashtags all ended up correct.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T7092, T6909

Differential Revision: https://secure.phabricator.com/D11697

+12 -26
+11 -20
src/applications/project/editor/PhabricatorProjectTransactionEditor.php
··· 82 82 switch ($xaction->getTransactionType()) { 83 83 case PhabricatorProjectTransaction::TYPE_NAME: 84 84 $object->setName($xaction->getNewValue()); 85 + // TODO - this is really "setPrimarySlug" 85 86 $object->setPhrictionSlug($xaction->getNewValue()); 86 87 return; 87 88 case PhabricatorProjectTransaction::TYPE_SLUGS: ··· 127 128 128 129 switch ($xaction->getTransactionType()) { 129 130 case PhabricatorProjectTransaction::TYPE_NAME: 130 - // First, remove the old and new slugs. Removing the old slug is 131 - // important when changing the project's capitalization or punctuation. 132 - // Removing the new slug is important when changing the project's name 133 - // so that one of its secondary slugs is now the primary slug. 131 + // First, add the old name as a secondary slug; this is helpful 132 + // for renames and generally a good thing to do. 134 133 if ($old !== null) { 135 - $this->removeSlug($object, $old); 134 + $this->addSlug($object, $old); 136 135 } 137 - $this->removeSlug($object, $new); 138 - 139 - $new_slug = id(new PhabricatorProjectSlug()) 140 - ->setSlug($object->getPrimarySlug()) 141 - ->setProjectPHID($object->getPHID()) 142 - ->save(); 136 + $this->addSlug($object, $new); 143 137 144 138 return; 145 139 case PhabricatorProjectTransaction::TYPE_SLUGS: ··· 429 423 return parent::extractFilePHIDsFromCustomTransaction($object, $xaction); 430 424 } 431 425 432 - private function removeSlug( 426 + private function addSlug( 433 427 PhabricatorLiskDAO $object, 434 428 $name) { 435 429 ··· 441 435 'slug = %s', 442 436 $slug); 443 437 444 - if (!$slug_object) { 438 + if ($slug_object) { 445 439 return; 446 440 } 447 441 448 - if ($slug_object->getProjectPHID() != $object->getPHID()) { 449 - throw new Exception( 450 - pht('Trying to remove slug owned by another project!')); 451 - } 452 - 453 - $slug_object->delete(); 442 + $new_slug = id(new PhabricatorProjectSlug()) 443 + ->setSlug($slug) 444 + ->setProjectPHID($object->getPHID()) 445 + ->save(); 454 446 } 455 - 456 447 }
+1 -6
src/applications/project/query/PhabricatorProjectQuery.php
··· 278 278 } 279 279 280 280 if ($this->slugs !== null) { 281 - $slugs = array(); 282 - foreach ($this->slugs as $slug) { 283 - $slugs[] = rtrim(PhabricatorSlug::normalize($slug), '/'); 284 - } 285 - 286 281 $where[] = qsprintf( 287 282 $conn_r, 288 283 'slug.slug IN (%Ls)', 289 - $slugs); 284 + $this->slugs); 290 285 } 291 286 292 287 if ($this->phrictionSlugs !== null) {