2012-10-25 20:36:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorFilesManagementMigrateWorkflow
|
|
|
|
extends PhabricatorFilesManagementWorkflow {
|
|
|
|
|
2015-01-15 21:42:07 +01:00
|
|
|
protected function didConstruct() {
|
2012-10-25 20:36:38 +02:00
|
|
|
$this
|
|
|
|
->setName('migrate')
|
2015-05-22 09:27:56 +02:00
|
|
|
->setSynopsis(pht('Migrate files between storage engines.'))
|
2012-10-25 20:36:38 +02:00
|
|
|
->setArguments(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => 'engine',
|
|
|
|
'param' => 'storage_engine',
|
2015-05-22 09:27:56 +02:00
|
|
|
'help' => pht('Migrate to the named storage engine.'),
|
2012-10-25 20:36:38 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'dry-run',
|
2015-05-22 09:27:56 +02:00
|
|
|
'help' => pht('Show what would be migrated.'),
|
2012-10-25 20:36:38 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'all',
|
2015-05-22 09:27:56 +02:00
|
|
|
'help' => pht('Migrate all files.'),
|
2012-10-25 20:36:38 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'names',
|
|
|
|
'wildcard' => true,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
|
|
|
$engine_id = $args->getArg('engine');
|
|
|
|
if (!$engine_id) {
|
|
|
|
throw new PhutilArgumentUsageException(
|
2015-05-22 09:27:56 +02:00
|
|
|
pht(
|
|
|
|
'Specify an engine to migrate to with `%s`. '.
|
|
|
|
'Use `%s` to get a list of engines.',
|
|
|
|
'--engine',
|
|
|
|
'files engines'));
|
2012-10-25 20:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$engine = PhabricatorFile::buildEngine($engine_id);
|
|
|
|
|
2013-05-29 15:28:57 +02:00
|
|
|
$iterator = $this->buildIterator($args);
|
|
|
|
if (!$iterator) {
|
2012-10-25 20:36:38 +02:00
|
|
|
throw new PhutilArgumentUsageException(
|
2015-05-22 09:27:56 +02:00
|
|
|
pht(
|
|
|
|
'Either specify a list of files to migrate, or use `%s` '.
|
|
|
|
'to migrate all files.',
|
|
|
|
'--all'));
|
2012-10-25 20:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$is_dry_run = $args->getArg('dry-run');
|
|
|
|
|
|
|
|
$failed = array();
|
|
|
|
|
|
|
|
foreach ($iterator as $file) {
|
|
|
|
$fid = 'F'.$file->getID();
|
|
|
|
|
|
|
|
if ($file->getStorageEngine() == $engine_id) {
|
|
|
|
$console->writeOut(
|
2015-05-22 09:27:56 +02:00
|
|
|
"%s\n",
|
|
|
|
pht(
|
|
|
|
"%s: Already stored on '%s'",
|
|
|
|
$fid,
|
|
|
|
$engine_id));
|
2012-10-25 20:36:38 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($is_dry_run) {
|
|
|
|
$console->writeOut(
|
2015-05-22 09:27:56 +02:00
|
|
|
"%s\n",
|
|
|
|
pht(
|
|
|
|
"%s: Would migrate from '%s' to '%s' (dry run)",
|
|
|
|
$fid,
|
|
|
|
$file->getStorageEngine(),
|
|
|
|
$engine_id));
|
2012-10-25 20:36:38 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$console->writeOut(
|
2015-05-22 09:27:56 +02:00
|
|
|
"%s\n",
|
|
|
|
pht(
|
|
|
|
"%s: Migrating from '%s' to '%s'...",
|
|
|
|
$fid,
|
|
|
|
$file->getStorageEngine(),
|
|
|
|
$engine_id));
|
2012-10-25 20:36:38 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
$file->migrateToEngine($engine);
|
2015-05-22 09:27:56 +02:00
|
|
|
$console->writeOut("%s\n", pht('Done.'));
|
2012-10-25 20:36:38 +02:00
|
|
|
} catch (Exception $ex) {
|
2015-05-22 09:27:56 +02:00
|
|
|
$console->writeOut("%s\n", pht('Failed!'));
|
2012-10-25 20:36:38 +02:00
|
|
|
$console->writeErr("%s\n", (string)$ex);
|
|
|
|
$failed[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($failed) {
|
2015-05-22 09:27:56 +02:00
|
|
|
$console->writeOut("**%s**\n", pht('Failures!'));
|
2012-10-25 20:36:38 +02:00
|
|
|
$ids = array();
|
|
|
|
foreach ($failed as $file) {
|
|
|
|
$ids[] = 'F'.$file->getID();
|
|
|
|
}
|
|
|
|
$console->writeOut("%s\n", implode(', ', $ids));
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
} else {
|
2015-05-22 09:27:56 +02:00
|
|
|
$console->writeOut("**%s**\n", pht('Success!'));
|
2012-10-25 20:36:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|