diff options
author | Bart Visscher <bartv@thisnet.nl> | 2013-09-01 16:40:50 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2013-09-01 16:40:50 +0200 |
commit | 0aba549e7f11e1035fa7a2e880803b47cbadd919 (patch) | |
tree | f2ba9c9cd15a555e2864764824d96b362653dbe6 /apps/files/command | |
parent | 92e90c8eb995c886b3e9cd77c14e3f0b25b95cd7 (diff) | |
download | nextcloud-server-0aba549e7f11e1035fa7a2e880803b47cbadd919.tar.gz nextcloud-server-0aba549e7f11e1035fa7a2e880803b47cbadd919.zip |
Use more object oriented way for console commands
Diffstat (limited to 'apps/files/command')
-rw-r--r-- | apps/files/command/scan.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/apps/files/command/scan.php b/apps/files/command/scan.php new file mode 100644 index 00000000000..fce4f6875d7 --- /dev/null +++ b/apps/files/command/scan.php @@ -0,0 +1,55 @@ +<?php + +namespace OCA\Files\Command; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class Scan extends Command +{ + protected function configure() + { + $this + ->setName('files:scan') + ->setDescription('rescan filesystem') + ->addArgument( + 'user_id', + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, + 'will rescan all files of the given user(s)' + ) + ->addOption( + 'all', + null, + InputOption::VALUE_NONE, + 'will rescan all files of all known users' + ) + ; + } + + protected function scanFiles($user, OutputInterface $output) { + $scanner = new \OC\Files\Utils\Scanner($user); + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { + $output->writeln("Scanning <info>$path</info>"); + }); + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { + $output->writeln("Scanning <info>$path</info>"); + }); + $scanner->scan(''); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + if ($input->getOption('all')) { + $users = \OC_User::getUsers(); + } else { + $users = $input->getArgument('user_id'); + } + + foreach ($users as $user) { + $this->scanFiles($user, $output); + } + } +} |