mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 13:30:55 +01:00
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
This commit is contained in:
parent
efba69a440
commit
67ac356b03
1 changed files with 61 additions and 35 deletions
|
@ -30,10 +30,8 @@ final class PhabricatorFilesManagementMigrateWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(PhutilArgumentParser $args) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
$console = PhutilConsole::getConsole();
|
$target_key = $args->getArg('engine');
|
||||||
|
if (!$target_key) {
|
||||||
$engine_id = $args->getArg('engine');
|
|
||||||
if (!$engine_id) {
|
|
||||||
throw new PhutilArgumentUsageException(
|
throw new PhutilArgumentUsageException(
|
||||||
pht(
|
pht(
|
||||||
'Specify an engine to migrate to with `%s`. '.
|
'Specify an engine to migrate to with `%s`. '.
|
||||||
|
@ -42,7 +40,7 @@ final class PhabricatorFilesManagementMigrateWorkflow
|
||||||
'files engines'));
|
'files engines'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$engine = PhabricatorFile::buildEngine($engine_id);
|
$target_engine = PhabricatorFile::buildEngine($target_key);
|
||||||
|
|
||||||
$iterator = $this->buildIterator($args);
|
$iterator = $this->buildIterator($args);
|
||||||
if (!$iterator) {
|
if (!$iterator) {
|
||||||
|
@ -56,62 +54,90 @@ final class PhabricatorFilesManagementMigrateWorkflow
|
||||||
$is_dry_run = $args->getArg('dry-run');
|
$is_dry_run = $args->getArg('dry-run');
|
||||||
|
|
||||||
$failed = array();
|
$failed = array();
|
||||||
|
$engines = PhabricatorFileStorageEngine::loadAllEngines();
|
||||||
foreach ($iterator as $file) {
|
foreach ($iterator as $file) {
|
||||||
$fid = 'F'.$file->getID();
|
$monogram = $file->getMonogram();
|
||||||
|
|
||||||
if ($file->getStorageEngine() == $engine_id) {
|
$engine_key = $file->getStorageEngine();
|
||||||
$console->writeOut(
|
$engine = idx($engines, $engine_key);
|
||||||
|
|
||||||
|
if (!$engine) {
|
||||||
|
echo tsprintf(
|
||||||
"%s\n",
|
"%s\n",
|
||||||
pht(
|
pht(
|
||||||
"%s: Already stored on '%s'",
|
'%s: Uses unknown storage engine "%s".',
|
||||||
$fid,
|
$monogram,
|
||||||
$engine_id));
|
$engine_key));
|
||||||
|
$failed[] = $file;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($engine->isChunkEngine()) {
|
||||||
|
echo tsprintf(
|
||||||
|
"%s\n",
|
||||||
|
pht(
|
||||||
|
'%s: Stored as chunks, no data to migrate directly.',
|
||||||
|
$monogram));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($engine_key === $target_key) {
|
||||||
|
echo tsprintf(
|
||||||
|
"%s\n",
|
||||||
|
pht(
|
||||||
|
'%s: Already stored in engine "%s".',
|
||||||
|
$monogram,
|
||||||
|
$target_key));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($is_dry_run) {
|
if ($is_dry_run) {
|
||||||
$console->writeOut(
|
echo tsprintf(
|
||||||
"%s\n",
|
"%s\n",
|
||||||
pht(
|
pht(
|
||||||
"%s: Would migrate from '%s' to '%s' (dry run)",
|
'%s: Would migrate from "%s" to "%s" (dry run).',
|
||||||
$fid,
|
$monogram,
|
||||||
$file->getStorageEngine(),
|
$engine_key,
|
||||||
$engine_id));
|
$target_key));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$console->writeOut(
|
echo tsprintf(
|
||||||
"%s\n",
|
"%s\n",
|
||||||
pht(
|
pht(
|
||||||
"%s: Migrating from '%s' to '%s'...",
|
'%s: Migrating from "%s" to "%s"...',
|
||||||
$fid,
|
$monogram,
|
||||||
$file->getStorageEngine(),
|
$engine_key,
|
||||||
$engine_id));
|
$target_key));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$file->migrateToEngine($engine);
|
$file->migrateToEngine($target_engine);
|
||||||
$console->writeOut("%s\n", pht('Done.'));
|
|
||||||
|
echo tsprintf(
|
||||||
|
"%s\n",
|
||||||
|
pht('Done.'));
|
||||||
|
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
$console->writeOut("%s\n", pht('Failed!'));
|
echo tsprintf(
|
||||||
$console->writeErr("%s\n", (string)$ex);
|
"%s\n",
|
||||||
|
pht('Failed! %s', (string)$ex));
|
||||||
$failed[] = $file;
|
$failed[] = $file;
|
||||||
|
|
||||||
|
throw $ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($failed) {
|
if ($failed) {
|
||||||
$console->writeOut("**%s**\n", pht('Failures!'));
|
$monograms = mpull($failed, 'getMonogram');
|
||||||
$ids = array();
|
|
||||||
foreach ($failed as $file) {
|
echo tsprintf(
|
||||||
$ids[] = 'F'.$file->getID();
|
"%s\n",
|
||||||
}
|
pht('Failures: %s.', implode(', ', $monograms)));
|
||||||
$console->writeOut("%s\n", implode(', ', $ids));
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
|
||||||
$console->writeOut("**%s**\n", pht('Success!'));
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue