@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.

Modernize `bin/files migrate` and fix behavior on chunk engines

Summary: Ref T9828. Mostly just does a minor modernization pass, but also doesn't migrate chunked files since it's not meaningful (they don't have data, directly).

Test Plan: Ran `bin/files migrate` with various flags. Migrated S3 -> Blob and Blob -> S3.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9828

Differential Revision: https://secure.phabricator.com/D14981

+61 -35
+61 -35
src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php
··· 30 30 } 31 31 32 32 public function execute(PhutilArgumentParser $args) { 33 - $console = PhutilConsole::getConsole(); 34 - 35 - $engine_id = $args->getArg('engine'); 36 - if (!$engine_id) { 33 + $target_key = $args->getArg('engine'); 34 + if (!$target_key) { 37 35 throw new PhutilArgumentUsageException( 38 36 pht( 39 37 'Specify an engine to migrate to with `%s`. '. ··· 42 40 'files engines')); 43 41 } 44 42 45 - $engine = PhabricatorFile::buildEngine($engine_id); 43 + $target_engine = PhabricatorFile::buildEngine($target_key); 46 44 47 45 $iterator = $this->buildIterator($args); 48 46 if (!$iterator) { ··· 56 54 $is_dry_run = $args->getArg('dry-run'); 57 55 58 56 $failed = array(); 59 - 57 + $engines = PhabricatorFileStorageEngine::loadAllEngines(); 60 58 foreach ($iterator as $file) { 61 - $fid = 'F'.$file->getID(); 59 + $monogram = $file->getMonogram(); 62 60 63 - if ($file->getStorageEngine() == $engine_id) { 64 - $console->writeOut( 61 + $engine_key = $file->getStorageEngine(); 62 + $engine = idx($engines, $engine_key); 63 + 64 + if (!$engine) { 65 + echo tsprintf( 65 66 "%s\n", 66 67 pht( 67 - "%s: Already stored on '%s'", 68 - $fid, 69 - $engine_id)); 68 + '%s: Uses unknown storage engine "%s".', 69 + $monogram, 70 + $engine_key)); 71 + $failed[] = $file; 72 + continue; 73 + } 74 + 75 + if ($engine->isChunkEngine()) { 76 + echo tsprintf( 77 + "%s\n", 78 + pht( 79 + '%s: Stored as chunks, no data to migrate directly.', 80 + $monogram)); 81 + continue; 82 + } 83 + 84 + if ($engine_key === $target_key) { 85 + echo tsprintf( 86 + "%s\n", 87 + pht( 88 + '%s: Already stored in engine "%s".', 89 + $monogram, 90 + $target_key)); 70 91 continue; 71 92 } 72 93 73 94 if ($is_dry_run) { 74 - $console->writeOut( 95 + echo tsprintf( 75 96 "%s\n", 76 97 pht( 77 - "%s: Would migrate from '%s' to '%s' (dry run)", 78 - $fid, 79 - $file->getStorageEngine(), 80 - $engine_id)); 98 + '%s: Would migrate from "%s" to "%s" (dry run).', 99 + $monogram, 100 + $engine_key, 101 + $target_key)); 81 102 continue; 82 103 } 83 104 84 - $console->writeOut( 105 + echo tsprintf( 85 106 "%s\n", 86 107 pht( 87 - "%s: Migrating from '%s' to '%s'...", 88 - $fid, 89 - $file->getStorageEngine(), 90 - $engine_id)); 108 + '%s: Migrating from "%s" to "%s"...', 109 + $monogram, 110 + $engine_key, 111 + $target_key)); 91 112 92 113 try { 93 - $file->migrateToEngine($engine); 94 - $console->writeOut("%s\n", pht('Done.')); 114 + $file->migrateToEngine($target_engine); 115 + 116 + echo tsprintf( 117 + "%s\n", 118 + pht('Done.')); 119 + 95 120 } catch (Exception $ex) { 96 - $console->writeOut("%s\n", pht('Failed!')); 97 - $console->writeErr("%s\n", (string)$ex); 121 + echo tsprintf( 122 + "%s\n", 123 + pht('Failed! %s', (string)$ex)); 98 124 $failed[] = $file; 125 + 126 + throw $ex; 99 127 } 100 128 } 101 129 102 130 if ($failed) { 103 - $console->writeOut("**%s**\n", pht('Failures!')); 104 - $ids = array(); 105 - foreach ($failed as $file) { 106 - $ids[] = 'F'.$file->getID(); 107 - } 108 - $console->writeOut("%s\n", implode(', ', $ids)); 131 + $monograms = mpull($failed, 'getMonogram'); 132 + 133 + echo tsprintf( 134 + "%s\n", 135 + pht('Failures: %s.', implode(', ', $monograms))); 109 136 110 137 return 1; 111 - } else { 112 - $console->writeOut("**%s**\n", pht('Success!')); 113 - return 0; 114 138 } 139 + 140 + return 0; 115 141 } 116 142 117 143 }