Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php b/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php
index ce48d29bb0..7923ab469c 100644
--- a/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php
+++ b/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php
@@ -1,117 +1,143 @@
<?php
final class PhabricatorFilesManagementMigrateWorkflow
extends PhabricatorFilesManagementWorkflow {
protected function didConstruct() {
$this
->setName('migrate')
->setSynopsis(pht('Migrate files between storage engines.'))
->setArguments(
array(
array(
'name' => 'engine',
'param' => 'storage_engine',
'help' => pht('Migrate to the named storage engine.'),
),
array(
'name' => 'dry-run',
'help' => pht('Show what would be migrated.'),
),
array(
'name' => 'all',
'help' => pht('Migrate all files.'),
),
array(
'name' => 'names',
'wildcard' => true,
),
));
}
public function execute(PhutilArgumentParser $args) {
- $console = PhutilConsole::getConsole();
-
- $engine_id = $args->getArg('engine');
- if (!$engine_id) {
+ $target_key = $args->getArg('engine');
+ if (!$target_key) {
throw new PhutilArgumentUsageException(
pht(
'Specify an engine to migrate to with `%s`. '.
'Use `%s` to get a list of engines.',
'--engine',
'files engines'));
}
- $engine = PhabricatorFile::buildEngine($engine_id);
+ $target_engine = PhabricatorFile::buildEngine($target_key);
$iterator = $this->buildIterator($args);
if (!$iterator) {
throw new PhutilArgumentUsageException(
pht(
'Either specify a list of files to migrate, or use `%s` '.
'to migrate all files.',
'--all'));
}
$is_dry_run = $args->getArg('dry-run');
$failed = array();
-
+ $engines = PhabricatorFileStorageEngine::loadAllEngines();
foreach ($iterator as $file) {
- $fid = 'F'.$file->getID();
+ $monogram = $file->getMonogram();
+
+ $engine_key = $file->getStorageEngine();
+ $engine = idx($engines, $engine_key);
+
+ if (!$engine) {
+ echo tsprintf(
+ "%s\n",
+ pht(
+ '%s: Uses unknown storage engine "%s".',
+ $monogram,
+ $engine_key));
+ $failed[] = $file;
+ continue;
+ }
- if ($file->getStorageEngine() == $engine_id) {
- $console->writeOut(
+ if ($engine->isChunkEngine()) {
+ echo tsprintf(
"%s\n",
pht(
- "%s: Already stored on '%s'",
- $fid,
- $engine_id));
+ '%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;
}
if ($is_dry_run) {
- $console->writeOut(
+ echo tsprintf(
"%s\n",
pht(
- "%s: Would migrate from '%s' to '%s' (dry run)",
- $fid,
- $file->getStorageEngine(),
- $engine_id));
+ '%s: Would migrate from "%s" to "%s" (dry run).',
+ $monogram,
+ $engine_key,
+ $target_key));
continue;
}
- $console->writeOut(
+ echo tsprintf(
"%s\n",
pht(
- "%s: Migrating from '%s' to '%s'...",
- $fid,
- $file->getStorageEngine(),
- $engine_id));
+ '%s: Migrating from "%s" to "%s"...',
+ $monogram,
+ $engine_key,
+ $target_key));
try {
- $file->migrateToEngine($engine);
- $console->writeOut("%s\n", pht('Done.'));
+ $file->migrateToEngine($target_engine);
+
+ echo tsprintf(
+ "%s\n",
+ pht('Done.'));
+
} catch (Exception $ex) {
- $console->writeOut("%s\n", pht('Failed!'));
- $console->writeErr("%s\n", (string)$ex);
+ echo tsprintf(
+ "%s\n",
+ pht('Failed! %s', (string)$ex));
$failed[] = $file;
+
+ throw $ex;
}
}
if ($failed) {
- $console->writeOut("**%s**\n", pht('Failures!'));
- $ids = array();
- foreach ($failed as $file) {
- $ids[] = 'F'.$file->getID();
- }
- $console->writeOut("%s\n", implode(', ', $ids));
+ $monograms = mpull($failed, 'getMonogram');
+
+ echo tsprintf(
+ "%s\n",
+ pht('Failures: %s.', implode(', ', $monograms)));
return 1;
- } else {
- $console->writeOut("**%s**\n", pht('Success!'));
- return 0;
}
+
+ return 0;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jun 11, 12:41 AM (1 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
141506
Default Alt Text
(5 KB)

Event Timeline