3 final class PhabricatorFilesManagementEncodeWorkflow
4 extends PhabricatorFilesManagementWorkflow
{
6 protected function didConstruct() {
7 $arguments = $this->newIteratorArguments();
12 'help' => pht('Select the storage format to use.'),
18 'help' => pht('Select a specific storage key.'),
24 'Re-encode files which are already stored in the target '.
31 pht('Change the storage encoding of files.'))
32 ->setArguments($arguments);
35 public function execute(PhutilArgumentParser
$args) {
36 $iterator = $this->buildIterator($args);
38 $force = (bool)$args->getArg('force');
40 $format_list = PhabricatorFileStorageFormat
::getAllFormats();
41 $format_list = array_keys($format_list);
42 $format_list = implode(', ', $format_list);
44 $format_key = $args->getArg('as');
45 if (!strlen($format_key)) {
46 throw new PhutilArgumentUsageException(
48 'Use --as <format> to select a target encoding format. Available '.
53 $format = PhabricatorFileStorageFormat
::getFormat($format_key);
55 throw new PhutilArgumentUsageException(
57 'Storage format "%s" is not valid. Available formats are: %s.',
62 $key_name = $args->getArg('key');
63 if (strlen($key_name)) {
64 $format->selectMasterKey($key_name);
67 $engines = PhabricatorFileStorageEngine
::loadAllEngines();
70 foreach ($iterator as $file) {
71 $monogram = $file->getMonogram();
73 $engine_key = $file->getStorageEngine();
74 $engine = idx($engines, $engine_key);
80 '%s: Uses unknown storage engine "%s".',
87 if ($engine->isChunkEngine()) {
91 '%s: Stored as chunks, no data to encode directly.',
96 if (($file->getStorageFormat() == $format_key) && !$force) {
100 '%s: Already encoded in target format.',
108 '%s: Changing encoding from "%s" to "%s".',
110 $file->getStorageFormat(),
114 $file->migrateToStorageFormat($format);
119 } catch (Exception
$ex) {
122 pht('Failed! %s', (string)$ex));
128 $monograms = mpull($failed, 'getMonogram');
132 pht('Failures: %s.', implode(', ', $monograms)));