scan.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
  4. * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
  5. * This file is licensed under the Affero General Public License version 3 or
  6. * later.
  7. * See the COPYING-README file.
  8. */
  9. namespace OCA\Files\Command;
  10. use Symfony\Component\Console\Command\Command;
  11. use Symfony\Component\Console\Input\InputArgument;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Input\InputOption;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. class Scan extends Command {
  16. /**
  17. * @var \OC\User\Manager $userManager
  18. */
  19. private $userManager;
  20. public function __construct(\OC\User\Manager $userManager) {
  21. $this->userManager = $userManager;
  22. parent::__construct();
  23. }
  24. protected function configure() {
  25. $this
  26. ->setName('files:scan')
  27. ->setDescription('rescan filesystem')
  28. ->addArgument(
  29. 'user_id',
  30. InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
  31. 'will rescan all files of the given user(s)'
  32. )
  33. ->addOption(
  34. 'all',
  35. null,
  36. InputOption::VALUE_NONE,
  37. 'will rescan all files of all known users'
  38. )
  39. ;
  40. }
  41. protected function scanFiles($user, OutputInterface $output) {
  42. $scanner = new \OC\Files\Utils\Scanner($user);
  43. $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) {
  44. $output->writeln("Scanning <info>$path</info>");
  45. });
  46. $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) {
  47. $output->writeln("Scanning <info>$path</info>");
  48. });
  49. $scanner->scan('');
  50. }
  51. protected function execute(InputInterface $input, OutputInterface $output) {
  52. if ($input->getOption('all')) {
  53. $users = $this->userManager->search('');
  54. } else {
  55. $users = $input->getArgument('user_id');
  56. }
  57. foreach ($users as $user) {
  58. if (is_object($user)) {
  59. $user = $user->getUID();
  60. }
  61. $this->scanFiles($user, $output);
  62. }
  63. }
  64. }