Page MenuHomestyx hydra

No OneTemporary

diff --git a/resources/sql/autopatches/20140521.projectslug.2.mig.php b/resources/sql/autopatches/20140521.projectslug.2.mig.php
index ca6ccf886a..e0ad4b5070 100644
--- a/resources/sql/autopatches/20140521.projectslug.2.mig.php
+++ b/resources/sql/autopatches/20140521.projectslug.2.mig.php
@@ -1,33 +1,36 @@
<?php
$project_table = new PhabricatorProject();
$table_name = $project_table->getTableName();
$conn_w = $project_table->establishConnection('w');
$slug_table_name = id(new PhabricatorProjectSlug())->getTableName();
-$time = time();
+$time = PhabricatorTime::getNow();
-echo pht('Migrating project phriction slugs...')."\n";
+echo pht('Migrating projects to slugs...')."\n";
foreach (new LiskMigrationIterator($project_table) as $project) {
$id = $project->getID();
echo pht('Migrating project %d...', $id)."\n";
- $phriction_slug = rtrim($project->getPhrictionSlug(), '/');
+
+ $slug_text = PhabricatorSlug::normalizeProjectSlug($project->getName());
$slug = id(new PhabricatorProjectSlug())
- ->loadOneWhere('slug = %s', $phriction_slug);
+ ->loadOneWhere('slug = %s', $slug_text);
+
if ($slug) {
echo pht('Already migrated %d... Continuing.', $id)."\n";
continue;
}
+
queryfx(
$conn_w,
'INSERT INTO %T (projectPHID, slug, dateCreated, dateModified) '.
'VALUES (%s, %s, %d, %d)',
$slug_table_name,
$project->getPHID(),
- $phriction_slug,
+ $slug_text,
$time,
$time);
echo pht('Migrated %d.', $id)."\n";
}
echo pht('Done.')."\n";
diff --git a/resources/sql/patches/090.forceuniqueprojectnames.php b/resources/sql/patches/090.forceuniqueprojectnames.php
index a3e029d50a..486856c1c3 100644
--- a/resources/sql/patches/090.forceuniqueprojectnames.php
+++ b/resources/sql/patches/090.forceuniqueprojectnames.php
@@ -1,112 +1,114 @@
<?php
echo pht('Ensuring project names are unique enough...')."\n";
$table = new PhabricatorProject();
$table->openTransaction();
$table->beginReadLocking();
$projects = $table->loadAll();
$slug_map = array();
foreach ($projects as $project) {
$slug = PhabricatorSlug::normalizeProjectSlug($project->getName());
if (!strlen($slug)) {
$project_id = $project->getID();
echo pht("Project #%d doesn't have a meaningful name...", $project_id)."\n";
$project->setName(trim(pht('Unnamed Project %s', $project->getName())));
}
$slug_map[$slug][] = $project->getID();
}
foreach ($slug_map as $slug => $similar) {
if (count($similar) <= 1) {
continue;
}
echo pht("Too many projects are similar to '%s'...", $slug)."\n";
foreach (array_slice($similar, 1, null, true) as $key => $project_id) {
$project = $projects[$project_id];
$old_name = $project->getName();
$new_name = rename_project($project, $projects);
echo pht(
"Renaming project #%d from '%s' to '%s'.\n",
$project_id,
$old_name,
$new_name);
$project->setName($new_name);
}
}
$update = $projects;
while ($update) {
$size = count($update);
foreach ($update as $key => $project) {
$id = $project->getID();
$name = $project->getName();
$slug = PhabricatorSlug::normalizeProjectSlug($name).'/';
echo pht("Updating project #%d '%s' (%s)... ", $id, $name, $slug);
try {
queryfx(
$project->establishConnection('w'),
'UPDATE %T SET name = %s, phrictionSlug = %s WHERE id = %d',
$project->getTableName(),
$name,
$slug,
$project->getID());
unset($update[$key]);
echo pht('OKAY')."\n";
} catch (AphrontDuplicateKeyQueryException $ex) {
echo pht('Failed, will retry.')."\n";
}
}
if (count($update) == $size) {
throw new Exception(
pht(
'Failed to make any progress while updating projects. Schema upgrade '.
'has failed. Go manually fix your project names to be unique '.
'(they are probably ridiculous?) and then try again.'));
}
}
$table->endReadLocking();
$table->saveTransaction();
echo pht('Done.')."\n";
/**
* Rename the project so that it has a unique slug, by appending (2), (3), etc.
* to its name.
*/
function rename_project($project, $projects) {
$suffix = 2;
while (true) {
$new_name = $project->getName().' ('.$suffix.')';
$new_slug = PhabricatorSlug::normalizeProjectSlug($new_name).'/';
$okay = true;
foreach ($projects as $other) {
if ($other->getID() == $project->getID()) {
continue;
}
- if ($other->getPhrictionSlug() == $new_slug) {
+
+ $other_slug = PhabricatorSlug::normalizeProjectSlug($other->getName());
+ if ($other_slug == $new_slug) {
$okay = false;
break;
}
}
if ($okay) {
break;
} else {
$suffix++;
}
}
return $new_name;
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Mar 16, 4:52 PM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72161
Default Alt Text
(4 KB)

Event Timeline