From 0aba549e7f11e1035fa7a2e880803b47cbadd919 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 1 Sep 2013 16:40:50 +0200 Subject: Use more object oriented way for console commands --- apps/files/command/scan.php | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 apps/files/command/scan.php (limited to 'apps/files/command') 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 @@ +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 $path"); + }); + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { + $output->writeln("Scanning $path"); + }); + $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); + } + } +} -- cgit v1.2.3 From cafc8cb22347f0c861bbc333354e2766779e065d Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 2 Sep 2013 18:18:12 +0200 Subject: Change Files Scan command to use OC\User\Manager --- apps/files/command/scan.php | 25 ++++++++++++++++++------- console.php | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'apps/files/command') diff --git a/apps/files/command/scan.php b/apps/files/command/scan.php index fce4f6875d7..c5631d19561 100644 --- a/apps/files/command/scan.php +++ b/apps/files/command/scan.php @@ -8,10 +8,19 @@ 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() - { +class Scan extends Command { + + /** + * @var \OC\User\Manager $userManager + */ + private $userManager; + + public function __construct(\OC\User\Manager $userManager) { + $this->userManager = $userManager; + parent::__construct(); + } + + protected function configure() { $this ->setName('files:scan') ->setDescription('rescan filesystem') @@ -40,15 +49,17 @@ class Scan extends Command $scanner->scan(''); } - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('all')) { - $users = \OC_User::getUsers(); + $users = $this->userManager->search(''); } else { $users = $input->getArgument('user_id'); } foreach ($users as $user) { + if (is_object($user)) { + $user = $user->getUID(); + } $this->scanFiles($user, $output); } } diff --git a/console.php b/console.php index 9639f60b7ac..11df7eb0dc9 100644 --- a/console.php +++ b/console.php @@ -27,5 +27,5 @@ if (!OC::$CLI) { $defaults = new OC_Defaults; $application = new Application($defaults->getName(), \OC_Util::getVersionString()); $application->add(new OC\Core\Command\Status); -$application->add(new OCA\Files\Command\Scan); +$application->add(new OCA\Files\Command\Scan(OC_User::getManager())); $application->run(); -- cgit v1.2.3 From a9ea99e93d0dc982b5daa3ed7974e5bd419dcd1b Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 19 Sep 2013 19:12:16 +0200 Subject: Add copyright, remove starting blank line --- apps/files/command/scan.php | 7 +++++++ console.php | 1 - core/command/status.php | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'apps/files/command') diff --git a/apps/files/command/scan.php b/apps/files/command/scan.php index c5631d19561..25ab70af362 100644 --- a/apps/files/command/scan.php +++ b/apps/files/command/scan.php @@ -1,4 +1,11 @@ + * Copyright (c) 2013 Bart Visscher + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ namespace OCA\Files\Command; diff --git a/console.php b/console.php index b8dd5e08790..25b8b312539 100644 --- a/console.php +++ b/console.php @@ -1,4 +1,3 @@ - diff --git a/core/command/status.php b/core/command/status.php index 2bd89919dd5..ea9825b0f61 100644 --- a/core/command/status.php +++ b/core/command/status.php @@ -1,4 +1,10 @@ + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ namespace OC\Core\Command; -- cgit v1.2.3