@@ -29,65 +29,65 @@ |
||
| 29 | 29 | use Symfony\Component\Console\Output\OutputInterface; |
| 30 | 30 | |
| 31 | 31 | class GetConfig extends Base { |
| 32 | - /** * @var IConfig */ |
|
| 33 | - protected $config; |
|
| 32 | + /** * @var IConfig */ |
|
| 33 | + protected $config; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param IConfig $config |
|
| 37 | - */ |
|
| 38 | - public function __construct(IConfig $config) { |
|
| 39 | - parent::__construct(); |
|
| 40 | - $this->config = $config; |
|
| 41 | - } |
|
| 35 | + /** |
|
| 36 | + * @param IConfig $config |
|
| 37 | + */ |
|
| 38 | + public function __construct(IConfig $config) { |
|
| 39 | + parent::__construct(); |
|
| 40 | + $this->config = $config; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - protected function configure() { |
|
| 44 | - parent::configure(); |
|
| 43 | + protected function configure() { |
|
| 44 | + parent::configure(); |
|
| 45 | 45 | |
| 46 | - $this |
|
| 47 | - ->setName('config:app:get') |
|
| 48 | - ->setDescription('Get an app config value') |
|
| 49 | - ->addArgument( |
|
| 50 | - 'app', |
|
| 51 | - InputArgument::REQUIRED, |
|
| 52 | - 'Name of the app' |
|
| 53 | - ) |
|
| 54 | - ->addArgument( |
|
| 55 | - 'name', |
|
| 56 | - InputArgument::REQUIRED, |
|
| 57 | - 'Name of the config to get' |
|
| 58 | - ) |
|
| 59 | - ->addOption( |
|
| 60 | - 'default-value', |
|
| 61 | - null, |
|
| 62 | - InputOption::VALUE_OPTIONAL, |
|
| 63 | - 'If no default value is set and the config does not exist, the command will exit with 1' |
|
| 64 | - ) |
|
| 65 | - ; |
|
| 66 | - } |
|
| 46 | + $this |
|
| 47 | + ->setName('config:app:get') |
|
| 48 | + ->setDescription('Get an app config value') |
|
| 49 | + ->addArgument( |
|
| 50 | + 'app', |
|
| 51 | + InputArgument::REQUIRED, |
|
| 52 | + 'Name of the app' |
|
| 53 | + ) |
|
| 54 | + ->addArgument( |
|
| 55 | + 'name', |
|
| 56 | + InputArgument::REQUIRED, |
|
| 57 | + 'Name of the config to get' |
|
| 58 | + ) |
|
| 59 | + ->addOption( |
|
| 60 | + 'default-value', |
|
| 61 | + null, |
|
| 62 | + InputOption::VALUE_OPTIONAL, |
|
| 63 | + 'If no default value is set and the config does not exist, the command will exit with 1' |
|
| 64 | + ) |
|
| 65 | + ; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Executes the current command. |
|
| 70 | - * |
|
| 71 | - * @param InputInterface $input An InputInterface instance |
|
| 72 | - * @param OutputInterface $output An OutputInterface instance |
|
| 73 | - * @return null|int null or 0 if everything went fine, or an error code |
|
| 74 | - */ |
|
| 75 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 76 | - $appName = $input->getArgument('app'); |
|
| 77 | - $configName = $input->getArgument('name'); |
|
| 78 | - $defaultValue = $input->getOption('default-value'); |
|
| 68 | + /** |
|
| 69 | + * Executes the current command. |
|
| 70 | + * |
|
| 71 | + * @param InputInterface $input An InputInterface instance |
|
| 72 | + * @param OutputInterface $output An OutputInterface instance |
|
| 73 | + * @return null|int null or 0 if everything went fine, or an error code |
|
| 74 | + */ |
|
| 75 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 76 | + $appName = $input->getArgument('app'); |
|
| 77 | + $configName = $input->getArgument('name'); |
|
| 78 | + $defaultValue = $input->getOption('default-value'); |
|
| 79 | 79 | |
| 80 | - if (!in_array($configName, $this->config->getAppKeys($appName)) && !$input->hasParameterOption('--default-value')) { |
|
| 81 | - return 1; |
|
| 82 | - } |
|
| 80 | + if (!in_array($configName, $this->config->getAppKeys($appName)) && !$input->hasParameterOption('--default-value')) { |
|
| 81 | + return 1; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if (!in_array($configName, $this->config->getAppKeys($appName))) { |
|
| 85 | - $configValue = $defaultValue; |
|
| 86 | - } else { |
|
| 87 | - $configValue = $this->config->getAppValue($appName, $configName); |
|
| 88 | - } |
|
| 84 | + if (!in_array($configName, $this->config->getAppKeys($appName))) { |
|
| 85 | + $configValue = $defaultValue; |
|
| 86 | + } else { |
|
| 87 | + $configValue = $this->config->getAppValue($appName, $configName); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $this->writeMixedInOutputFormat($input, $output, $configValue); |
|
| 91 | - return 0; |
|
| 92 | - } |
|
| 90 | + $this->writeMixedInOutputFormat($input, $output, $configValue); |
|
| 91 | + return 0; |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | use Symfony\Component\Console\Input\InputInterface; |
| 33 | 33 | use Symfony\Component\Console\Output\OutputInterface; |
| 34 | 34 | |
| 35 | -class Import extends Command implements CompletionAwareInterface { |
|
| 35 | +class Import extends Command implements CompletionAwareInterface { |
|
| 36 | 36 | protected $validRootKeys = ['system', 'apps']; |
| 37 | 37 | |
| 38 | 38 | /** @var IConfig */ |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | try { |
| 70 | 70 | $configs = $this->validateFileContent($content); |
| 71 | 71 | } catch (\UnexpectedValueException $e) { |
| 72 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
| 72 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
| 73 | 73 | return; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $output->writeln('<info>Config successfully imported from: ' . $importFile . '</info>'); |
|
| 92 | + $output->writeln('<info>Config successfully imported from: '.$importFile.'</info>'); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | $additionalKeys = array_diff($arrayKeys, $this->validRootKeys); |
| 144 | 144 | $commonKeys = array_intersect($arrayKeys, $this->validRootKeys); |
| 145 | 145 | if (!empty($additionalKeys)) { |
| 146 | - throw new \UnexpectedValueException('Found invalid entries in root: ' . implode(', ', $additionalKeys)); |
|
| 146 | + throw new \UnexpectedValueException('Found invalid entries in root: '.implode(', ', $additionalKeys)); |
|
| 147 | 147 | } |
| 148 | 148 | if (empty($commonKeys)) { |
| 149 | - throw new \UnexpectedValueException('At least one key of the following is expected: ' . implode(', ', $this->validRootKeys)); |
|
| 149 | + throw new \UnexpectedValueException('At least one key of the following is expected: '.implode(', ', $this->validRootKeys)); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if (isset($array['system'])) { |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | protected function checkTypeRecursively($configValue, $configName) { |
| 176 | 176 | if (!is_array($configValue) && !is_bool($configValue) && !is_int($configValue) && !is_string($configValue) && !is_null($configValue)) { |
| 177 | - throw new \UnexpectedValueException('Invalid system config value for "' . $configName . '". Only arrays, bools, integers, strings and null (delete) are allowed.'); |
|
| 177 | + throw new \UnexpectedValueException('Invalid system config value for "'.$configName.'". Only arrays, bools, integers, strings and null (delete) are allowed.'); |
|
| 178 | 178 | } |
| 179 | 179 | if (is_array($configValue)) { |
| 180 | 180 | foreach ($configValue as $key => $value) { |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | foreach ($array as $app => $configs) { |
| 193 | 193 | foreach ($configs as $name => $value) { |
| 194 | 194 | if (!is_int($value) && !is_string($value) && !is_null($value)) { |
| 195 | - throw new \UnexpectedValueException('Invalid app config value for "' . $app . '":"' . $name . '". Only integers, strings and null (delete) are allowed.'); |
|
| 195 | + throw new \UnexpectedValueException('Invalid app config value for "'.$app.'":"'.$name.'". Only integers, strings and null (delete) are allowed.'); |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -33,193 +33,193 @@ |
||
| 33 | 33 | use Symfony\Component\Console\Output\OutputInterface; |
| 34 | 34 | |
| 35 | 35 | class Import extends Command implements CompletionAwareInterface { |
| 36 | - protected $validRootKeys = ['system', 'apps']; |
|
| 37 | - |
|
| 38 | - /** @var IConfig */ |
|
| 39 | - protected $config; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param IConfig $config |
|
| 43 | - */ |
|
| 44 | - public function __construct(IConfig $config) { |
|
| 45 | - parent::__construct(); |
|
| 46 | - $this->config = $config; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - protected function configure() { |
|
| 50 | - $this |
|
| 51 | - ->setName('config:import') |
|
| 52 | - ->setDescription('Import a list of configs') |
|
| 53 | - ->addArgument( |
|
| 54 | - 'file', |
|
| 55 | - InputArgument::OPTIONAL, |
|
| 56 | - 'File with the json array to import' |
|
| 57 | - ) |
|
| 58 | - ; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 62 | - $importFile = $input->getArgument('file'); |
|
| 63 | - if ($importFile !== null) { |
|
| 64 | - $content = $this->getArrayFromFile($importFile); |
|
| 65 | - } else { |
|
| 66 | - $content = $this->getArrayFromStdin(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - try { |
|
| 70 | - $configs = $this->validateFileContent($content); |
|
| 71 | - } catch (\UnexpectedValueException $e) { |
|
| 72 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
| 73 | - return; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (!empty($configs['system'])) { |
|
| 77 | - $this->config->setSystemValues($configs['system']); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - if (!empty($configs['apps'])) { |
|
| 81 | - foreach ($configs['apps'] as $app => $appConfigs) { |
|
| 82 | - foreach ($appConfigs as $key => $value) { |
|
| 83 | - if ($value === null) { |
|
| 84 | - $this->config->deleteAppValue($app, $key); |
|
| 85 | - } else { |
|
| 86 | - $this->config->setAppValue($app, $key, $value); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $output->writeln('<info>Config successfully imported from: ' . $importFile . '</info>'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Get the content from stdin ("config:import < file.json") |
|
| 97 | - * |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 100 | - protected function getArrayFromStdin() { |
|
| 101 | - // Read from stdin. stream_set_blocking is used to prevent blocking |
|
| 102 | - // when nothing is passed via stdin. |
|
| 103 | - stream_set_blocking(STDIN, 0); |
|
| 104 | - $content = file_get_contents('php://stdin'); |
|
| 105 | - stream_set_blocking(STDIN, 1); |
|
| 106 | - return $content; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Get the content of the specified file ("config:import file.json") |
|
| 111 | - * |
|
| 112 | - * @param string $importFile |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - protected function getArrayFromFile($importFile) { |
|
| 116 | - return file_get_contents($importFile); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @param string $content |
|
| 121 | - * @return array |
|
| 122 | - * @throws \UnexpectedValueException when the array is invalid |
|
| 123 | - */ |
|
| 124 | - protected function validateFileContent($content) { |
|
| 125 | - $decodedContent = json_decode($content, true); |
|
| 126 | - if (!is_array($decodedContent) || empty($decodedContent)) { |
|
| 127 | - throw new \UnexpectedValueException('The file must contain a valid json array'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $this->validateArray($decodedContent); |
|
| 131 | - |
|
| 132 | - return $decodedContent; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Validates that the array only contains `system` and `apps` |
|
| 137 | - * |
|
| 138 | - * @param array $array |
|
| 139 | - */ |
|
| 140 | - protected function validateArray($array) { |
|
| 141 | - $arrayKeys = array_keys($array); |
|
| 142 | - $additionalKeys = array_diff($arrayKeys, $this->validRootKeys); |
|
| 143 | - $commonKeys = array_intersect($arrayKeys, $this->validRootKeys); |
|
| 144 | - if (!empty($additionalKeys)) { |
|
| 145 | - throw new \UnexpectedValueException('Found invalid entries in root: ' . implode(', ', $additionalKeys)); |
|
| 146 | - } |
|
| 147 | - if (empty($commonKeys)) { |
|
| 148 | - throw new \UnexpectedValueException('At least one key of the following is expected: ' . implode(', ', $this->validRootKeys)); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if (isset($array['system'])) { |
|
| 152 | - if (is_array($array['system'])) { |
|
| 153 | - foreach ($array['system'] as $name => $value) { |
|
| 154 | - $this->checkTypeRecursively($value, $name); |
|
| 155 | - } |
|
| 156 | - } else { |
|
| 157 | - throw new \UnexpectedValueException('The system config array is not an array'); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if (isset($array['apps'])) { |
|
| 162 | - if (is_array($array['apps'])) { |
|
| 163 | - $this->validateAppsArray($array['apps']); |
|
| 164 | - } else { |
|
| 165 | - throw new \UnexpectedValueException('The apps config array is not an array'); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param mixed $configValue |
|
| 172 | - * @param string $configName |
|
| 173 | - */ |
|
| 174 | - protected function checkTypeRecursively($configValue, $configName) { |
|
| 175 | - if (!is_array($configValue) && !is_bool($configValue) && !is_int($configValue) && !is_string($configValue) && !is_null($configValue)) { |
|
| 176 | - throw new \UnexpectedValueException('Invalid system config value for "' . $configName . '". Only arrays, bools, integers, strings and null (delete) are allowed.'); |
|
| 177 | - } |
|
| 178 | - if (is_array($configValue)) { |
|
| 179 | - foreach ($configValue as $key => $value) { |
|
| 180 | - $this->checkTypeRecursively($value, $configName); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Validates that app configs are only integers and strings |
|
| 187 | - * |
|
| 188 | - * @param array $array |
|
| 189 | - */ |
|
| 190 | - protected function validateAppsArray($array) { |
|
| 191 | - foreach ($array as $app => $configs) { |
|
| 192 | - foreach ($configs as $name => $value) { |
|
| 193 | - if (!is_int($value) && !is_string($value) && !is_null($value)) { |
|
| 194 | - throw new \UnexpectedValueException('Invalid app config value for "' . $app . '":"' . $name . '". Only integers, strings and null (delete) are allowed.'); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @param string $optionName |
|
| 202 | - * @param CompletionContext $context |
|
| 203 | - * @return string[] |
|
| 204 | - */ |
|
| 205 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 206 | - return []; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * @param string $argumentName |
|
| 211 | - * @param CompletionContext $context |
|
| 212 | - * @return string[] |
|
| 213 | - */ |
|
| 214 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 215 | - if ($argumentName === 'file') { |
|
| 216 | - $helper = new ShellPathCompletion( |
|
| 217 | - $this->getName(), |
|
| 218 | - 'file', |
|
| 219 | - Completion::TYPE_ARGUMENT |
|
| 220 | - ); |
|
| 221 | - return $helper->run(); |
|
| 222 | - } |
|
| 223 | - return []; |
|
| 224 | - } |
|
| 36 | + protected $validRootKeys = ['system', 'apps']; |
|
| 37 | + |
|
| 38 | + /** @var IConfig */ |
|
| 39 | + protected $config; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param IConfig $config |
|
| 43 | + */ |
|
| 44 | + public function __construct(IConfig $config) { |
|
| 45 | + parent::__construct(); |
|
| 46 | + $this->config = $config; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + protected function configure() { |
|
| 50 | + $this |
|
| 51 | + ->setName('config:import') |
|
| 52 | + ->setDescription('Import a list of configs') |
|
| 53 | + ->addArgument( |
|
| 54 | + 'file', |
|
| 55 | + InputArgument::OPTIONAL, |
|
| 56 | + 'File with the json array to import' |
|
| 57 | + ) |
|
| 58 | + ; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 62 | + $importFile = $input->getArgument('file'); |
|
| 63 | + if ($importFile !== null) { |
|
| 64 | + $content = $this->getArrayFromFile($importFile); |
|
| 65 | + } else { |
|
| 66 | + $content = $this->getArrayFromStdin(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + try { |
|
| 70 | + $configs = $this->validateFileContent($content); |
|
| 71 | + } catch (\UnexpectedValueException $e) { |
|
| 72 | + $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
| 73 | + return; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (!empty($configs['system'])) { |
|
| 77 | + $this->config->setSystemValues($configs['system']); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + if (!empty($configs['apps'])) { |
|
| 81 | + foreach ($configs['apps'] as $app => $appConfigs) { |
|
| 82 | + foreach ($appConfigs as $key => $value) { |
|
| 83 | + if ($value === null) { |
|
| 84 | + $this->config->deleteAppValue($app, $key); |
|
| 85 | + } else { |
|
| 86 | + $this->config->setAppValue($app, $key, $value); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $output->writeln('<info>Config successfully imported from: ' . $importFile . '</info>'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Get the content from stdin ("config:import < file.json") |
|
| 97 | + * |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | + protected function getArrayFromStdin() { |
|
| 101 | + // Read from stdin. stream_set_blocking is used to prevent blocking |
|
| 102 | + // when nothing is passed via stdin. |
|
| 103 | + stream_set_blocking(STDIN, 0); |
|
| 104 | + $content = file_get_contents('php://stdin'); |
|
| 105 | + stream_set_blocking(STDIN, 1); |
|
| 106 | + return $content; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Get the content of the specified file ("config:import file.json") |
|
| 111 | + * |
|
| 112 | + * @param string $importFile |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + protected function getArrayFromFile($importFile) { |
|
| 116 | + return file_get_contents($importFile); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @param string $content |
|
| 121 | + * @return array |
|
| 122 | + * @throws \UnexpectedValueException when the array is invalid |
|
| 123 | + */ |
|
| 124 | + protected function validateFileContent($content) { |
|
| 125 | + $decodedContent = json_decode($content, true); |
|
| 126 | + if (!is_array($decodedContent) || empty($decodedContent)) { |
|
| 127 | + throw new \UnexpectedValueException('The file must contain a valid json array'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $this->validateArray($decodedContent); |
|
| 131 | + |
|
| 132 | + return $decodedContent; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Validates that the array only contains `system` and `apps` |
|
| 137 | + * |
|
| 138 | + * @param array $array |
|
| 139 | + */ |
|
| 140 | + protected function validateArray($array) { |
|
| 141 | + $arrayKeys = array_keys($array); |
|
| 142 | + $additionalKeys = array_diff($arrayKeys, $this->validRootKeys); |
|
| 143 | + $commonKeys = array_intersect($arrayKeys, $this->validRootKeys); |
|
| 144 | + if (!empty($additionalKeys)) { |
|
| 145 | + throw new \UnexpectedValueException('Found invalid entries in root: ' . implode(', ', $additionalKeys)); |
|
| 146 | + } |
|
| 147 | + if (empty($commonKeys)) { |
|
| 148 | + throw new \UnexpectedValueException('At least one key of the following is expected: ' . implode(', ', $this->validRootKeys)); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if (isset($array['system'])) { |
|
| 152 | + if (is_array($array['system'])) { |
|
| 153 | + foreach ($array['system'] as $name => $value) { |
|
| 154 | + $this->checkTypeRecursively($value, $name); |
|
| 155 | + } |
|
| 156 | + } else { |
|
| 157 | + throw new \UnexpectedValueException('The system config array is not an array'); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if (isset($array['apps'])) { |
|
| 162 | + if (is_array($array['apps'])) { |
|
| 163 | + $this->validateAppsArray($array['apps']); |
|
| 164 | + } else { |
|
| 165 | + throw new \UnexpectedValueException('The apps config array is not an array'); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param mixed $configValue |
|
| 172 | + * @param string $configName |
|
| 173 | + */ |
|
| 174 | + protected function checkTypeRecursively($configValue, $configName) { |
|
| 175 | + if (!is_array($configValue) && !is_bool($configValue) && !is_int($configValue) && !is_string($configValue) && !is_null($configValue)) { |
|
| 176 | + throw new \UnexpectedValueException('Invalid system config value for "' . $configName . '". Only arrays, bools, integers, strings and null (delete) are allowed.'); |
|
| 177 | + } |
|
| 178 | + if (is_array($configValue)) { |
|
| 179 | + foreach ($configValue as $key => $value) { |
|
| 180 | + $this->checkTypeRecursively($value, $configName); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Validates that app configs are only integers and strings |
|
| 187 | + * |
|
| 188 | + * @param array $array |
|
| 189 | + */ |
|
| 190 | + protected function validateAppsArray($array) { |
|
| 191 | + foreach ($array as $app => $configs) { |
|
| 192 | + foreach ($configs as $name => $value) { |
|
| 193 | + if (!is_int($value) && !is_string($value) && !is_null($value)) { |
|
| 194 | + throw new \UnexpectedValueException('Invalid app config value for "' . $app . '":"' . $name . '". Only integers, strings and null (delete) are allowed.'); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @param string $optionName |
|
| 202 | + * @param CompletionContext $context |
|
| 203 | + * @return string[] |
|
| 204 | + */ |
|
| 205 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 206 | + return []; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * @param string $argumentName |
|
| 211 | + * @param CompletionContext $context |
|
| 212 | + * @return string[] |
|
| 213 | + */ |
|
| 214 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 215 | + if ($argumentName === 'file') { |
|
| 216 | + $helper = new ShellPathCompletion( |
|
| 217 | + $this->getName(), |
|
| 218 | + 'file', |
|
| 219 | + Completion::TYPE_ARGUMENT |
|
| 220 | + ); |
|
| 221 | + return $helper->run(); |
|
| 222 | + } |
|
| 223 | + return []; |
|
| 224 | + } |
|
| 225 | 225 | } |
@@ -28,23 +28,23 @@ |
||
| 28 | 28 | use Symfony\Component\Console\Output\OutputInterface; |
| 29 | 29 | |
| 30 | 30 | class Status extends Base { |
| 31 | - protected function configure() { |
|
| 32 | - parent::configure(); |
|
| 31 | + protected function configure() { |
|
| 32 | + parent::configure(); |
|
| 33 | 33 | |
| 34 | - $this |
|
| 35 | - ->setName('status') |
|
| 36 | - ->setDescription('show some status information') |
|
| 37 | - ; |
|
| 38 | - } |
|
| 34 | + $this |
|
| 35 | + ->setName('status') |
|
| 36 | + ->setDescription('show some status information') |
|
| 37 | + ; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 41 | - $values = array( |
|
| 42 | - 'installed' => (bool) \OC::$server->getConfig()->getSystemValue('installed', false), |
|
| 43 | - 'version' => implode('.', \OCP\Util::getVersion()), |
|
| 44 | - 'versionstring' => \OC_Util::getVersionString(), |
|
| 45 | - 'edition' => '', |
|
| 46 | - ); |
|
| 40 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 41 | + $values = array( |
|
| 42 | + 'installed' => (bool) \OC::$server->getConfig()->getSystemValue('installed', false), |
|
| 43 | + 'version' => implode('.', \OCP\Util::getVersion()), |
|
| 44 | + 'versionstring' => \OC_Util::getVersionString(), |
|
| 45 | + 'edition' => '', |
|
| 46 | + ); |
|
| 47 | 47 | |
| 48 | - $this->writeArrayInOutputFormat($input, $output, $values); |
|
| 49 | - } |
|
| 48 | + $this->writeArrayInOutputFormat($input, $output, $values); |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -30,35 +30,35 @@ |
||
| 30 | 30 | |
| 31 | 31 | class Enable extends Base { |
| 32 | 32 | |
| 33 | - /** @var Manager */ |
|
| 34 | - private $manager; |
|
| 33 | + /** @var Manager */ |
|
| 34 | + private $manager; |
|
| 35 | 35 | |
| 36 | - /** @var IUserManager */ |
|
| 37 | - protected $userManager; |
|
| 36 | + /** @var IUserManager */ |
|
| 37 | + protected $userManager; |
|
| 38 | 38 | |
| 39 | - public function __construct(Manager $manager, IUserManager $userManager) { |
|
| 40 | - parent::__construct('twofactorauth:enable'); |
|
| 41 | - $this->manager = $manager; |
|
| 42 | - $this->userManager = $userManager; |
|
| 43 | - } |
|
| 39 | + public function __construct(Manager $manager, IUserManager $userManager) { |
|
| 40 | + parent::__construct('twofactorauth:enable'); |
|
| 41 | + $this->manager = $manager; |
|
| 42 | + $this->userManager = $userManager; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - protected function configure() { |
|
| 46 | - parent::configure(); |
|
| 45 | + protected function configure() { |
|
| 46 | + parent::configure(); |
|
| 47 | 47 | |
| 48 | - $this->setName('twofactorauth:enable'); |
|
| 49 | - $this->setDescription('Enable two-factor authentication for a user'); |
|
| 50 | - $this->addArgument('uid', InputArgument::REQUIRED); |
|
| 51 | - } |
|
| 48 | + $this->setName('twofactorauth:enable'); |
|
| 49 | + $this->setDescription('Enable two-factor authentication for a user'); |
|
| 50 | + $this->addArgument('uid', InputArgument::REQUIRED); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 54 | - $uid = $input->getArgument('uid'); |
|
| 55 | - $user = $this->userManager->get($uid); |
|
| 56 | - if (is_null($user)) { |
|
| 57 | - $output->writeln("<error>Invalid UID</error>"); |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - $this->manager->enableTwoFactorAuthentication($user); |
|
| 61 | - $output->writeln("Two-factor authentication enabled for user $uid"); |
|
| 62 | - } |
|
| 53 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 54 | + $uid = $input->getArgument('uid'); |
|
| 55 | + $user = $this->userManager->get($uid); |
|
| 56 | + if (is_null($user)) { |
|
| 57 | + $output->writeln("<error>Invalid UID</error>"); |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + $this->manager->enableTwoFactorAuthentication($user); |
|
| 61 | + $output->writeln("Two-factor authentication enabled for user $uid"); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | } |
@@ -30,35 +30,35 @@ |
||
| 30 | 30 | |
| 31 | 31 | class Disable extends Base { |
| 32 | 32 | |
| 33 | - /** @var Manager */ |
|
| 34 | - private $manager; |
|
| 33 | + /** @var Manager */ |
|
| 34 | + private $manager; |
|
| 35 | 35 | |
| 36 | - /** @var IUserManager */ |
|
| 37 | - protected $userManager; |
|
| 36 | + /** @var IUserManager */ |
|
| 37 | + protected $userManager; |
|
| 38 | 38 | |
| 39 | - public function __construct(Manager $manager, IUserManager $userManager) { |
|
| 40 | - parent::__construct('twofactorauth:disable'); |
|
| 41 | - $this->manager = $manager; |
|
| 42 | - $this->userManager = $userManager; |
|
| 43 | - } |
|
| 39 | + public function __construct(Manager $manager, IUserManager $userManager) { |
|
| 40 | + parent::__construct('twofactorauth:disable'); |
|
| 41 | + $this->manager = $manager; |
|
| 42 | + $this->userManager = $userManager; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - protected function configure() { |
|
| 46 | - parent::configure(); |
|
| 45 | + protected function configure() { |
|
| 46 | + parent::configure(); |
|
| 47 | 47 | |
| 48 | - $this->setName('twofactorauth:disable'); |
|
| 49 | - $this->setDescription('Disable two-factor authentication for a user'); |
|
| 50 | - $this->addArgument('uid', InputArgument::REQUIRED); |
|
| 51 | - } |
|
| 48 | + $this->setName('twofactorauth:disable'); |
|
| 49 | + $this->setDescription('Disable two-factor authentication for a user'); |
|
| 50 | + $this->addArgument('uid', InputArgument::REQUIRED); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 54 | - $uid = $input->getArgument('uid'); |
|
| 55 | - $user = $this->userManager->get($uid); |
|
| 56 | - if (is_null($user)) { |
|
| 57 | - $output->writeln("<error>Invalid UID</error>"); |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - $this->manager->disableTwoFactorAuthentication($user); |
|
| 61 | - $output->writeln("Two-factor authentication disabled for user $uid"); |
|
| 62 | - } |
|
| 53 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 54 | + $uid = $input->getArgument('uid'); |
|
| 55 | + $user = $this->userManager->get($uid); |
|
| 56 | + if (is_null($user)) { |
|
| 57 | + $output->writeln("<error>Invalid UID</error>"); |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + $this->manager->disableTwoFactorAuthentication($user); |
|
| 61 | + $output->writeln("Two-factor authentication disabled for user $uid"); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | } |
@@ -30,25 +30,25 @@ |
||
| 30 | 30 | |
| 31 | 31 | class DataFingerprint extends Command { |
| 32 | 32 | |
| 33 | - /** @var IConfig */ |
|
| 34 | - protected $config; |
|
| 35 | - /** @var ITimeFactory */ |
|
| 36 | - protected $timeFactory; |
|
| 33 | + /** @var IConfig */ |
|
| 34 | + protected $config; |
|
| 35 | + /** @var ITimeFactory */ |
|
| 36 | + protected $timeFactory; |
|
| 37 | 37 | |
| 38 | - public function __construct(IConfig $config, |
|
| 39 | - ITimeFactory $timeFactory) { |
|
| 40 | - $this->config = $config; |
|
| 41 | - $this->timeFactory = $timeFactory; |
|
| 42 | - parent::__construct(); |
|
| 43 | - } |
|
| 38 | + public function __construct(IConfig $config, |
|
| 39 | + ITimeFactory $timeFactory) { |
|
| 40 | + $this->config = $config; |
|
| 41 | + $this->timeFactory = $timeFactory; |
|
| 42 | + parent::__construct(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - protected function configure() { |
|
| 46 | - $this |
|
| 47 | - ->setName('maintenance:data-fingerprint') |
|
| 48 | - ->setDescription('update the systems data-fingerprint after a backup is restored'); |
|
| 49 | - } |
|
| 45 | + protected function configure() { |
|
| 46 | + $this |
|
| 47 | + ->setName('maintenance:data-fingerprint') |
|
| 48 | + ->setDescription('update the systems data-fingerprint after a backup is restored'); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 52 | - $this->config->setSystemValue('data-fingerprint', md5($this->timeFactory->getTime())); |
|
| 53 | - } |
|
| 51 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 52 | + $this->config->setSystemValue('data-fingerprint', md5($this->timeFactory->getTime())); |
|
| 53 | + } |
|
| 54 | 54 | } |
@@ -132,16 +132,16 @@ |
||
| 132 | 132 | $this->output->writeln(''); |
| 133 | 133 | break; |
| 134 | 134 | case '\OC\Repair::step': |
| 135 | - $this->output->writeln(' - ' . $event->getArgument(0)); |
|
| 135 | + $this->output->writeln(' - '.$event->getArgument(0)); |
|
| 136 | 136 | break; |
| 137 | 137 | case '\OC\Repair::info': |
| 138 | - $this->output->writeln(' - ' . $event->getArgument(0)); |
|
| 138 | + $this->output->writeln(' - '.$event->getArgument(0)); |
|
| 139 | 139 | break; |
| 140 | 140 | case '\OC\Repair::warning': |
| 141 | - $this->output->writeln(' - WARNING: ' . $event->getArgument(0)); |
|
| 141 | + $this->output->writeln(' - WARNING: '.$event->getArgument(0)); |
|
| 142 | 142 | break; |
| 143 | 143 | case '\OC\Repair::error': |
| 144 | - $this->output->writeln(' - ERROR: ' . $event->getArgument(0)); |
|
| 144 | + $this->output->writeln(' - ERROR: '.$event->getArgument(0)); |
|
| 145 | 145 | break; |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -38,116 +38,116 @@ |
||
| 38 | 38 | use Symfony\Component\EventDispatcher\GenericEvent; |
| 39 | 39 | |
| 40 | 40 | class Repair extends Command { |
| 41 | - /** @var \OC\Repair $repair */ |
|
| 42 | - protected $repair; |
|
| 43 | - /** @var IConfig */ |
|
| 44 | - protected $config; |
|
| 45 | - /** @var EventDispatcherInterface */ |
|
| 46 | - private $dispatcher; |
|
| 47 | - /** @var ProgressBar */ |
|
| 48 | - private $progress; |
|
| 49 | - /** @var OutputInterface */ |
|
| 50 | - private $output; |
|
| 51 | - /** @var IAppManager */ |
|
| 52 | - private $appManager; |
|
| 41 | + /** @var \OC\Repair $repair */ |
|
| 42 | + protected $repair; |
|
| 43 | + /** @var IConfig */ |
|
| 44 | + protected $config; |
|
| 45 | + /** @var EventDispatcherInterface */ |
|
| 46 | + private $dispatcher; |
|
| 47 | + /** @var ProgressBar */ |
|
| 48 | + private $progress; |
|
| 49 | + /** @var OutputInterface */ |
|
| 50 | + private $output; |
|
| 51 | + /** @var IAppManager */ |
|
| 52 | + private $appManager; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param \OC\Repair $repair |
|
| 56 | - * @param IConfig $config |
|
| 57 | - * @param EventDispatcherInterface $dispatcher |
|
| 58 | - * @param IAppManager $appManager |
|
| 59 | - */ |
|
| 60 | - public function __construct(\OC\Repair $repair, IConfig $config, EventDispatcherInterface $dispatcher, IAppManager $appManager) { |
|
| 61 | - $this->repair = $repair; |
|
| 62 | - $this->config = $config; |
|
| 63 | - $this->dispatcher = $dispatcher; |
|
| 64 | - $this->appManager = $appManager; |
|
| 65 | - parent::__construct(); |
|
| 66 | - } |
|
| 54 | + /** |
|
| 55 | + * @param \OC\Repair $repair |
|
| 56 | + * @param IConfig $config |
|
| 57 | + * @param EventDispatcherInterface $dispatcher |
|
| 58 | + * @param IAppManager $appManager |
|
| 59 | + */ |
|
| 60 | + public function __construct(\OC\Repair $repair, IConfig $config, EventDispatcherInterface $dispatcher, IAppManager $appManager) { |
|
| 61 | + $this->repair = $repair; |
|
| 62 | + $this->config = $config; |
|
| 63 | + $this->dispatcher = $dispatcher; |
|
| 64 | + $this->appManager = $appManager; |
|
| 65 | + parent::__construct(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - protected function configure() { |
|
| 69 | - $this |
|
| 70 | - ->setName('maintenance:repair') |
|
| 71 | - ->setDescription('repair this installation') |
|
| 72 | - ->addOption( |
|
| 73 | - 'include-expensive', |
|
| 74 | - null, |
|
| 75 | - InputOption::VALUE_NONE, |
|
| 76 | - 'Use this option when you want to include resource and load expensive tasks'); |
|
| 77 | - } |
|
| 68 | + protected function configure() { |
|
| 69 | + $this |
|
| 70 | + ->setName('maintenance:repair') |
|
| 71 | + ->setDescription('repair this installation') |
|
| 72 | + ->addOption( |
|
| 73 | + 'include-expensive', |
|
| 74 | + null, |
|
| 75 | + InputOption::VALUE_NONE, |
|
| 76 | + 'Use this option when you want to include resource and load expensive tasks'); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 80 | - $includeExpensive = $input->getOption('include-expensive'); |
|
| 81 | - if ($includeExpensive) { |
|
| 82 | - foreach ($this->repair->getExpensiveRepairSteps() as $step) { |
|
| 83 | - $this->repair->addStep($step); |
|
| 84 | - } |
|
| 85 | - } |
|
| 79 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 80 | + $includeExpensive = $input->getOption('include-expensive'); |
|
| 81 | + if ($includeExpensive) { |
|
| 82 | + foreach ($this->repair->getExpensiveRepairSteps() as $step) { |
|
| 83 | + $this->repair->addStep($step); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - $apps = $this->appManager->getInstalledApps(); |
|
| 88 | - foreach ($apps as $app) { |
|
| 89 | - if (!$this->appManager->isEnabledForUser($app)) { |
|
| 90 | - continue; |
|
| 91 | - } |
|
| 92 | - $info = \OC_App::getAppInfo($app); |
|
| 93 | - if (!is_array($info)) { |
|
| 94 | - continue; |
|
| 95 | - } |
|
| 96 | - $steps = $info['repair-steps']['post-migration']; |
|
| 97 | - foreach ($steps as $step) { |
|
| 98 | - try { |
|
| 99 | - $this->repair->addStep($step); |
|
| 100 | - } catch (Exception $ex) { |
|
| 101 | - $output->writeln("<error>Failed to load repair step for $app: {$ex->getMessage()}</error>"); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - } |
|
| 87 | + $apps = $this->appManager->getInstalledApps(); |
|
| 88 | + foreach ($apps as $app) { |
|
| 89 | + if (!$this->appManager->isEnabledForUser($app)) { |
|
| 90 | + continue; |
|
| 91 | + } |
|
| 92 | + $info = \OC_App::getAppInfo($app); |
|
| 93 | + if (!is_array($info)) { |
|
| 94 | + continue; |
|
| 95 | + } |
|
| 96 | + $steps = $info['repair-steps']['post-migration']; |
|
| 97 | + foreach ($steps as $step) { |
|
| 98 | + try { |
|
| 99 | + $this->repair->addStep($step); |
|
| 100 | + } catch (Exception $ex) { |
|
| 101 | + $output->writeln("<error>Failed to load repair step for $app: {$ex->getMessage()}</error>"); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - $maintenanceMode = $this->config->getSystemValue('maintenance', false); |
|
| 107 | - $this->config->setSystemValue('maintenance', true); |
|
| 106 | + $maintenanceMode = $this->config->getSystemValue('maintenance', false); |
|
| 107 | + $this->config->setSystemValue('maintenance', true); |
|
| 108 | 108 | |
| 109 | - $this->progress = new ProgressBar($output); |
|
| 110 | - $this->output = $output; |
|
| 111 | - $this->dispatcher->addListener('\OC\Repair::startProgress', [$this, 'handleRepairFeedBack']); |
|
| 112 | - $this->dispatcher->addListener('\OC\Repair::advance', [$this, 'handleRepairFeedBack']); |
|
| 113 | - $this->dispatcher->addListener('\OC\Repair::finishProgress', [$this, 'handleRepairFeedBack']); |
|
| 114 | - $this->dispatcher->addListener('\OC\Repair::step', [$this, 'handleRepairFeedBack']); |
|
| 115 | - $this->dispatcher->addListener('\OC\Repair::info', [$this, 'handleRepairFeedBack']); |
|
| 116 | - $this->dispatcher->addListener('\OC\Repair::warning', [$this, 'handleRepairFeedBack']); |
|
| 117 | - $this->dispatcher->addListener('\OC\Repair::error', [$this, 'handleRepairFeedBack']); |
|
| 109 | + $this->progress = new ProgressBar($output); |
|
| 110 | + $this->output = $output; |
|
| 111 | + $this->dispatcher->addListener('\OC\Repair::startProgress', [$this, 'handleRepairFeedBack']); |
|
| 112 | + $this->dispatcher->addListener('\OC\Repair::advance', [$this, 'handleRepairFeedBack']); |
|
| 113 | + $this->dispatcher->addListener('\OC\Repair::finishProgress', [$this, 'handleRepairFeedBack']); |
|
| 114 | + $this->dispatcher->addListener('\OC\Repair::step', [$this, 'handleRepairFeedBack']); |
|
| 115 | + $this->dispatcher->addListener('\OC\Repair::info', [$this, 'handleRepairFeedBack']); |
|
| 116 | + $this->dispatcher->addListener('\OC\Repair::warning', [$this, 'handleRepairFeedBack']); |
|
| 117 | + $this->dispatcher->addListener('\OC\Repair::error', [$this, 'handleRepairFeedBack']); |
|
| 118 | 118 | |
| 119 | - $this->repair->run(); |
|
| 119 | + $this->repair->run(); |
|
| 120 | 120 | |
| 121 | - $this->config->setSystemValue('maintenance', $maintenanceMode); |
|
| 122 | - } |
|
| 121 | + $this->config->setSystemValue('maintenance', $maintenanceMode); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - public function handleRepairFeedBack($event) { |
|
| 125 | - if (!$event instanceof GenericEvent) { |
|
| 126 | - return; |
|
| 127 | - } |
|
| 128 | - switch ($event->getSubject()) { |
|
| 129 | - case '\OC\Repair::startProgress': |
|
| 130 | - $this->progress->start($event->getArgument(0)); |
|
| 131 | - break; |
|
| 132 | - case '\OC\Repair::advance': |
|
| 133 | - $this->progress->advance($event->getArgument(0)); |
|
| 134 | - break; |
|
| 135 | - case '\OC\Repair::finishProgress': |
|
| 136 | - $this->progress->finish(); |
|
| 137 | - $this->output->writeln(''); |
|
| 138 | - break; |
|
| 139 | - case '\OC\Repair::step': |
|
| 140 | - $this->output->writeln(' - ' . $event->getArgument(0)); |
|
| 141 | - break; |
|
| 142 | - case '\OC\Repair::info': |
|
| 143 | - $this->output->writeln(' - ' . $event->getArgument(0)); |
|
| 144 | - break; |
|
| 145 | - case '\OC\Repair::warning': |
|
| 146 | - $this->output->writeln(' - WARNING: ' . $event->getArgument(0)); |
|
| 147 | - break; |
|
| 148 | - case '\OC\Repair::error': |
|
| 149 | - $this->output->writeln(' - ERROR: ' . $event->getArgument(0)); |
|
| 150 | - break; |
|
| 151 | - } |
|
| 152 | - } |
|
| 124 | + public function handleRepairFeedBack($event) { |
|
| 125 | + if (!$event instanceof GenericEvent) { |
|
| 126 | + return; |
|
| 127 | + } |
|
| 128 | + switch ($event->getSubject()) { |
|
| 129 | + case '\OC\Repair::startProgress': |
|
| 130 | + $this->progress->start($event->getArgument(0)); |
|
| 131 | + break; |
|
| 132 | + case '\OC\Repair::advance': |
|
| 133 | + $this->progress->advance($event->getArgument(0)); |
|
| 134 | + break; |
|
| 135 | + case '\OC\Repair::finishProgress': |
|
| 136 | + $this->progress->finish(); |
|
| 137 | + $this->output->writeln(''); |
|
| 138 | + break; |
|
| 139 | + case '\OC\Repair::step': |
|
| 140 | + $this->output->writeln(' - ' . $event->getArgument(0)); |
|
| 141 | + break; |
|
| 142 | + case '\OC\Repair::info': |
|
| 143 | + $this->output->writeln(' - ' . $event->getArgument(0)); |
|
| 144 | + break; |
|
| 145 | + case '\OC\Repair::warning': |
|
| 146 | + $this->output->writeln(' - WARNING: ' . $event->getArgument(0)); |
|
| 147 | + break; |
|
| 148 | + case '\OC\Repair::error': |
|
| 149 | + $this->output->writeln(' - ERROR: ' . $event->getArgument(0)); |
|
| 150 | + break; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -32,67 +32,67 @@ |
||
| 32 | 32 | |
| 33 | 33 | class UpdateDB extends Command { |
| 34 | 34 | |
| 35 | - const DEFAULT_MIMETYPE = 'application/octet-stream'; |
|
| 35 | + const DEFAULT_MIMETYPE = 'application/octet-stream'; |
|
| 36 | 36 | |
| 37 | - /** @var IMimeTypeDetector */ |
|
| 38 | - protected $mimetypeDetector; |
|
| 37 | + /** @var IMimeTypeDetector */ |
|
| 38 | + protected $mimetypeDetector; |
|
| 39 | 39 | |
| 40 | - /** @var IMimeTypeLoader */ |
|
| 41 | - protected $mimetypeLoader; |
|
| 40 | + /** @var IMimeTypeLoader */ |
|
| 41 | + protected $mimetypeLoader; |
|
| 42 | 42 | |
| 43 | - public function __construct( |
|
| 44 | - IMimeTypeDetector $mimetypeDetector, |
|
| 45 | - IMimeTypeLoader $mimetypeLoader |
|
| 46 | - ) { |
|
| 47 | - parent::__construct(); |
|
| 48 | - $this->mimetypeDetector = $mimetypeDetector; |
|
| 49 | - $this->mimetypeLoader = $mimetypeLoader; |
|
| 50 | - } |
|
| 43 | + public function __construct( |
|
| 44 | + IMimeTypeDetector $mimetypeDetector, |
|
| 45 | + IMimeTypeLoader $mimetypeLoader |
|
| 46 | + ) { |
|
| 47 | + parent::__construct(); |
|
| 48 | + $this->mimetypeDetector = $mimetypeDetector; |
|
| 49 | + $this->mimetypeLoader = $mimetypeLoader; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - protected function configure() { |
|
| 53 | - $this |
|
| 54 | - ->setName('maintenance:mimetype:update-db') |
|
| 55 | - ->setDescription('Update database mimetypes and update filecache') |
|
| 56 | - ->addOption( |
|
| 57 | - 'repair-filecache', |
|
| 58 | - null, |
|
| 59 | - InputOption::VALUE_NONE, |
|
| 60 | - 'Repair filecache for all mimetypes, not just new ones' |
|
| 61 | - ) |
|
| 62 | - ; |
|
| 63 | - } |
|
| 52 | + protected function configure() { |
|
| 53 | + $this |
|
| 54 | + ->setName('maintenance:mimetype:update-db') |
|
| 55 | + ->setDescription('Update database mimetypes and update filecache') |
|
| 56 | + ->addOption( |
|
| 57 | + 'repair-filecache', |
|
| 58 | + null, |
|
| 59 | + InputOption::VALUE_NONE, |
|
| 60 | + 'Repair filecache for all mimetypes, not just new ones' |
|
| 61 | + ) |
|
| 62 | + ; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 66 | - $mappings = $this->mimetypeDetector->getAllMappings(); |
|
| 65 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 66 | + $mappings = $this->mimetypeDetector->getAllMappings(); |
|
| 67 | 67 | |
| 68 | - $totalFilecacheUpdates = 0; |
|
| 69 | - $totalNewMimetypes = 0; |
|
| 68 | + $totalFilecacheUpdates = 0; |
|
| 69 | + $totalNewMimetypes = 0; |
|
| 70 | 70 | |
| 71 | - foreach ($mappings as $ext => $mimetypes) { |
|
| 72 | - if ($ext[0] === '_') { |
|
| 73 | - // comment |
|
| 74 | - continue; |
|
| 75 | - } |
|
| 76 | - $mimetype = $mimetypes[0]; |
|
| 77 | - $existing = $this->mimetypeLoader->exists($mimetype); |
|
| 78 | - // this will add the mimetype if it didn't exist |
|
| 79 | - $mimetypeId = $this->mimetypeLoader->getId($mimetype); |
|
| 71 | + foreach ($mappings as $ext => $mimetypes) { |
|
| 72 | + if ($ext[0] === '_') { |
|
| 73 | + // comment |
|
| 74 | + continue; |
|
| 75 | + } |
|
| 76 | + $mimetype = $mimetypes[0]; |
|
| 77 | + $existing = $this->mimetypeLoader->exists($mimetype); |
|
| 78 | + // this will add the mimetype if it didn't exist |
|
| 79 | + $mimetypeId = $this->mimetypeLoader->getId($mimetype); |
|
| 80 | 80 | |
| 81 | - if (!$existing) { |
|
| 82 | - $output->writeln('Added mimetype "'.$mimetype.'" to database'); |
|
| 83 | - $totalNewMimetypes++; |
|
| 84 | - } |
|
| 81 | + if (!$existing) { |
|
| 82 | + $output->writeln('Added mimetype "'.$mimetype.'" to database'); |
|
| 83 | + $totalNewMimetypes++; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - if (!$existing || $input->getOption('repair-filecache')) { |
|
| 87 | - $touchedFilecacheRows = $this->mimetypeLoader->updateFilecache($ext, $mimetypeId); |
|
| 88 | - if ($touchedFilecacheRows > 0) { |
|
| 89 | - $output->writeln('Updated '.$touchedFilecacheRows.' filecache rows for mimetype "'.$mimetype.'"'); |
|
| 90 | - } |
|
| 91 | - $totalFilecacheUpdates += $touchedFilecacheRows; |
|
| 92 | - } |
|
| 93 | - } |
|
| 86 | + if (!$existing || $input->getOption('repair-filecache')) { |
|
| 87 | + $touchedFilecacheRows = $this->mimetypeLoader->updateFilecache($ext, $mimetypeId); |
|
| 88 | + if ($touchedFilecacheRows > 0) { |
|
| 89 | + $output->writeln('Updated '.$touchedFilecacheRows.' filecache rows for mimetype "'.$mimetype.'"'); |
|
| 90 | + } |
|
| 91 | + $totalFilecacheUpdates += $touchedFilecacheRows; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - $output->writeln('Added '.$totalNewMimetypes.' new mimetypes'); |
|
| 96 | - $output->writeln('Updated '.$totalFilecacheUpdates.' filecache rows'); |
|
| 97 | - } |
|
| 95 | + $output->writeln('Added '.$totalNewMimetypes.' new mimetypes'); |
|
| 96 | + $output->writeln('Updated '.$totalFilecacheUpdates.' filecache rows'); |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -32,82 +32,82 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | class UpdateJS extends Command { |
| 34 | 34 | |
| 35 | - /** @var IMimeTypeDetector */ |
|
| 36 | - protected $mimetypeDetector; |
|
| 37 | - |
|
| 38 | - public function __construct( |
|
| 39 | - IMimeTypeDetector $mimetypeDetector |
|
| 40 | - ) { |
|
| 41 | - parent::__construct(); |
|
| 42 | - $this->mimetypeDetector = $mimetypeDetector; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - protected function configure() { |
|
| 46 | - $this |
|
| 47 | - ->setName('maintenance:mimetype:update-js') |
|
| 48 | - ->setDescription('Update mimetypelist.js'); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 52 | - // Fetch all the aliases |
|
| 53 | - $aliases = $this->mimetypeDetector->getAllAliases(); |
|
| 54 | - |
|
| 55 | - // Remove comments |
|
| 56 | - $keys = array_filter(array_keys($aliases), function($k) { |
|
| 57 | - return $k[0] === '_'; |
|
| 58 | - }); |
|
| 59 | - foreach($keys as $key) { |
|
| 60 | - unset($aliases[$key]); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // Fetch all files |
|
| 64 | - $dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes'); |
|
| 65 | - |
|
| 66 | - $files = []; |
|
| 67 | - foreach($dir as $fileInfo) { |
|
| 68 | - if ($fileInfo->isFile()) { |
|
| 69 | - $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); |
|
| 70 | - $files[] = $file; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - //Remove duplicates |
|
| 75 | - $files = array_values(array_unique($files)); |
|
| 76 | - sort($files); |
|
| 77 | - |
|
| 78 | - // Fetch all themes! |
|
| 79 | - $themes = []; |
|
| 80 | - $dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/'); |
|
| 81 | - foreach($dirs as $dir) { |
|
| 82 | - //Valid theme dir |
|
| 83 | - if ($dir->isFile() || $dir->isDot()) { |
|
| 84 | - continue; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $theme = $dir->getFilename(); |
|
| 88 | - $themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/'; |
|
| 89 | - // Check if this theme has its own filetype icons |
|
| 90 | - if (!file_exists($themeDir)) { |
|
| 91 | - continue; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $themes[$theme] = []; |
|
| 95 | - // Fetch all the theme icons! |
|
| 96 | - $themeIt = new \DirectoryIterator($themeDir); |
|
| 97 | - foreach ($themeIt as $fileInfo) { |
|
| 98 | - if ($fileInfo->isFile()) { |
|
| 99 | - $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); |
|
| 100 | - $themes[$theme][] = $file; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - //Remove Duplicates |
|
| 105 | - $themes[$theme] = array_values(array_unique($themes[$theme])); |
|
| 106 | - sort($themes[$theme]); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - //Generate the JS |
|
| 110 | - $js = '/** |
|
| 35 | + /** @var IMimeTypeDetector */ |
|
| 36 | + protected $mimetypeDetector; |
|
| 37 | + |
|
| 38 | + public function __construct( |
|
| 39 | + IMimeTypeDetector $mimetypeDetector |
|
| 40 | + ) { |
|
| 41 | + parent::__construct(); |
|
| 42 | + $this->mimetypeDetector = $mimetypeDetector; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + protected function configure() { |
|
| 46 | + $this |
|
| 47 | + ->setName('maintenance:mimetype:update-js') |
|
| 48 | + ->setDescription('Update mimetypelist.js'); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 52 | + // Fetch all the aliases |
|
| 53 | + $aliases = $this->mimetypeDetector->getAllAliases(); |
|
| 54 | + |
|
| 55 | + // Remove comments |
|
| 56 | + $keys = array_filter(array_keys($aliases), function($k) { |
|
| 57 | + return $k[0] === '_'; |
|
| 58 | + }); |
|
| 59 | + foreach($keys as $key) { |
|
| 60 | + unset($aliases[$key]); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // Fetch all files |
|
| 64 | + $dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes'); |
|
| 65 | + |
|
| 66 | + $files = []; |
|
| 67 | + foreach($dir as $fileInfo) { |
|
| 68 | + if ($fileInfo->isFile()) { |
|
| 69 | + $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); |
|
| 70 | + $files[] = $file; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + //Remove duplicates |
|
| 75 | + $files = array_values(array_unique($files)); |
|
| 76 | + sort($files); |
|
| 77 | + |
|
| 78 | + // Fetch all themes! |
|
| 79 | + $themes = []; |
|
| 80 | + $dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/'); |
|
| 81 | + foreach($dirs as $dir) { |
|
| 82 | + //Valid theme dir |
|
| 83 | + if ($dir->isFile() || $dir->isDot()) { |
|
| 84 | + continue; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $theme = $dir->getFilename(); |
|
| 88 | + $themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/'; |
|
| 89 | + // Check if this theme has its own filetype icons |
|
| 90 | + if (!file_exists($themeDir)) { |
|
| 91 | + continue; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $themes[$theme] = []; |
|
| 95 | + // Fetch all the theme icons! |
|
| 96 | + $themeIt = new \DirectoryIterator($themeDir); |
|
| 97 | + foreach ($themeIt as $fileInfo) { |
|
| 98 | + if ($fileInfo->isFile()) { |
|
| 99 | + $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); |
|
| 100 | + $themes[$theme][] = $file; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + //Remove Duplicates |
|
| 105 | + $themes[$theme] = array_values(array_unique($themes[$theme])); |
|
| 106 | + sort($themes[$theme]); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + //Generate the JS |
|
| 110 | + $js = '/** |
|
| 111 | 111 | * This file is automatically generated |
| 112 | 112 | * DO NOT EDIT MANUALLY! |
| 113 | 113 | * |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | }; |
| 123 | 123 | '; |
| 124 | 124 | |
| 125 | - //Output the JS |
|
| 126 | - file_put_contents(\OC::$SERVERROOT.'/core/js/mimetypelist.js', $js); |
|
| 125 | + //Output the JS |
|
| 126 | + file_put_contents(\OC::$SERVERROOT.'/core/js/mimetypelist.js', $js); |
|
| 127 | 127 | |
| 128 | - $output->writeln('<info>mimetypelist.js is updated'); |
|
| 129 | - } |
|
| 128 | + $output->writeln('<info>mimetypelist.js is updated'); |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $keys = array_filter(array_keys($aliases), function($k) { |
| 57 | 57 | return $k[0] === '_'; |
| 58 | 58 | }); |
| 59 | - foreach($keys as $key) { |
|
| 59 | + foreach ($keys as $key) { |
|
| 60 | 60 | unset($aliases[$key]); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes'); |
| 65 | 65 | |
| 66 | 66 | $files = []; |
| 67 | - foreach($dir as $fileInfo) { |
|
| 67 | + foreach ($dir as $fileInfo) { |
|
| 68 | 68 | if ($fileInfo->isFile()) { |
| 69 | 69 | $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); |
| 70 | 70 | $files[] = $file; |
@@ -78,14 +78,14 @@ discard block |
||
| 78 | 78 | // Fetch all themes! |
| 79 | 79 | $themes = []; |
| 80 | 80 | $dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/'); |
| 81 | - foreach($dirs as $dir) { |
|
| 81 | + foreach ($dirs as $dir) { |
|
| 82 | 82 | //Valid theme dir |
| 83 | 83 | if ($dir->isFile() || $dir->isDot()) { |
| 84 | 84 | continue; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $theme = $dir->getFilename(); |
| 88 | - $themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/'; |
|
| 88 | + $themeDir = $dir->getPath().'/'.$theme.'/core/img/filetypes/'; |
|
| 89 | 89 | // Check if this theme has its own filetype icons |
| 90 | 90 | if (!file_exists($themeDir)) { |
| 91 | 91 | continue; |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * To regenerate this file run ./occ maintenance:mimetype:update-js |
| 117 | 117 | */ |
| 118 | 118 | OC.MimeTypeList={ |
| 119 | - aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ', |
|
| 120 | - files: ' . json_encode($files, JSON_PRETTY_PRINT) . ', |
|
| 121 | - themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . ' |
|
| 119 | + aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).', |
|
| 120 | + files: ' . json_encode($files, JSON_PRETTY_PRINT).', |
|
| 121 | + themes: ' . json_encode($themes, JSON_PRETTY_PRINT).' |
|
| 122 | 122 | }; |
| 123 | 123 | '; |
| 124 | 124 | |