Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/groupfolders.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2021-12-16 15:01:46 +0300
committerCarl Schwan <carl@carlschwan.eu>2021-12-16 15:01:46 +0300
commit17aff8dfc6a439d87c3d52720922d6b2b47df099 (patch)
tree741a11c888e178ab355ba72bb14fc63f24bd6756 /lib/Command/Scan.php
parentc016c6854dd0159f7e797bf1ec754b04f7c1c334 (diff)
More refactoring
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib/Command/Scan.php')
-rw-r--r--lib/Command/Scan.php86
1 files changed, 37 insertions, 49 deletions
diff --git a/lib/Command/Scan.php b/lib/Command/Scan.php
index 8fc1de07..c6d51f55 100644
--- a/lib/Command/Scan.php
+++ b/lib/Command/Scan.php
@@ -23,6 +23,7 @@ namespace OCA\GroupFolders\Command;
use OC\Core\Command\Base;
use OC\Files\ObjectStore\NoopScanner;
+use OCA\GroupFolders\Command\FolderCommand;
use OCA\GroupFolders\Folder\FolderManager;
use OCA\GroupFolders\Mount\MountProvider;
use OCP\Constants;
@@ -32,20 +33,10 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-class Scan extends Base {
- private $folderManager;
- private $rootFolder;
- private $mountProvider;
+class Scan extends FolderCommand {
private $foldersCounter = 0;
private $filesCounter = 0;
- public function __construct(FolderManager $folderManager, IRootFolder $rootFolder, MountProvider $mountProvider) {
- parent::__construct();
- $this->folderManager = $folderManager;
- $this->rootFolder = $rootFolder;
- $this->mountProvider = $mountProvider;
- }
-
protected function configure() {
$this
->setName('groupfolders:scan')
@@ -55,52 +46,49 @@ class Scan extends Base {
}
protected function execute(InputInterface $input, OutputInterface $output) {
- $folderId = (int)$input->getArgument('folder_id');
- $folder = $this->folderManager->getFolder($folderId, $this->rootFolder->getMountPoint()->getNumericStorageId());
- if ($folder) {
- $mount = $this->mountProvider->getMount($folder['id'], '/' . $folder['mount_point'], Constants::PERMISSION_ALL, $folder['quota']);
- $scanner = $mount->getStorage()->getScanner();
+ $folder = $this->getFolder($input, $output);
+ if ($folder === false) {
+ return -1;
+ }
+ $mount = $this->mountProvider->getMount($folder['id'], '/' . $folder['mount_point'], Constants::PERMISSION_ALL, $folder['quota']);
+ $scanner = $mount->getStorage()->getScanner();
- if ($scanner instanceof NoopScanner) {
- $output->writeln("Scanning group folders using an object store as primary storage is not supported.");
- return -1;
- }
+ if ($scanner instanceof NoopScanner) {
+ $output->writeln("Scanning group folders using an object store as primary storage is not supported.");
+ return -1;
+ }
- $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($output) {
- $output->writeln("\tFile\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE);
- ++$this->filesCounter;
- // abortIfInterrupted doesn't exist in nc14
- if (method_exists($this, 'abortIfInterrupted')) {
- $this->abortIfInterrupted();
- }
- });
+ $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($output) {
+ $output->writeln("\tFile\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE);
+ ++$this->filesCounter;
+ // abortIfInterrupted doesn't exist in nc14
+ if (method_exists($this, 'abortIfInterrupted')) {
+ $this->abortIfInterrupted();
+ }
+ });
- $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($output) {
- $output->writeln("\tFolder\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE);
- ++$this->foldersCounter;
- // abortIfInterrupted doesn't exist in nc14
- if (method_exists($this, 'abortIfInterrupted')) {
- $this->abortIfInterrupted();
- }
- });
+ $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($output) {
+ $output->writeln("\tFolder\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE);
+ ++$this->foldersCounter;
+ // abortIfInterrupted doesn't exist in nc14
+ if (method_exists($this, 'abortIfInterrupted')) {
+ $this->abortIfInterrupted();
+ }
+ });
- $start = microtime(true);
+ $start = microtime(true);
- $scanner->setUseTransactions(false);
- $scanner->scan('');
+ $scanner->setUseTransactions(false);
+ $scanner->scan('');
- $end = microtime(true);
+ $end = microtime(true);
- $headers = [
- 'Folders', 'Files', 'Elapsed time'
- ];
+ $headers = [
+ 'Folders', 'Files', 'Elapsed time'
+ ];
- $this->showSummary($headers, null, $output, $end - $start);
- return 0;
- } else {
- $output->writeln('<error>Folder not found: ' . $folderId . '</error>');
- return -1;
- }
+ $this->showSummary($headers, null, $output, $end - $start);
+ return 0;
}
protected function showSummary($headers, $rows, OutputInterface $output, float $duration) {