Path: blob/master/src/applications/files/management/PhabricatorFilesManagementCycleWorkflow.php
13419 views
<?php12final class PhabricatorFilesManagementCycleWorkflow3extends PhabricatorFilesManagementWorkflow {45protected function didConstruct() {6$arguments = $this->newIteratorArguments();7$arguments[] = array(8'name' => 'key',9'param' => 'keyname',10'help' => pht('Select a specific storage key to cycle to.'),11);1213$this14->setName('cycle')15->setSynopsis(16pht('Cycle master key for encrypted files.'))17->setArguments($arguments);18}1920public function execute(PhutilArgumentParser $args) {21$iterator = $this->buildIterator($args);2223$format_map = PhabricatorFileStorageFormat::getAllFormats();24$engines = PhabricatorFileStorageEngine::loadAllEngines();2526$key_name = $args->getArg('key');2728$failed = array();29foreach ($iterator as $file) {30$monogram = $file->getMonogram();3132$engine_key = $file->getStorageEngine();33$engine = idx($engines, $engine_key);3435if (!$engine) {36echo tsprintf(37"%s\n",38pht(39'%s: Uses unknown storage engine "%s".',40$monogram,41$engine_key));42$failed[] = $file;43continue;44}4546if ($engine->isChunkEngine()) {47echo tsprintf(48"%s\n",49pht(50'%s: Stored as chunks, declining to cycle directly.',51$monogram));52continue;53}5455$format_key = $file->getStorageFormat();56if (empty($format_map[$format_key])) {57echo tsprintf(58"%s\n",59pht(60'%s: Uses unknown storage format "%s".',61$monogram,62$format_key));63$failed[] = $file;64continue;65}6667$format = clone $format_map[$format_key];68$format->setFile($file);6970if (!$format->canCycleMasterKey()) {71echo tsprintf(72"%s\n",73pht(74'%s: Storage format ("%s") does not support key cycling.',75$monogram,76$format->getStorageFormatName()));77continue;78}7980echo tsprintf(81"%s\n",82pht(83'%s: Cycling master key.',84$monogram));8586try {87if ($key_name) {88$format->selectMasterKey($key_name);89}9091$file->cycleMasterStorageKey($format);9293echo tsprintf(94"%s\n",95pht('Done.'));96} catch (Exception $ex) {97echo tsprintf(98"%B\n",99pht('Failed! %s', (string)$ex));100$failed[] = $file;101}102}103104if ($failed) {105$monograms = mpull($failed, 'getMonogram');106107echo tsprintf(108"%s\n",109pht('Failures: %s.', implode(', ', $monograms)));110111return 1;112}113114return 0;115}116117}118119120