1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 20:10:55 +01:00

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
This commit is contained in:
epriestley 2014-07-10 10:18:32 -07:00
parent e46826ad36
commit 3d804bf14d

View file

@ -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();
}
}