@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 114 lines 2.9 kB view raw
1<?php 2 3echo pht('Ensuring project names are unique enough...')."\n"; 4$table = new PhabricatorProject(); 5$table->openTransaction(); 6$table->beginReadLocking(); 7 8$projects = $table->loadAll(); 9 10$slug_map = array(); 11 12foreach ($projects as $project) { 13 $slug = PhabricatorSlug::normalizeProjectSlug($project->getName()); 14 15 if (!strlen($slug)) { 16 $project_id = $project->getID(); 17 echo pht("Project #%d doesn't have a meaningful name...", $project_id)."\n"; 18 $project->setName(trim(pht('Unnamed Project %s', $project->getName()))); 19 } 20 21 $slug_map[$slug][] = $project->getID(); 22} 23 24 25foreach ($slug_map as $slug => $similar) { 26 if (count($similar) <= 1) { 27 continue; 28 } 29 echo pht("Too many projects are similar to '%s'...", $slug)."\n"; 30 31 foreach (array_slice($similar, 1, null, true) as $key => $project_id) { 32 $project = $projects[$project_id]; 33 $old_name = $project->getName(); 34 $new_name = rename_project($project, $projects); 35 36 echo pht( 37 "Renaming project #%d from '%s' to '%s'.\n", 38 $project_id, 39 $old_name, 40 $new_name); 41 $project->setName($new_name); 42 } 43} 44 45$update = $projects; 46while ($update) { 47 $size = count($update); 48 foreach ($update as $key => $project) { 49 $id = $project->getID(); 50 $name = $project->getName(); 51 52 $slug = PhabricatorSlug::normalizeProjectSlug($name).'/'; 53 54 echo pht("Updating project #%d '%s' (%s)... ", $id, $name, $slug); 55 try { 56 queryfx( 57 $project->establishConnection('w'), 58 'UPDATE %T SET name = %s, phrictionSlug = %s WHERE id = %d', 59 $project->getTableName(), 60 $name, 61 $slug, 62 $project->getID()); 63 unset($update[$key]); 64 echo pht('OKAY')."\n"; 65 } catch (AphrontDuplicateKeyQueryException $ex) { 66 echo pht('Failed, will retry.')."\n"; 67 } 68 } 69 if (count($update) == $size) { 70 throw new Exception( 71 pht( 72 'Failed to make any progress while updating projects. Schema upgrade '. 73 'has failed. Go manually fix your project names to be unique '. 74 '(they are probably ridiculous?) and then try again.')); 75 } 76} 77 78$table->endReadLocking(); 79$table->saveTransaction(); 80echo pht('Done.')."\n"; 81 82 83/** 84 * Rename the project so that it has a unique slug, by appending (2), (3), etc. 85 * to its name. 86 */ 87function rename_project($project, $projects) { 88 $suffix = 2; 89 while (true) { 90 $new_name = $project->getName().' ('.$suffix.')'; 91 92 $new_slug = PhabricatorSlug::normalizeProjectSlug($new_name).'/'; 93 94 $okay = true; 95 foreach ($projects as $other) { 96 if ($other->getID() == $project->getID()) { 97 continue; 98 } 99 100 $other_slug = PhabricatorSlug::normalizeProjectSlug($other->getName()); 101 if ($other_slug == $new_slug) { 102 $okay = false; 103 break; 104 } 105 } 106 if ($okay) { 107 break; 108 } else { 109 $suffix++; 110 } 111 } 112 113 return $new_name; 114}