Conditions | 4 |
Paths | 6 |
Total Lines | 25 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | public function run() |
||
18 | { |
||
19 | $module = $this->controller->module; |
||
20 | $newKeyName = $this->controller->keyName; |
||
21 | |||
22 | if (empty($newKeyName)) { |
||
23 | $newKeyName = $module->getEncryptor()->getDefaultKeyName(); |
||
24 | } |
||
25 | |||
26 | if (!$module->getEncryptor()->hasKey($newKeyName)) { |
||
27 | throw new InvalidArgumentException('No key with name "' . $newKeyName . '" available.'); |
||
28 | } |
||
29 | |||
30 | if ($this->controller->confirm('Rotate all encryption keys to key "' . $newKeyName . '"?')) { |
||
31 | $result = $module->rotateStorageEncryptionKeys($newKeyName); |
||
32 | |||
33 | $this->controller->stdout("Updated models:" . PHP_EOL); |
||
34 | $this->controller->stdout(Table::widget([ |
||
35 | 'headers' => ['Model', 'Num Updated'], |
||
36 | 'rows' => array_map(fn($model) => [$model, $result[$model]], array_keys($result)), |
||
37 | ])); |
||
38 | $this->controller->stdout('Successfully rotated encryption keys.' . PHP_EOL, Console::FG_GREEN); |
||
39 | } |
||
40 | |||
41 | return ExitCode::OK; |
||
42 | } |
||
44 |