mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 01:10:58 +01:00
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
This commit is contained in:
parent
5b1ea8c8d5
commit
ac504f232f
2 changed files with 12 additions and 26 deletions
|
@ -82,6 +82,7 @@ final class PhabricatorProjectTransactionEditor
|
|||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorProjectTransaction::TYPE_NAME:
|
||||
$object->setName($xaction->getNewValue());
|
||||
// TODO - this is really "setPrimarySlug"
|
||||
$object->setPhrictionSlug($xaction->getNewValue());
|
||||
return;
|
||||
case PhabricatorProjectTransaction::TYPE_SLUGS:
|
||||
|
@ -127,19 +128,12 @@ final class PhabricatorProjectTransactionEditor
|
|||
|
||||
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 punctuation.
|
||||
// Removing the new slug is important when changing the project's name
|
||||
// so that one of its secondary slugs is now the primary slug.
|
||||
// First, add the old name as a secondary slug; this is helpful
|
||||
// for renames and generally a good thing to do.
|
||||
if ($old !== null) {
|
||||
$this->removeSlug($object, $old);
|
||||
$this->addSlug($object, $old);
|
||||
}
|
||||
$this->removeSlug($object, $new);
|
||||
|
||||
$new_slug = id(new PhabricatorProjectSlug())
|
||||
->setSlug($object->getPrimarySlug())
|
||||
->setProjectPHID($object->getPHID())
|
||||
->save();
|
||||
$this->addSlug($object, $new);
|
||||
|
||||
return;
|
||||
case PhabricatorProjectTransaction::TYPE_SLUGS:
|
||||
|
@ -429,7 +423,7 @@ final class PhabricatorProjectTransactionEditor
|
|||
return parent::extractFilePHIDsFromCustomTransaction($object, $xaction);
|
||||
}
|
||||
|
||||
private function removeSlug(
|
||||
private function addSlug(
|
||||
PhabricatorLiskDAO $object,
|
||||
$name) {
|
||||
|
||||
|
@ -441,16 +435,13 @@ final class PhabricatorProjectTransactionEditor
|
|||
'slug = %s',
|
||||
$slug);
|
||||
|
||||
if (!$slug_object) {
|
||||
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();
|
||||
$new_slug = id(new PhabricatorProjectSlug())
|
||||
->setSlug($slug)
|
||||
->setProjectPHID($object->getPHID())
|
||||
->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -278,15 +278,10 @@ final class PhabricatorProjectQuery
|
|||
}
|
||||
|
||||
if ($this->slugs !== null) {
|
||||
$slugs = array();
|
||||
foreach ($this->slugs as $slug) {
|
||||
$slugs[] = rtrim(PhabricatorSlug::normalize($slug), '/');
|
||||
}
|
||||
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'slug.slug IN (%Ls)',
|
||||
$slugs);
|
||||
$this->slugs);
|
||||
}
|
||||
|
||||
if ($this->phrictionSlugs !== null) {
|
||||
|
|
Loading…
Reference in a new issue