@@ -32,158 +32,158 @@ |
||
| 32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
| 33 | 33 | |
| 34 | 34 | class Base extends Command implements CompletionAwareInterface { |
| 35 | - const OUTPUT_FORMAT_PLAIN = 'plain'; |
|
| 36 | - const OUTPUT_FORMAT_JSON = 'json'; |
|
| 37 | - const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty'; |
|
| 38 | - |
|
| 39 | - protected $defaultOutputFormat = self::OUTPUT_FORMAT_PLAIN; |
|
| 40 | - |
|
| 41 | - /** @var boolean */ |
|
| 42 | - private $php_pcntl_signal = false; |
|
| 43 | - |
|
| 44 | - /** @var boolean */ |
|
| 45 | - private $interrupted = false; |
|
| 46 | - |
|
| 47 | - protected function configure() { |
|
| 48 | - $this |
|
| 49 | - ->addOption( |
|
| 50 | - 'output', |
|
| 51 | - null, |
|
| 52 | - InputOption::VALUE_OPTIONAL, |
|
| 53 | - 'Output format (plain, json or json_pretty, default is plain)', |
|
| 54 | - $this->defaultOutputFormat |
|
| 55 | - ) |
|
| 56 | - ; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param InputInterface $input |
|
| 61 | - * @param OutputInterface $output |
|
| 62 | - * @param array $items |
|
| 63 | - * @param string $prefix |
|
| 64 | - */ |
|
| 65 | - protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') { |
|
| 66 | - switch ($input->getOption('output')) { |
|
| 67 | - case self::OUTPUT_FORMAT_JSON: |
|
| 68 | - $output->writeln(json_encode($items)); |
|
| 69 | - break; |
|
| 70 | - case self::OUTPUT_FORMAT_JSON_PRETTY: |
|
| 71 | - $output->writeln(json_encode($items, JSON_PRETTY_PRINT)); |
|
| 72 | - break; |
|
| 73 | - default: |
|
| 74 | - foreach ($items as $key => $item) { |
|
| 75 | - if (is_array($item)) { |
|
| 76 | - $output->writeln($prefix . $key . ':'); |
|
| 77 | - $this->writeArrayInOutputFormat($input, $output, $item, ' ' . $prefix); |
|
| 78 | - continue; |
|
| 79 | - } |
|
| 80 | - if (!is_int($key) || ListCommand::class === get_class($this)) { |
|
| 81 | - $value = $this->valueToString($item); |
|
| 82 | - if (!is_null($value)) { |
|
| 83 | - $output->writeln($prefix . $key . ': ' . $value); |
|
| 84 | - } else { |
|
| 85 | - $output->writeln($prefix . $key); |
|
| 86 | - } |
|
| 87 | - } else { |
|
| 88 | - $output->writeln($prefix . $this->valueToString($item)); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - break; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @param InputInterface $input |
|
| 97 | - * @param OutputInterface $output |
|
| 98 | - * @param mixed $item |
|
| 99 | - */ |
|
| 100 | - protected function writeMixedInOutputFormat(InputInterface $input, OutputInterface $output, $item) { |
|
| 101 | - if (is_array($item)) { |
|
| 102 | - $this->writeArrayInOutputFormat($input, $output, $item, ''); |
|
| 103 | - return; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - switch ($input->getOption('output')) { |
|
| 107 | - case self::OUTPUT_FORMAT_JSON: |
|
| 108 | - $output->writeln(json_encode($item)); |
|
| 109 | - break; |
|
| 110 | - case self::OUTPUT_FORMAT_JSON_PRETTY: |
|
| 111 | - $output->writeln(json_encode($item, JSON_PRETTY_PRINT)); |
|
| 112 | - break; |
|
| 113 | - default: |
|
| 114 | - $output->writeln($this->valueToString($item, false)); |
|
| 115 | - break; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - protected function valueToString($value, $returnNull = true) { |
|
| 120 | - if ($value === false) { |
|
| 121 | - return 'false'; |
|
| 122 | - } else if ($value === true) { |
|
| 123 | - return 'true'; |
|
| 124 | - } else if ($value === null) { |
|
| 125 | - return $returnNull ? null : 'null'; |
|
| 126 | - } else { |
|
| 127 | - return $value; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Throw InterruptedException when interrupted by user |
|
| 133 | - * |
|
| 134 | - * @throws InterruptedException |
|
| 135 | - */ |
|
| 136 | - protected function abortIfInterrupted() { |
|
| 137 | - if ($this->php_pcntl_signal === false) { |
|
| 138 | - return; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - pcntl_signal_dispatch(); |
|
| 142 | - |
|
| 143 | - if ($this->interrupted === true) { |
|
| 144 | - throw new InterruptedException('Command interrupted by user'); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Changes the status of the command to "interrupted" if ctrl-c has been pressed |
|
| 150 | - * |
|
| 151 | - * Gives a chance to the command to properly terminate what it's doing |
|
| 152 | - */ |
|
| 153 | - protected function cancelOperation() { |
|
| 154 | - $this->interrupted = true; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - public function run(InputInterface $input, OutputInterface $output) { |
|
| 158 | - // check if the php pcntl_signal functions are accessible |
|
| 159 | - $this->php_pcntl_signal = function_exists('pcntl_signal'); |
|
| 160 | - if ($this->php_pcntl_signal) { |
|
| 161 | - // Collect interrupts and notify the running command |
|
| 162 | - pcntl_signal(SIGTERM, [$this, 'cancelOperation']); |
|
| 163 | - pcntl_signal(SIGINT, [$this, 'cancelOperation']); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - return parent::run($input, $output); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param string $optionName |
|
| 171 | - * @param CompletionContext $context |
|
| 172 | - * @return string[] |
|
| 173 | - */ |
|
| 174 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 175 | - if ($optionName === 'output') { |
|
| 176 | - return ['plain', 'json', 'json_pretty']; |
|
| 177 | - } |
|
| 178 | - return []; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * @param string $argumentName |
|
| 183 | - * @param CompletionContext $context |
|
| 184 | - * @return string[] |
|
| 185 | - */ |
|
| 186 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 187 | - return []; |
|
| 188 | - } |
|
| 35 | + const OUTPUT_FORMAT_PLAIN = 'plain'; |
|
| 36 | + const OUTPUT_FORMAT_JSON = 'json'; |
|
| 37 | + const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty'; |
|
| 38 | + |
|
| 39 | + protected $defaultOutputFormat = self::OUTPUT_FORMAT_PLAIN; |
|
| 40 | + |
|
| 41 | + /** @var boolean */ |
|
| 42 | + private $php_pcntl_signal = false; |
|
| 43 | + |
|
| 44 | + /** @var boolean */ |
|
| 45 | + private $interrupted = false; |
|
| 46 | + |
|
| 47 | + protected function configure() { |
|
| 48 | + $this |
|
| 49 | + ->addOption( |
|
| 50 | + 'output', |
|
| 51 | + null, |
|
| 52 | + InputOption::VALUE_OPTIONAL, |
|
| 53 | + 'Output format (plain, json or json_pretty, default is plain)', |
|
| 54 | + $this->defaultOutputFormat |
|
| 55 | + ) |
|
| 56 | + ; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param InputInterface $input |
|
| 61 | + * @param OutputInterface $output |
|
| 62 | + * @param array $items |
|
| 63 | + * @param string $prefix |
|
| 64 | + */ |
|
| 65 | + protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') { |
|
| 66 | + switch ($input->getOption('output')) { |
|
| 67 | + case self::OUTPUT_FORMAT_JSON: |
|
| 68 | + $output->writeln(json_encode($items)); |
|
| 69 | + break; |
|
| 70 | + case self::OUTPUT_FORMAT_JSON_PRETTY: |
|
| 71 | + $output->writeln(json_encode($items, JSON_PRETTY_PRINT)); |
|
| 72 | + break; |
|
| 73 | + default: |
|
| 74 | + foreach ($items as $key => $item) { |
|
| 75 | + if (is_array($item)) { |
|
| 76 | + $output->writeln($prefix . $key . ':'); |
|
| 77 | + $this->writeArrayInOutputFormat($input, $output, $item, ' ' . $prefix); |
|
| 78 | + continue; |
|
| 79 | + } |
|
| 80 | + if (!is_int($key) || ListCommand::class === get_class($this)) { |
|
| 81 | + $value = $this->valueToString($item); |
|
| 82 | + if (!is_null($value)) { |
|
| 83 | + $output->writeln($prefix . $key . ': ' . $value); |
|
| 84 | + } else { |
|
| 85 | + $output->writeln($prefix . $key); |
|
| 86 | + } |
|
| 87 | + } else { |
|
| 88 | + $output->writeln($prefix . $this->valueToString($item)); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + break; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @param InputInterface $input |
|
| 97 | + * @param OutputInterface $output |
|
| 98 | + * @param mixed $item |
|
| 99 | + */ |
|
| 100 | + protected function writeMixedInOutputFormat(InputInterface $input, OutputInterface $output, $item) { |
|
| 101 | + if (is_array($item)) { |
|
| 102 | + $this->writeArrayInOutputFormat($input, $output, $item, ''); |
|
| 103 | + return; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + switch ($input->getOption('output')) { |
|
| 107 | + case self::OUTPUT_FORMAT_JSON: |
|
| 108 | + $output->writeln(json_encode($item)); |
|
| 109 | + break; |
|
| 110 | + case self::OUTPUT_FORMAT_JSON_PRETTY: |
|
| 111 | + $output->writeln(json_encode($item, JSON_PRETTY_PRINT)); |
|
| 112 | + break; |
|
| 113 | + default: |
|
| 114 | + $output->writeln($this->valueToString($item, false)); |
|
| 115 | + break; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + protected function valueToString($value, $returnNull = true) { |
|
| 120 | + if ($value === false) { |
|
| 121 | + return 'false'; |
|
| 122 | + } else if ($value === true) { |
|
| 123 | + return 'true'; |
|
| 124 | + } else if ($value === null) { |
|
| 125 | + return $returnNull ? null : 'null'; |
|
| 126 | + } else { |
|
| 127 | + return $value; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Throw InterruptedException when interrupted by user |
|
| 133 | + * |
|
| 134 | + * @throws InterruptedException |
|
| 135 | + */ |
|
| 136 | + protected function abortIfInterrupted() { |
|
| 137 | + if ($this->php_pcntl_signal === false) { |
|
| 138 | + return; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + pcntl_signal_dispatch(); |
|
| 142 | + |
|
| 143 | + if ($this->interrupted === true) { |
|
| 144 | + throw new InterruptedException('Command interrupted by user'); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Changes the status of the command to "interrupted" if ctrl-c has been pressed |
|
| 150 | + * |
|
| 151 | + * Gives a chance to the command to properly terminate what it's doing |
|
| 152 | + */ |
|
| 153 | + protected function cancelOperation() { |
|
| 154 | + $this->interrupted = true; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + public function run(InputInterface $input, OutputInterface $output) { |
|
| 158 | + // check if the php pcntl_signal functions are accessible |
|
| 159 | + $this->php_pcntl_signal = function_exists('pcntl_signal'); |
|
| 160 | + if ($this->php_pcntl_signal) { |
|
| 161 | + // Collect interrupts and notify the running command |
|
| 162 | + pcntl_signal(SIGTERM, [$this, 'cancelOperation']); |
|
| 163 | + pcntl_signal(SIGINT, [$this, 'cancelOperation']); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + return parent::run($input, $output); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param string $optionName |
|
| 171 | + * @param CompletionContext $context |
|
| 172 | + * @return string[] |
|
| 173 | + */ |
|
| 174 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 175 | + if ($optionName === 'output') { |
|
| 176 | + return ['plain', 'json', 'json_pretty']; |
|
| 177 | + } |
|
| 178 | + return []; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * @param string $argumentName |
|
| 183 | + * @param CompletionContext $context |
|
| 184 | + * @return string[] |
|
| 185 | + */ |
|
| 186 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 187 | + return []; |
|
| 188 | + } |
|
| 189 | 189 | } |
@@ -39,258 +39,258 @@ |
||
| 39 | 39 | |
| 40 | 40 | class ScanAppData extends Base { |
| 41 | 41 | |
| 42 | - /** @var IRootFolder */ |
|
| 43 | - protected $root; |
|
| 44 | - /** @var IConfig */ |
|
| 45 | - protected $config; |
|
| 46 | - /** @var float */ |
|
| 47 | - protected $execTime = 0; |
|
| 48 | - /** @var int */ |
|
| 49 | - protected $foldersCounter = 0; |
|
| 50 | - /** @var int */ |
|
| 51 | - protected $filesCounter = 0; |
|
| 42 | + /** @var IRootFolder */ |
|
| 43 | + protected $root; |
|
| 44 | + /** @var IConfig */ |
|
| 45 | + protected $config; |
|
| 46 | + /** @var float */ |
|
| 47 | + protected $execTime = 0; |
|
| 48 | + /** @var int */ |
|
| 49 | + protected $foldersCounter = 0; |
|
| 50 | + /** @var int */ |
|
| 51 | + protected $filesCounter = 0; |
|
| 52 | 52 | |
| 53 | - public function __construct(IRootFolder $rootFolder, IConfig $config) { |
|
| 54 | - parent::__construct(); |
|
| 53 | + public function __construct(IRootFolder $rootFolder, IConfig $config) { |
|
| 54 | + parent::__construct(); |
|
| 55 | 55 | |
| 56 | - $this->root = $rootFolder; |
|
| 57 | - $this->config = $config; |
|
| 58 | - } |
|
| 56 | + $this->root = $rootFolder; |
|
| 57 | + $this->config = $config; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - protected function configure() { |
|
| 61 | - parent::configure(); |
|
| 60 | + protected function configure() { |
|
| 61 | + parent::configure(); |
|
| 62 | 62 | |
| 63 | - $this |
|
| 64 | - ->setName('files:scan-app-data') |
|
| 65 | - ->setDescription('rescan the AppData folder') |
|
| 66 | - ->addOption( |
|
| 67 | - 'quiet', |
|
| 68 | - 'q', |
|
| 69 | - InputOption::VALUE_NONE, |
|
| 70 | - 'suppress any output' |
|
| 71 | - ) |
|
| 72 | - ->addOption( |
|
| 73 | - 'verbose', |
|
| 74 | - '-v|vv|vvv', |
|
| 75 | - InputOption::VALUE_NONE, |
|
| 76 | - 'verbose the output' |
|
| 77 | - ); |
|
| 78 | - } |
|
| 63 | + $this |
|
| 64 | + ->setName('files:scan-app-data') |
|
| 65 | + ->setDescription('rescan the AppData folder') |
|
| 66 | + ->addOption( |
|
| 67 | + 'quiet', |
|
| 68 | + 'q', |
|
| 69 | + InputOption::VALUE_NONE, |
|
| 70 | + 'suppress any output' |
|
| 71 | + ) |
|
| 72 | + ->addOption( |
|
| 73 | + 'verbose', |
|
| 74 | + '-v|vv|vvv', |
|
| 75 | + InputOption::VALUE_NONE, |
|
| 76 | + 'verbose the output' |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - public function checkScanWarning($fullPath, OutputInterface $output) { |
|
| 81 | - $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath)); |
|
| 82 | - $path = basename($fullPath); |
|
| 80 | + public function checkScanWarning($fullPath, OutputInterface $output) { |
|
| 81 | + $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath)); |
|
| 82 | + $path = basename($fullPath); |
|
| 83 | 83 | |
| 84 | - if ($normalizedPath !== $path) { |
|
| 85 | - $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
| 86 | - } |
|
| 87 | - } |
|
| 84 | + if ($normalizedPath !== $path) { |
|
| 85 | + $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - protected function scanFiles($verbose, OutputInterface $output) { |
|
| 90 | - try { |
|
| 91 | - $appData = $this->getAppDataFolder(); |
|
| 92 | - } catch (NotFoundException $e) { |
|
| 93 | - $output->writeln('NoAppData folder found'); |
|
| 94 | - return; |
|
| 95 | - } |
|
| 89 | + protected function scanFiles($verbose, OutputInterface $output) { |
|
| 90 | + try { |
|
| 91 | + $appData = $this->getAppDataFolder(); |
|
| 92 | + } catch (NotFoundException $e) { |
|
| 93 | + $output->writeln('NoAppData folder found'); |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - $connection = $this->reconnectToDatabase($output); |
|
| 98 | - $scanner = new \OC\Files\Utils\Scanner(null, $connection, \OC::$server->getLogger()); |
|
| 99 | - # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
| 100 | - # printout and count |
|
| 101 | - if ($verbose) { |
|
| 102 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 103 | - $output->writeln("\tFile <info>$path</info>"); |
|
| 104 | - $this->filesCounter += 1; |
|
| 105 | - $this->abortIfInterrupted(); |
|
| 106 | - }); |
|
| 107 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 108 | - $output->writeln("\tFolder <info>$path</info>"); |
|
| 109 | - $this->foldersCounter += 1; |
|
| 110 | - $this->abortIfInterrupted(); |
|
| 111 | - }); |
|
| 112 | - $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
| 113 | - $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')'); |
|
| 114 | - }); |
|
| 115 | - # count only |
|
| 116 | - } else { |
|
| 117 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) { |
|
| 118 | - $this->filesCounter += 1; |
|
| 119 | - $this->abortIfInterrupted(); |
|
| 120 | - }); |
|
| 121 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { |
|
| 122 | - $this->foldersCounter += 1; |
|
| 123 | - $this->abortIfInterrupted(); |
|
| 124 | - }); |
|
| 125 | - } |
|
| 126 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { |
|
| 127 | - $this->checkScanWarning($path, $output); |
|
| 128 | - }); |
|
| 129 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { |
|
| 130 | - $this->checkScanWarning($path, $output); |
|
| 131 | - }); |
|
| 97 | + $connection = $this->reconnectToDatabase($output); |
|
| 98 | + $scanner = new \OC\Files\Utils\Scanner(null, $connection, \OC::$server->getLogger()); |
|
| 99 | + # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
| 100 | + # printout and count |
|
| 101 | + if ($verbose) { |
|
| 102 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 103 | + $output->writeln("\tFile <info>$path</info>"); |
|
| 104 | + $this->filesCounter += 1; |
|
| 105 | + $this->abortIfInterrupted(); |
|
| 106 | + }); |
|
| 107 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 108 | + $output->writeln("\tFolder <info>$path</info>"); |
|
| 109 | + $this->foldersCounter += 1; |
|
| 110 | + $this->abortIfInterrupted(); |
|
| 111 | + }); |
|
| 112 | + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
| 113 | + $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')'); |
|
| 114 | + }); |
|
| 115 | + # count only |
|
| 116 | + } else { |
|
| 117 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) { |
|
| 118 | + $this->filesCounter += 1; |
|
| 119 | + $this->abortIfInterrupted(); |
|
| 120 | + }); |
|
| 121 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { |
|
| 122 | + $this->foldersCounter += 1; |
|
| 123 | + $this->abortIfInterrupted(); |
|
| 124 | + }); |
|
| 125 | + } |
|
| 126 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { |
|
| 127 | + $this->checkScanWarning($path, $output); |
|
| 128 | + }); |
|
| 129 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { |
|
| 130 | + $this->checkScanWarning($path, $output); |
|
| 131 | + }); |
|
| 132 | 132 | |
| 133 | - try { |
|
| 134 | - $scanner->scan($appData->getPath()); |
|
| 135 | - } catch (ForbiddenException $e) { |
|
| 136 | - $output->writeln("<error>Storage not writable</error>"); |
|
| 137 | - $output->writeln('Make sure you\'re running the scan command only as the user the web server runs as'); |
|
| 138 | - } catch (InterruptedException $e) { |
|
| 139 | - # exit the function if ctrl-c has been pressed |
|
| 140 | - $output->writeln('Interrupted by user'); |
|
| 141 | - } catch (NotFoundException $e) { |
|
| 142 | - $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
| 143 | - } catch (\Exception $e) { |
|
| 144 | - $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
| 145 | - $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
| 146 | - } |
|
| 147 | - } |
|
| 133 | + try { |
|
| 134 | + $scanner->scan($appData->getPath()); |
|
| 135 | + } catch (ForbiddenException $e) { |
|
| 136 | + $output->writeln("<error>Storage not writable</error>"); |
|
| 137 | + $output->writeln('Make sure you\'re running the scan command only as the user the web server runs as'); |
|
| 138 | + } catch (InterruptedException $e) { |
|
| 139 | + # exit the function if ctrl-c has been pressed |
|
| 140 | + $output->writeln('Interrupted by user'); |
|
| 141 | + } catch (NotFoundException $e) { |
|
| 142 | + $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
| 143 | + } catch (\Exception $e) { |
|
| 144 | + $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
| 145 | + $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | |
| 150 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 151 | - # no messaging level option means: no full printout but statistics |
|
| 152 | - # $quiet means no print at all |
|
| 153 | - # $verbose means full printout including statistics |
|
| 154 | - # -q -v full stat |
|
| 155 | - # 0 0 no yes |
|
| 156 | - # 0 1 yes yes |
|
| 157 | - # 1 -- no no (quiet overrules verbose) |
|
| 158 | - $verbose = $input->getOption('verbose'); |
|
| 159 | - $quiet = $input->getOption('quiet'); |
|
| 160 | - # restrict the verbosity level to VERBOSITY_VERBOSE |
|
| 161 | - if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
| 162 | - $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
| 163 | - } |
|
| 164 | - if ($quiet) { |
|
| 165 | - $verbose = false; |
|
| 166 | - } |
|
| 150 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 151 | + # no messaging level option means: no full printout but statistics |
|
| 152 | + # $quiet means no print at all |
|
| 153 | + # $verbose means full printout including statistics |
|
| 154 | + # -q -v full stat |
|
| 155 | + # 0 0 no yes |
|
| 156 | + # 0 1 yes yes |
|
| 157 | + # 1 -- no no (quiet overrules verbose) |
|
| 158 | + $verbose = $input->getOption('verbose'); |
|
| 159 | + $quiet = $input->getOption('quiet'); |
|
| 160 | + # restrict the verbosity level to VERBOSITY_VERBOSE |
|
| 161 | + if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
| 162 | + $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
| 163 | + } |
|
| 164 | + if ($quiet) { |
|
| 165 | + $verbose = false; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - $output->writeln("\nScanning AppData for files"); |
|
| 168 | + $output->writeln("\nScanning AppData for files"); |
|
| 169 | 169 | |
| 170 | - $this->initTools(); |
|
| 170 | + $this->initTools(); |
|
| 171 | 171 | |
| 172 | - $this->scanFiles($verbose, $output); |
|
| 172 | + $this->scanFiles($verbose, $output); |
|
| 173 | 173 | |
| 174 | - # stat: printout statistics if $quiet was not set |
|
| 175 | - if (!$quiet) { |
|
| 176 | - $this->presentStats($output); |
|
| 177 | - } |
|
| 178 | - } |
|
| 174 | + # stat: printout statistics if $quiet was not set |
|
| 175 | + if (!$quiet) { |
|
| 176 | + $this->presentStats($output); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Initialises some useful tools for the Command |
|
| 182 | - */ |
|
| 183 | - protected function initTools() { |
|
| 184 | - // Start the timer |
|
| 185 | - $this->execTime = -microtime(true); |
|
| 186 | - // Convert PHP errors to exceptions |
|
| 187 | - set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
| 188 | - } |
|
| 180 | + /** |
|
| 181 | + * Initialises some useful tools for the Command |
|
| 182 | + */ |
|
| 183 | + protected function initTools() { |
|
| 184 | + // Start the timer |
|
| 185 | + $this->execTime = -microtime(true); |
|
| 186 | + // Convert PHP errors to exceptions |
|
| 187 | + set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
| 192 | - * |
|
| 193 | - * @see https://secure.php.net/manual/en/function.set-error-handler.php |
|
| 194 | - * |
|
| 195 | - * @param int $severity the level of the error raised |
|
| 196 | - * @param string $message |
|
| 197 | - * @param string $file the filename that the error was raised in |
|
| 198 | - * @param int $line the line number the error was raised |
|
| 199 | - * |
|
| 200 | - * @throws \ErrorException |
|
| 201 | - */ |
|
| 202 | - public function exceptionErrorHandler($severity, $message, $file, $line) { |
|
| 203 | - if (!(error_reporting() & $severity)) { |
|
| 204 | - // This error code is not included in error_reporting |
|
| 205 | - return; |
|
| 206 | - } |
|
| 207 | - throw new \ErrorException($message, 0, $severity, $file, $line); |
|
| 208 | - } |
|
| 190 | + /** |
|
| 191 | + * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
| 192 | + * |
|
| 193 | + * @see https://secure.php.net/manual/en/function.set-error-handler.php |
|
| 194 | + * |
|
| 195 | + * @param int $severity the level of the error raised |
|
| 196 | + * @param string $message |
|
| 197 | + * @param string $file the filename that the error was raised in |
|
| 198 | + * @param int $line the line number the error was raised |
|
| 199 | + * |
|
| 200 | + * @throws \ErrorException |
|
| 201 | + */ |
|
| 202 | + public function exceptionErrorHandler($severity, $message, $file, $line) { |
|
| 203 | + if (!(error_reporting() & $severity)) { |
|
| 204 | + // This error code is not included in error_reporting |
|
| 205 | + return; |
|
| 206 | + } |
|
| 207 | + throw new \ErrorException($message, 0, $severity, $file, $line); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * @param OutputInterface $output |
|
| 212 | - */ |
|
| 213 | - protected function presentStats(OutputInterface $output) { |
|
| 214 | - // Stop the timer |
|
| 215 | - $this->execTime += microtime(true); |
|
| 216 | - $output->writeln(""); |
|
| 210 | + /** |
|
| 211 | + * @param OutputInterface $output |
|
| 212 | + */ |
|
| 213 | + protected function presentStats(OutputInterface $output) { |
|
| 214 | + // Stop the timer |
|
| 215 | + $this->execTime += microtime(true); |
|
| 216 | + $output->writeln(""); |
|
| 217 | 217 | |
| 218 | - $headers = [ |
|
| 219 | - 'Folders', 'Files', 'Elapsed time' |
|
| 220 | - ]; |
|
| 218 | + $headers = [ |
|
| 219 | + 'Folders', 'Files', 'Elapsed time' |
|
| 220 | + ]; |
|
| 221 | 221 | |
| 222 | - $this->showSummary($headers, null, $output); |
|
| 223 | - } |
|
| 222 | + $this->showSummary($headers, null, $output); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Shows a summary of operations |
|
| 227 | - * |
|
| 228 | - * @param string[] $headers |
|
| 229 | - * @param string[] $rows |
|
| 230 | - * @param OutputInterface $output |
|
| 231 | - */ |
|
| 232 | - protected function showSummary($headers, $rows, OutputInterface $output) { |
|
| 233 | - $niceDate = $this->formatExecTime(); |
|
| 234 | - if (!$rows) { |
|
| 235 | - $rows = [ |
|
| 236 | - $this->foldersCounter, |
|
| 237 | - $this->filesCounter, |
|
| 238 | - $niceDate, |
|
| 239 | - ]; |
|
| 240 | - } |
|
| 241 | - $table = new Table($output); |
|
| 242 | - $table |
|
| 243 | - ->setHeaders($headers) |
|
| 244 | - ->setRows([$rows]); |
|
| 245 | - $table->render(); |
|
| 246 | - } |
|
| 225 | + /** |
|
| 226 | + * Shows a summary of operations |
|
| 227 | + * |
|
| 228 | + * @param string[] $headers |
|
| 229 | + * @param string[] $rows |
|
| 230 | + * @param OutputInterface $output |
|
| 231 | + */ |
|
| 232 | + protected function showSummary($headers, $rows, OutputInterface $output) { |
|
| 233 | + $niceDate = $this->formatExecTime(); |
|
| 234 | + if (!$rows) { |
|
| 235 | + $rows = [ |
|
| 236 | + $this->foldersCounter, |
|
| 237 | + $this->filesCounter, |
|
| 238 | + $niceDate, |
|
| 239 | + ]; |
|
| 240 | + } |
|
| 241 | + $table = new Table($output); |
|
| 242 | + $table |
|
| 243 | + ->setHeaders($headers) |
|
| 244 | + ->setRows([$rows]); |
|
| 245 | + $table->render(); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * Formats microtime into a human readable format |
|
| 251 | - * |
|
| 252 | - * @return string |
|
| 253 | - */ |
|
| 254 | - protected function formatExecTime() { |
|
| 255 | - list($secs, ) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 249 | + /** |
|
| 250 | + * Formats microtime into a human readable format |
|
| 251 | + * |
|
| 252 | + * @return string |
|
| 253 | + */ |
|
| 254 | + protected function formatExecTime() { |
|
| 255 | + list($secs, ) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 256 | 256 | |
| 257 | - # if you want to have microseconds add this: . '.' . $tens; |
|
| 258 | - return date('H:i:s', $secs); |
|
| 259 | - } |
|
| 257 | + # if you want to have microseconds add this: . '.' . $tens; |
|
| 258 | + return date('H:i:s', $secs); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * @return \OCP\IDBConnection |
|
| 263 | - */ |
|
| 264 | - protected function reconnectToDatabase(OutputInterface $output) { |
|
| 265 | - /** @var Connection | IDBConnection $connection*/ |
|
| 266 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 267 | - try { |
|
| 268 | - $connection->close(); |
|
| 269 | - } catch (\Exception $ex) { |
|
| 270 | - $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
| 271 | - } |
|
| 272 | - while (!$connection->isConnected()) { |
|
| 273 | - try { |
|
| 274 | - $connection->connect(); |
|
| 275 | - } catch (\Exception $ex) { |
|
| 276 | - $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
| 277 | - sleep(60); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - return $connection; |
|
| 281 | - } |
|
| 261 | + /** |
|
| 262 | + * @return \OCP\IDBConnection |
|
| 263 | + */ |
|
| 264 | + protected function reconnectToDatabase(OutputInterface $output) { |
|
| 265 | + /** @var Connection | IDBConnection $connection*/ |
|
| 266 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 267 | + try { |
|
| 268 | + $connection->close(); |
|
| 269 | + } catch (\Exception $ex) { |
|
| 270 | + $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
| 271 | + } |
|
| 272 | + while (!$connection->isConnected()) { |
|
| 273 | + try { |
|
| 274 | + $connection->connect(); |
|
| 275 | + } catch (\Exception $ex) { |
|
| 276 | + $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
| 277 | + sleep(60); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + return $connection; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * @return \OCP\Files\Folder |
|
| 285 | - * @throws NotFoundException |
|
| 286 | - */ |
|
| 287 | - private function getAppDataFolder() { |
|
| 288 | - $instanceId = $this->config->getSystemValue('instanceid', null); |
|
| 283 | + /** |
|
| 284 | + * @return \OCP\Files\Folder |
|
| 285 | + * @throws NotFoundException |
|
| 286 | + */ |
|
| 287 | + private function getAppDataFolder() { |
|
| 288 | + $instanceId = $this->config->getSystemValue('instanceid', null); |
|
| 289 | 289 | |
| 290 | - if ($instanceId === null) { |
|
| 291 | - throw new NotFoundException(); |
|
| 292 | - } |
|
| 290 | + if ($instanceId === null) { |
|
| 291 | + throw new NotFoundException(); |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - return $this->root->get('appdata_'.$instanceId); |
|
| 295 | - } |
|
| 294 | + return $this->root->get('appdata_'.$instanceId); |
|
| 295 | + } |
|
| 296 | 296 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $path = basename($fullPath); |
| 83 | 83 | |
| 84 | 84 | if ($normalizedPath !== $path) { |
| 85 | - $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
| 85 | + $output->writeln("\t<error>Entry \"".$fullPath.'" will not be accessible due to incompatible encoding</error>'); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
@@ -99,26 +99,26 @@ discard block |
||
| 99 | 99 | # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
| 100 | 100 | # printout and count |
| 101 | 101 | if ($verbose) { |
| 102 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 102 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { |
|
| 103 | 103 | $output->writeln("\tFile <info>$path</info>"); |
| 104 | 104 | $this->filesCounter += 1; |
| 105 | 105 | $this->abortIfInterrupted(); |
| 106 | 106 | }); |
| 107 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 107 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { |
|
| 108 | 108 | $output->writeln("\tFolder <info>$path</info>"); |
| 109 | 109 | $this->foldersCounter += 1; |
| 110 | 110 | $this->abortIfInterrupted(); |
| 111 | 111 | }); |
| 112 | - $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
| 113 | - $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')'); |
|
| 112 | + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function(StorageNotAvailableException $e) use ($output) { |
|
| 113 | + $output->writeln('Error while scanning, storage not available ('.$e->getMessage().')'); |
|
| 114 | 114 | }); |
| 115 | 115 | # count only |
| 116 | 116 | } else { |
| 117 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) { |
|
| 117 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function() use ($output) { |
|
| 118 | 118 | $this->filesCounter += 1; |
| 119 | 119 | $this->abortIfInterrupted(); |
| 120 | 120 | }); |
| 121 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { |
|
| 121 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function() use ($output) { |
|
| 122 | 122 | $this->foldersCounter += 1; |
| 123 | 123 | $this->abortIfInterrupted(); |
| 124 | 124 | }); |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | # exit the function if ctrl-c has been pressed |
| 140 | 140 | $output->writeln('Interrupted by user'); |
| 141 | 141 | } catch (NotFoundException $e) { |
| 142 | - $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
| 142 | + $output->writeln('<error>Path not found: '.$e->getMessage().'</error>'); |
|
| 143 | 143 | } catch (\Exception $e) { |
| 144 | - $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
| 145 | - $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
| 144 | + $output->writeln('<error>Exception during scan: '.$e->getMessage().'</error>'); |
|
| 145 | + $output->writeln('<error>'.$e->getTraceAsString().'</error>'); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @return string |
| 253 | 253 | */ |
| 254 | 254 | protected function formatExecTime() { |
| 255 | - list($secs, ) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 255 | + list($secs,) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 256 | 256 | |
| 257 | 257 | # if you want to have microseconds add this: . '.' . $tens; |
| 258 | 258 | return date('H:i:s', $secs); |
@@ -45,318 +45,318 @@ |
||
| 45 | 45 | |
| 46 | 46 | class Scan extends Base { |
| 47 | 47 | |
| 48 | - /** @var IUserManager $userManager */ |
|
| 49 | - private $userManager; |
|
| 50 | - /** @var float */ |
|
| 51 | - protected $execTime = 0; |
|
| 52 | - /** @var int */ |
|
| 53 | - protected $foldersCounter = 0; |
|
| 54 | - /** @var int */ |
|
| 55 | - protected $filesCounter = 0; |
|
| 48 | + /** @var IUserManager $userManager */ |
|
| 49 | + private $userManager; |
|
| 50 | + /** @var float */ |
|
| 51 | + protected $execTime = 0; |
|
| 52 | + /** @var int */ |
|
| 53 | + protected $foldersCounter = 0; |
|
| 54 | + /** @var int */ |
|
| 55 | + protected $filesCounter = 0; |
|
| 56 | 56 | |
| 57 | - public function __construct(IUserManager $userManager) { |
|
| 58 | - $this->userManager = $userManager; |
|
| 59 | - parent::__construct(); |
|
| 60 | - } |
|
| 57 | + public function __construct(IUserManager $userManager) { |
|
| 58 | + $this->userManager = $userManager; |
|
| 59 | + parent::__construct(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - protected function configure() { |
|
| 63 | - parent::configure(); |
|
| 62 | + protected function configure() { |
|
| 63 | + parent::configure(); |
|
| 64 | 64 | |
| 65 | - $this |
|
| 66 | - ->setName('files:scan') |
|
| 67 | - ->setDescription('rescan filesystem') |
|
| 68 | - ->addArgument( |
|
| 69 | - 'user_id', |
|
| 70 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 71 | - 'will rescan all files of the given user(s)' |
|
| 72 | - ) |
|
| 73 | - ->addOption( |
|
| 74 | - 'path', |
|
| 75 | - 'p', |
|
| 76 | - InputArgument::OPTIONAL, |
|
| 77 | - 'limit rescan to this path, eg. --path="/alice/files/Music", the user_id is determined by the path and the user_id parameter and --all are ignored' |
|
| 78 | - ) |
|
| 79 | - ->addOption( |
|
| 80 | - 'quiet', |
|
| 81 | - 'q', |
|
| 82 | - InputOption::VALUE_NONE, |
|
| 83 | - 'suppress any output' |
|
| 84 | - ) |
|
| 85 | - ->addOption( |
|
| 86 | - 'verbose', |
|
| 87 | - '-v|vv|vvv', |
|
| 88 | - InputOption::VALUE_NONE, |
|
| 89 | - 'verbose the output' |
|
| 90 | - ) |
|
| 91 | - ->addOption( |
|
| 92 | - 'all', |
|
| 93 | - null, |
|
| 94 | - InputOption::VALUE_NONE, |
|
| 95 | - 'will rescan all files of all known users' |
|
| 96 | - )->addOption( |
|
| 97 | - 'unscanned', |
|
| 98 | - null, |
|
| 99 | - InputOption::VALUE_NONE, |
|
| 100 | - 'only scan files which are marked as not fully scanned' |
|
| 101 | - )->addOption( |
|
| 102 | - 'shallow', |
|
| 103 | - null, |
|
| 104 | - InputOption::VALUE_NONE, |
|
| 105 | - 'do not scan folders recursively' |
|
| 106 | - )->addOption( |
|
| 107 | - 'home-only', |
|
| 108 | - null, |
|
| 109 | - InputOption::VALUE_NONE, |
|
| 110 | - 'only scan the home storage, ignoring any mounted external storage or share' |
|
| 111 | - ); |
|
| 112 | - } |
|
| 65 | + $this |
|
| 66 | + ->setName('files:scan') |
|
| 67 | + ->setDescription('rescan filesystem') |
|
| 68 | + ->addArgument( |
|
| 69 | + 'user_id', |
|
| 70 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 71 | + 'will rescan all files of the given user(s)' |
|
| 72 | + ) |
|
| 73 | + ->addOption( |
|
| 74 | + 'path', |
|
| 75 | + 'p', |
|
| 76 | + InputArgument::OPTIONAL, |
|
| 77 | + 'limit rescan to this path, eg. --path="/alice/files/Music", the user_id is determined by the path and the user_id parameter and --all are ignored' |
|
| 78 | + ) |
|
| 79 | + ->addOption( |
|
| 80 | + 'quiet', |
|
| 81 | + 'q', |
|
| 82 | + InputOption::VALUE_NONE, |
|
| 83 | + 'suppress any output' |
|
| 84 | + ) |
|
| 85 | + ->addOption( |
|
| 86 | + 'verbose', |
|
| 87 | + '-v|vv|vvv', |
|
| 88 | + InputOption::VALUE_NONE, |
|
| 89 | + 'verbose the output' |
|
| 90 | + ) |
|
| 91 | + ->addOption( |
|
| 92 | + 'all', |
|
| 93 | + null, |
|
| 94 | + InputOption::VALUE_NONE, |
|
| 95 | + 'will rescan all files of all known users' |
|
| 96 | + )->addOption( |
|
| 97 | + 'unscanned', |
|
| 98 | + null, |
|
| 99 | + InputOption::VALUE_NONE, |
|
| 100 | + 'only scan files which are marked as not fully scanned' |
|
| 101 | + )->addOption( |
|
| 102 | + 'shallow', |
|
| 103 | + null, |
|
| 104 | + InputOption::VALUE_NONE, |
|
| 105 | + 'do not scan folders recursively' |
|
| 106 | + )->addOption( |
|
| 107 | + 'home-only', |
|
| 108 | + null, |
|
| 109 | + InputOption::VALUE_NONE, |
|
| 110 | + 'only scan the home storage, ignoring any mounted external storage or share' |
|
| 111 | + ); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - public function checkScanWarning($fullPath, OutputInterface $output) { |
|
| 115 | - $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath)); |
|
| 116 | - $path = basename($fullPath); |
|
| 114 | + public function checkScanWarning($fullPath, OutputInterface $output) { |
|
| 115 | + $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath)); |
|
| 116 | + $path = basename($fullPath); |
|
| 117 | 117 | |
| 118 | - if ($normalizedPath !== $path) { |
|
| 119 | - $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
| 120 | - } |
|
| 121 | - } |
|
| 118 | + if ($normalizedPath !== $path) { |
|
| 119 | + $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - protected function scanFiles($user, $path, $verbose, OutputInterface $output, $backgroundScan = false, $recursive = true, $homeOnly = false) { |
|
| 124 | - $connection = $this->reconnectToDatabase($output); |
|
| 125 | - $scanner = new \OC\Files\Utils\Scanner($user, $connection, \OC::$server->getLogger()); |
|
| 126 | - # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
| 127 | - # printout and count |
|
| 128 | - if ($verbose) { |
|
| 129 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 130 | - $output->writeln("\tFile <info>$path</info>"); |
|
| 131 | - $this->filesCounter += 1; |
|
| 132 | - $this->abortIfInterrupted(); |
|
| 133 | - }); |
|
| 134 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 135 | - $output->writeln("\tFolder <info>$path</info>"); |
|
| 136 | - $this->foldersCounter += 1; |
|
| 137 | - $this->abortIfInterrupted(); |
|
| 138 | - }); |
|
| 139 | - $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
| 140 | - $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')'); |
|
| 141 | - }); |
|
| 142 | - # count only |
|
| 143 | - } else { |
|
| 144 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) { |
|
| 145 | - $this->filesCounter += 1; |
|
| 146 | - $this->abortIfInterrupted(); |
|
| 147 | - }); |
|
| 148 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { |
|
| 149 | - $this->foldersCounter += 1; |
|
| 150 | - $this->abortIfInterrupted(); |
|
| 151 | - }); |
|
| 152 | - } |
|
| 153 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 154 | - $this->checkScanWarning($path, $output); |
|
| 155 | - }); |
|
| 156 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 157 | - $this->checkScanWarning($path, $output); |
|
| 158 | - }); |
|
| 123 | + protected function scanFiles($user, $path, $verbose, OutputInterface $output, $backgroundScan = false, $recursive = true, $homeOnly = false) { |
|
| 124 | + $connection = $this->reconnectToDatabase($output); |
|
| 125 | + $scanner = new \OC\Files\Utils\Scanner($user, $connection, \OC::$server->getLogger()); |
|
| 126 | + # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
| 127 | + # printout and count |
|
| 128 | + if ($verbose) { |
|
| 129 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 130 | + $output->writeln("\tFile <info>$path</info>"); |
|
| 131 | + $this->filesCounter += 1; |
|
| 132 | + $this->abortIfInterrupted(); |
|
| 133 | + }); |
|
| 134 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 135 | + $output->writeln("\tFolder <info>$path</info>"); |
|
| 136 | + $this->foldersCounter += 1; |
|
| 137 | + $this->abortIfInterrupted(); |
|
| 138 | + }); |
|
| 139 | + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
| 140 | + $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')'); |
|
| 141 | + }); |
|
| 142 | + # count only |
|
| 143 | + } else { |
|
| 144 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) { |
|
| 145 | + $this->filesCounter += 1; |
|
| 146 | + $this->abortIfInterrupted(); |
|
| 147 | + }); |
|
| 148 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { |
|
| 149 | + $this->foldersCounter += 1; |
|
| 150 | + $this->abortIfInterrupted(); |
|
| 151 | + }); |
|
| 152 | + } |
|
| 153 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 154 | + $this->checkScanWarning($path, $output); |
|
| 155 | + }); |
|
| 156 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 157 | + $this->checkScanWarning($path, $output); |
|
| 158 | + }); |
|
| 159 | 159 | |
| 160 | - try { |
|
| 161 | - if ($backgroundScan) { |
|
| 162 | - $scanner->backgroundScan($path); |
|
| 163 | - } else { |
|
| 164 | - $scanner->scan($path, $recursive, $homeOnly ? [$this, 'filterHomeMount'] : null); |
|
| 165 | - } |
|
| 166 | - } catch (ForbiddenException $e) { |
|
| 167 | - $output->writeln("<error>Home storage for user $user not writable</error>"); |
|
| 168 | - $output->writeln('Make sure you\'re running the scan command only as the user the web server runs as'); |
|
| 169 | - } catch (InterruptedException $e) { |
|
| 170 | - # exit the function if ctrl-c has been pressed |
|
| 171 | - $output->writeln('Interrupted by user'); |
|
| 172 | - } catch (NotFoundException $e) { |
|
| 173 | - $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
| 174 | - } catch (\Exception $e) { |
|
| 175 | - $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
| 176 | - $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
| 177 | - } |
|
| 178 | - } |
|
| 160 | + try { |
|
| 161 | + if ($backgroundScan) { |
|
| 162 | + $scanner->backgroundScan($path); |
|
| 163 | + } else { |
|
| 164 | + $scanner->scan($path, $recursive, $homeOnly ? [$this, 'filterHomeMount'] : null); |
|
| 165 | + } |
|
| 166 | + } catch (ForbiddenException $e) { |
|
| 167 | + $output->writeln("<error>Home storage for user $user not writable</error>"); |
|
| 168 | + $output->writeln('Make sure you\'re running the scan command only as the user the web server runs as'); |
|
| 169 | + } catch (InterruptedException $e) { |
|
| 170 | + # exit the function if ctrl-c has been pressed |
|
| 171 | + $output->writeln('Interrupted by user'); |
|
| 172 | + } catch (NotFoundException $e) { |
|
| 173 | + $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
| 174 | + } catch (\Exception $e) { |
|
| 175 | + $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
| 176 | + $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - public function filterHomeMount(IMountPoint $mountPoint) { |
|
| 181 | - // any mountpoint inside '/$user/files/' |
|
| 182 | - return substr_count($mountPoint->getMountPoint(), '/') <= 3; |
|
| 183 | - } |
|
| 180 | + public function filterHomeMount(IMountPoint $mountPoint) { |
|
| 181 | + // any mountpoint inside '/$user/files/' |
|
| 182 | + return substr_count($mountPoint->getMountPoint(), '/') <= 3; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 186 | - $inputPath = $input->getOption('path'); |
|
| 187 | - if ($inputPath) { |
|
| 188 | - $inputPath = '/' . trim($inputPath, '/'); |
|
| 189 | - list (, $user,) = explode('/', $inputPath, 3); |
|
| 190 | - $users = array($user); |
|
| 191 | - } else if ($input->getOption('all')) { |
|
| 192 | - $users = $this->userManager->search(''); |
|
| 193 | - } else { |
|
| 194 | - $users = $input->getArgument('user_id'); |
|
| 195 | - } |
|
| 185 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 186 | + $inputPath = $input->getOption('path'); |
|
| 187 | + if ($inputPath) { |
|
| 188 | + $inputPath = '/' . trim($inputPath, '/'); |
|
| 189 | + list (, $user,) = explode('/', $inputPath, 3); |
|
| 190 | + $users = array($user); |
|
| 191 | + } else if ($input->getOption('all')) { |
|
| 192 | + $users = $this->userManager->search(''); |
|
| 193 | + } else { |
|
| 194 | + $users = $input->getArgument('user_id'); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - # no messaging level option means: no full printout but statistics |
|
| 198 | - # $quiet means no print at all |
|
| 199 | - # $verbose means full printout including statistics |
|
| 200 | - # -q -v full stat |
|
| 201 | - # 0 0 no yes |
|
| 202 | - # 0 1 yes yes |
|
| 203 | - # 1 -- no no (quiet overrules verbose) |
|
| 204 | - $verbose = $input->getOption('verbose'); |
|
| 205 | - $quiet = $input->getOption('quiet'); |
|
| 206 | - # restrict the verbosity level to VERBOSITY_VERBOSE |
|
| 207 | - if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
| 208 | - $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
| 209 | - } |
|
| 210 | - if ($quiet) { |
|
| 211 | - $verbose = false; |
|
| 212 | - } |
|
| 197 | + # no messaging level option means: no full printout but statistics |
|
| 198 | + # $quiet means no print at all |
|
| 199 | + # $verbose means full printout including statistics |
|
| 200 | + # -q -v full stat |
|
| 201 | + # 0 0 no yes |
|
| 202 | + # 0 1 yes yes |
|
| 203 | + # 1 -- no no (quiet overrules verbose) |
|
| 204 | + $verbose = $input->getOption('verbose'); |
|
| 205 | + $quiet = $input->getOption('quiet'); |
|
| 206 | + # restrict the verbosity level to VERBOSITY_VERBOSE |
|
| 207 | + if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
| 208 | + $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
| 209 | + } |
|
| 210 | + if ($quiet) { |
|
| 211 | + $verbose = false; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - # check quantity of users to be process and show it on the command line |
|
| 215 | - $users_total = count($users); |
|
| 216 | - if ($users_total === 0) { |
|
| 217 | - $output->writeln("<error>Please specify the user id to scan, \"--all\" to scan for all users or \"--path=...\"</error>"); |
|
| 218 | - return; |
|
| 219 | - } else { |
|
| 220 | - if ($users_total > 1) { |
|
| 221 | - $output->writeln("\nScanning files for $users_total users"); |
|
| 222 | - } |
|
| 223 | - } |
|
| 214 | + # check quantity of users to be process and show it on the command line |
|
| 215 | + $users_total = count($users); |
|
| 216 | + if ($users_total === 0) { |
|
| 217 | + $output->writeln("<error>Please specify the user id to scan, \"--all\" to scan for all users or \"--path=...\"</error>"); |
|
| 218 | + return; |
|
| 219 | + } else { |
|
| 220 | + if ($users_total > 1) { |
|
| 221 | + $output->writeln("\nScanning files for $users_total users"); |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - $this->initTools(); |
|
| 225 | + $this->initTools(); |
|
| 226 | 226 | |
| 227 | - $user_count = 0; |
|
| 228 | - foreach ($users as $user) { |
|
| 229 | - if (is_object($user)) { |
|
| 230 | - $user = $user->getUID(); |
|
| 231 | - } |
|
| 232 | - $path = $inputPath ? $inputPath : '/' . $user; |
|
| 233 | - $user_count += 1; |
|
| 234 | - if ($this->userManager->userExists($user)) { |
|
| 235 | - # add an extra line when verbose is set to optical separate users |
|
| 236 | - if ($verbose) { |
|
| 237 | - $output->writeln(""); |
|
| 238 | - } |
|
| 239 | - $output->writeln("Starting scan for user $user_count out of $users_total ($user)"); |
|
| 240 | - # full: printout data if $verbose was set |
|
| 241 | - $this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'), ! $input->getOption('shallow'), $input->getOption('home-only')); |
|
| 242 | - } else { |
|
| 243 | - $output->writeln("<error>Unknown user $user_count $user</error>"); |
|
| 244 | - } |
|
| 227 | + $user_count = 0; |
|
| 228 | + foreach ($users as $user) { |
|
| 229 | + if (is_object($user)) { |
|
| 230 | + $user = $user->getUID(); |
|
| 231 | + } |
|
| 232 | + $path = $inputPath ? $inputPath : '/' . $user; |
|
| 233 | + $user_count += 1; |
|
| 234 | + if ($this->userManager->userExists($user)) { |
|
| 235 | + # add an extra line when verbose is set to optical separate users |
|
| 236 | + if ($verbose) { |
|
| 237 | + $output->writeln(""); |
|
| 238 | + } |
|
| 239 | + $output->writeln("Starting scan for user $user_count out of $users_total ($user)"); |
|
| 240 | + # full: printout data if $verbose was set |
|
| 241 | + $this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'), ! $input->getOption('shallow'), $input->getOption('home-only')); |
|
| 242 | + } else { |
|
| 243 | + $output->writeln("<error>Unknown user $user_count $user</error>"); |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - try { |
|
| 247 | - $this->abortIfInterrupted(); |
|
| 248 | - } catch(InterruptedException $e) { |
|
| 249 | - break; |
|
| 250 | - } |
|
| 251 | - } |
|
| 246 | + try { |
|
| 247 | + $this->abortIfInterrupted(); |
|
| 248 | + } catch(InterruptedException $e) { |
|
| 249 | + break; |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - # stat: printout statistics if $quiet was not set |
|
| 254 | - if (!$quiet) { |
|
| 255 | - $this->presentStats($output); |
|
| 256 | - } |
|
| 257 | - } |
|
| 253 | + # stat: printout statistics if $quiet was not set |
|
| 254 | + if (!$quiet) { |
|
| 255 | + $this->presentStats($output); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Initialises some useful tools for the Command |
|
| 261 | - */ |
|
| 262 | - protected function initTools() { |
|
| 263 | - // Start the timer |
|
| 264 | - $this->execTime = -microtime(true); |
|
| 265 | - // Convert PHP errors to exceptions |
|
| 266 | - set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
| 267 | - } |
|
| 259 | + /** |
|
| 260 | + * Initialises some useful tools for the Command |
|
| 261 | + */ |
|
| 262 | + protected function initTools() { |
|
| 263 | + // Start the timer |
|
| 264 | + $this->execTime = -microtime(true); |
|
| 265 | + // Convert PHP errors to exceptions |
|
| 266 | + set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
| 271 | - * |
|
| 272 | - * @see https://secure.php.net/manual/en/function.set-error-handler.php |
|
| 273 | - * |
|
| 274 | - * @param int $severity the level of the error raised |
|
| 275 | - * @param string $message |
|
| 276 | - * @param string $file the filename that the error was raised in |
|
| 277 | - * @param int $line the line number the error was raised |
|
| 278 | - * |
|
| 279 | - * @throws \ErrorException |
|
| 280 | - */ |
|
| 281 | - public function exceptionErrorHandler($severity, $message, $file, $line) { |
|
| 282 | - if (!(error_reporting() & $severity)) { |
|
| 283 | - // This error code is not included in error_reporting |
|
| 284 | - return; |
|
| 285 | - } |
|
| 286 | - throw new \ErrorException($message, 0, $severity, $file, $line); |
|
| 287 | - } |
|
| 269 | + /** |
|
| 270 | + * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
| 271 | + * |
|
| 272 | + * @see https://secure.php.net/manual/en/function.set-error-handler.php |
|
| 273 | + * |
|
| 274 | + * @param int $severity the level of the error raised |
|
| 275 | + * @param string $message |
|
| 276 | + * @param string $file the filename that the error was raised in |
|
| 277 | + * @param int $line the line number the error was raised |
|
| 278 | + * |
|
| 279 | + * @throws \ErrorException |
|
| 280 | + */ |
|
| 281 | + public function exceptionErrorHandler($severity, $message, $file, $line) { |
|
| 282 | + if (!(error_reporting() & $severity)) { |
|
| 283 | + // This error code is not included in error_reporting |
|
| 284 | + return; |
|
| 285 | + } |
|
| 286 | + throw new \ErrorException($message, 0, $severity, $file, $line); |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - /** |
|
| 290 | - * @param OutputInterface $output |
|
| 291 | - */ |
|
| 292 | - protected function presentStats(OutputInterface $output) { |
|
| 293 | - // Stop the timer |
|
| 294 | - $this->execTime += microtime(true); |
|
| 295 | - $output->writeln(""); |
|
| 289 | + /** |
|
| 290 | + * @param OutputInterface $output |
|
| 291 | + */ |
|
| 292 | + protected function presentStats(OutputInterface $output) { |
|
| 293 | + // Stop the timer |
|
| 294 | + $this->execTime += microtime(true); |
|
| 295 | + $output->writeln(""); |
|
| 296 | 296 | |
| 297 | - $headers = [ |
|
| 298 | - 'Folders', 'Files', 'Elapsed time' |
|
| 299 | - ]; |
|
| 297 | + $headers = [ |
|
| 298 | + 'Folders', 'Files', 'Elapsed time' |
|
| 299 | + ]; |
|
| 300 | 300 | |
| 301 | - $this->showSummary($headers, null, $output); |
|
| 302 | - } |
|
| 301 | + $this->showSummary($headers, null, $output); |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - /** |
|
| 305 | - * Shows a summary of operations |
|
| 306 | - * |
|
| 307 | - * @param string[] $headers |
|
| 308 | - * @param string[] $rows |
|
| 309 | - * @param OutputInterface $output |
|
| 310 | - */ |
|
| 311 | - protected function showSummary($headers, $rows, OutputInterface $output) { |
|
| 312 | - $niceDate = $this->formatExecTime(); |
|
| 313 | - if (!$rows) { |
|
| 314 | - $rows = [ |
|
| 315 | - $this->foldersCounter, |
|
| 316 | - $this->filesCounter, |
|
| 317 | - $niceDate, |
|
| 318 | - ]; |
|
| 319 | - } |
|
| 320 | - $table = new Table($output); |
|
| 321 | - $table |
|
| 322 | - ->setHeaders($headers) |
|
| 323 | - ->setRows([$rows]); |
|
| 324 | - $table->render(); |
|
| 325 | - } |
|
| 304 | + /** |
|
| 305 | + * Shows a summary of operations |
|
| 306 | + * |
|
| 307 | + * @param string[] $headers |
|
| 308 | + * @param string[] $rows |
|
| 309 | + * @param OutputInterface $output |
|
| 310 | + */ |
|
| 311 | + protected function showSummary($headers, $rows, OutputInterface $output) { |
|
| 312 | + $niceDate = $this->formatExecTime(); |
|
| 313 | + if (!$rows) { |
|
| 314 | + $rows = [ |
|
| 315 | + $this->foldersCounter, |
|
| 316 | + $this->filesCounter, |
|
| 317 | + $niceDate, |
|
| 318 | + ]; |
|
| 319 | + } |
|
| 320 | + $table = new Table($output); |
|
| 321 | + $table |
|
| 322 | + ->setHeaders($headers) |
|
| 323 | + ->setRows([$rows]); |
|
| 324 | + $table->render(); |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | 327 | |
| 328 | - /** |
|
| 329 | - * Formats microtime into a human readable format |
|
| 330 | - * |
|
| 331 | - * @return string |
|
| 332 | - */ |
|
| 333 | - protected function formatExecTime() { |
|
| 334 | - list($secs, ) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 328 | + /** |
|
| 329 | + * Formats microtime into a human readable format |
|
| 330 | + * |
|
| 331 | + * @return string |
|
| 332 | + */ |
|
| 333 | + protected function formatExecTime() { |
|
| 334 | + list($secs, ) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 335 | 335 | |
| 336 | - # if you want to have microseconds add this: . '.' . $tens; |
|
| 337 | - return date('H:i:s', $secs); |
|
| 338 | - } |
|
| 336 | + # if you want to have microseconds add this: . '.' . $tens; |
|
| 337 | + return date('H:i:s', $secs); |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * @return \OCP\IDBConnection |
|
| 342 | - */ |
|
| 343 | - protected function reconnectToDatabase(OutputInterface $output) { |
|
| 344 | - /** @var Connection | IDBConnection $connection */ |
|
| 345 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 346 | - try { |
|
| 347 | - $connection->close(); |
|
| 348 | - } catch (\Exception $ex) { |
|
| 349 | - $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
| 350 | - } |
|
| 351 | - while (!$connection->isConnected()) { |
|
| 352 | - try { |
|
| 353 | - $connection->connect(); |
|
| 354 | - } catch (\Exception $ex) { |
|
| 355 | - $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
| 356 | - sleep(60); |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - return $connection; |
|
| 360 | - } |
|
| 340 | + /** |
|
| 341 | + * @return \OCP\IDBConnection |
|
| 342 | + */ |
|
| 343 | + protected function reconnectToDatabase(OutputInterface $output) { |
|
| 344 | + /** @var Connection | IDBConnection $connection */ |
|
| 345 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 346 | + try { |
|
| 347 | + $connection->close(); |
|
| 348 | + } catch (\Exception $ex) { |
|
| 349 | + $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
| 350 | + } |
|
| 351 | + while (!$connection->isConnected()) { |
|
| 352 | + try { |
|
| 353 | + $connection->connect(); |
|
| 354 | + } catch (\Exception $ex) { |
|
| 355 | + $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
| 356 | + sleep(60); |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + return $connection; |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | 362 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $path = basename($fullPath); |
| 117 | 117 | |
| 118 | 118 | if ($normalizedPath !== $path) { |
| 119 | - $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
| 119 | + $output->writeln("\t<error>Entry \"".$fullPath.'" will not be accessible due to incompatible encoding</error>'); |
|
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
@@ -126,34 +126,34 @@ discard block |
||
| 126 | 126 | # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
| 127 | 127 | # printout and count |
| 128 | 128 | if ($verbose) { |
| 129 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 129 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { |
|
| 130 | 130 | $output->writeln("\tFile <info>$path</info>"); |
| 131 | 131 | $this->filesCounter += 1; |
| 132 | 132 | $this->abortIfInterrupted(); |
| 133 | 133 | }); |
| 134 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 134 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { |
|
| 135 | 135 | $output->writeln("\tFolder <info>$path</info>"); |
| 136 | 136 | $this->foldersCounter += 1; |
| 137 | 137 | $this->abortIfInterrupted(); |
| 138 | 138 | }); |
| 139 | - $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
| 140 | - $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')'); |
|
| 139 | + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function(StorageNotAvailableException $e) use ($output) { |
|
| 140 | + $output->writeln('Error while scanning, storage not available ('.$e->getMessage().')'); |
|
| 141 | 141 | }); |
| 142 | 142 | # count only |
| 143 | 143 | } else { |
| 144 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) { |
|
| 144 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function() use ($output) { |
|
| 145 | 145 | $this->filesCounter += 1; |
| 146 | 146 | $this->abortIfInterrupted(); |
| 147 | 147 | }); |
| 148 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { |
|
| 148 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function() use ($output) { |
|
| 149 | 149 | $this->foldersCounter += 1; |
| 150 | 150 | $this->abortIfInterrupted(); |
| 151 | 151 | }); |
| 152 | 152 | } |
| 153 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 153 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { |
|
| 154 | 154 | $this->checkScanWarning($path, $output); |
| 155 | 155 | }); |
| 156 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 156 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { |
|
| 157 | 157 | $this->checkScanWarning($path, $output); |
| 158 | 158 | }); |
| 159 | 159 | |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | # exit the function if ctrl-c has been pressed |
| 171 | 171 | $output->writeln('Interrupted by user'); |
| 172 | 172 | } catch (NotFoundException $e) { |
| 173 | - $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
| 173 | + $output->writeln('<error>Path not found: '.$e->getMessage().'</error>'); |
|
| 174 | 174 | } catch (\Exception $e) { |
| 175 | - $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
| 176 | - $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
| 175 | + $output->writeln('<error>Exception during scan: '.$e->getMessage().'</error>'); |
|
| 176 | + $output->writeln('<error>'.$e->getTraceAsString().'</error>'); |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 186 | 186 | $inputPath = $input->getOption('path'); |
| 187 | 187 | if ($inputPath) { |
| 188 | - $inputPath = '/' . trim($inputPath, '/'); |
|
| 188 | + $inputPath = '/'.trim($inputPath, '/'); |
|
| 189 | 189 | list (, $user,) = explode('/', $inputPath, 3); |
| 190 | 190 | $users = array($user); |
| 191 | 191 | } else if ($input->getOption('all')) { |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | if (is_object($user)) { |
| 230 | 230 | $user = $user->getUID(); |
| 231 | 231 | } |
| 232 | - $path = $inputPath ? $inputPath : '/' . $user; |
|
| 232 | + $path = $inputPath ? $inputPath : '/'.$user; |
|
| 233 | 233 | $user_count += 1; |
| 234 | 234 | if ($this->userManager->userExists($user)) { |
| 235 | 235 | # add an extra line when verbose is set to optical separate users |
@@ -238,14 +238,14 @@ discard block |
||
| 238 | 238 | } |
| 239 | 239 | $output->writeln("Starting scan for user $user_count out of $users_total ($user)"); |
| 240 | 240 | # full: printout data if $verbose was set |
| 241 | - $this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'), ! $input->getOption('shallow'), $input->getOption('home-only')); |
|
| 241 | + $this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'), !$input->getOption('shallow'), $input->getOption('home-only')); |
|
| 242 | 242 | } else { |
| 243 | 243 | $output->writeln("<error>Unknown user $user_count $user</error>"); |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | try { |
| 247 | 247 | $this->abortIfInterrupted(); |
| 248 | - } catch(InterruptedException $e) { |
|
| 248 | + } catch (InterruptedException $e) { |
|
| 249 | 249 | break; |
| 250 | 250 | } |
| 251 | 251 | } |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * @return string |
| 332 | 332 | */ |
| 333 | 333 | protected function formatExecTime() { |
| 334 | - list($secs, ) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 334 | + list($secs,) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 335 | 335 | |
| 336 | 336 | # if you want to have microseconds add this: . '.' . $tens; |
| 337 | 337 | return date('H:i:s', $secs); |