mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
ef85f49adc
Summary: This commit doesn't change license of any file. It just makes the license implicit (inherited from LICENSE file in the root directory). We are removing the headers for these reasons: - It wastes space in editors, less code is visible in editor upon opening a file. - It brings noise to diff of the first change of any file every year. - It confuses Git file copy detection when creating small files. - We don't have an explicit license header in other files (JS, CSS, images, documentation). - Using license header in every file is not obligatory: http://www.apache.org/dev/apply-license.html#new. This change is approved by Alma Chao (Lead Open Source and IP Counsel at Facebook). Test Plan: Verified that the license survived only in LICENSE file and that it didn't modify externals. Reviewers: epriestley, davidrecordon Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2035 Differential Revision: https://secure.phabricator.com/D3886
101 lines
2.6 KiB
PHP
101 lines
2.6 KiB
PHP
<?php
|
|
|
|
echo "Ensuring project names are unique enough...\n";
|
|
$projects = id(new PhabricatorProject())->loadAll();
|
|
|
|
$slug_map = array();
|
|
|
|
foreach ($projects as $project) {
|
|
$project->setPhrictionSlug($project->getName());
|
|
$slug = $project->getPhrictionSlug();
|
|
if ($slug == '/') {
|
|
$project_id = $project->getID();
|
|
echo "Project #{$project_id} doesn't have a meaningful name...\n";
|
|
$project->setName(trim('Unnamed Project '.$project->getName()));
|
|
}
|
|
$slug_map[$slug][] = $project->getID();
|
|
}
|
|
|
|
|
|
foreach ($slug_map as $slug => $similar) {
|
|
if (count($similar) <= 1) {
|
|
continue;
|
|
}
|
|
echo "Too many projects are similar to '{$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 "Renaming project #{$project_id} ".
|
|
"from '{$old_name}' to '{$new_name}'.\n";
|
|
$project->setName($new_name);
|
|
}
|
|
}
|
|
|
|
$update = $projects;
|
|
while ($update) {
|
|
$size = count($update);
|
|
foreach ($update as $key => $project) {
|
|
$id = $project->getID();
|
|
$name = $project->getName();
|
|
$project->setPhrictionSlug($name);
|
|
$slug = $project->getPhrictionSlug();
|
|
|
|
echo "Updating project #{$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 "okay.\n";
|
|
} catch (AphrontQueryDuplicateKeyException $ex) {
|
|
echo "failed, will retry.\n";
|
|
}
|
|
}
|
|
if (count($update) == $size) {
|
|
throw new Exception(
|
|
"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.");
|
|
}
|
|
}
|
|
|
|
echo "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.')';
|
|
$project->setPhrictionSlug($new_name);
|
|
$new_slug = $project->getPhrictionSlug();
|
|
|
|
$okay = true;
|
|
foreach ($projects as $other) {
|
|
if ($other->getID() == $project->getID()) {
|
|
continue;
|
|
}
|
|
if ($other->getPhrictionSlug() == $new_slug) {
|
|
$okay = false;
|
|
break;
|
|
}
|
|
}
|
|
if ($okay) {
|
|
break;
|
|
} else {
|
|
$suffix++;
|
|
}
|
|
}
|
|
|
|
return $new_name;
|
|
}
|