Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / files / management / PhabricatorFilesManagementCycleWorkflow.php
blobcbcfac2cc8183102751949a10acf82dc210c0aa4
1 <?php
3 final class PhabricatorFilesManagementCycleWorkflow
4 extends PhabricatorFilesManagementWorkflow {
6 protected function didConstruct() {
7 $arguments = $this->newIteratorArguments();
8 $arguments[] = array(
9 'name' => 'key',
10 'param' => 'keyname',
11 'help' => pht('Select a specific storage key to cycle to.'),
14 $this
15 ->setName('cycle')
16 ->setSynopsis(
17 pht('Cycle master key for encrypted files.'))
18 ->setArguments($arguments);
21 public function execute(PhutilArgumentParser $args) {
22 $iterator = $this->buildIterator($args);
24 $format_map = PhabricatorFileStorageFormat::getAllFormats();
25 $engines = PhabricatorFileStorageEngine::loadAllEngines();
27 $key_name = $args->getArg('key');
29 $failed = array();
30 foreach ($iterator as $file) {
31 $monogram = $file->getMonogram();
33 $engine_key = $file->getStorageEngine();
34 $engine = idx($engines, $engine_key);
36 if (!$engine) {
37 echo tsprintf(
38 "%s\n",
39 pht(
40 '%s: Uses unknown storage engine "%s".',
41 $monogram,
42 $engine_key));
43 $failed[] = $file;
44 continue;
47 if ($engine->isChunkEngine()) {
48 echo tsprintf(
49 "%s\n",
50 pht(
51 '%s: Stored as chunks, declining to cycle directly.',
52 $monogram));
53 continue;
56 $format_key = $file->getStorageFormat();
57 if (empty($format_map[$format_key])) {
58 echo tsprintf(
59 "%s\n",
60 pht(
61 '%s: Uses unknown storage format "%s".',
62 $monogram,
63 $format_key));
64 $failed[] = $file;
65 continue;
68 $format = clone $format_map[$format_key];
69 $format->setFile($file);
71 if (!$format->canCycleMasterKey()) {
72 echo tsprintf(
73 "%s\n",
74 pht(
75 '%s: Storage format ("%s") does not support key cycling.',
76 $monogram,
77 $format->getStorageFormatName()));
78 continue;
81 echo tsprintf(
82 "%s\n",
83 pht(
84 '%s: Cycling master key.',
85 $monogram));
87 try {
88 if ($key_name) {
89 $format->selectMasterKey($key_name);
92 $file->cycleMasterStorageKey($format);
94 echo tsprintf(
95 "%s\n",
96 pht('Done.'));
97 } catch (Exception $ex) {
98 echo tsprintf(
99 "%B\n",
100 pht('Failed! %s', (string)$ex));
101 $failed[] = $file;
105 if ($failed) {
106 $monograms = mpull($failed, 'getMonogram');
108 echo tsprintf(
109 "%s\n",
110 pht('Failures: %s.', implode(', ', $monograms)));
112 return 1;
115 return 0;