-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScanCommand.php
More file actions
65 lines (55 loc) · 1.68 KB
/
ScanCommand.php
File metadata and controls
65 lines (55 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
// SPDX-FileCopyrightText: 2025 Lennart Dohmann <lennart.dohmann@gdata.de>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace OCA\GDataVaas\Command;
use OCA\GDataVaas\Logging\ConsoleCommandLogger;
use OCA\GDataVaas\Service\ScanService;
use OCA\GDataVaas\Service\TagUnscannedService;
use OCP\DB\Exception;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ScanCommand extends Command {
private ScanService $scanService;
private TagUnscannedService $tagUnscannedService;
private LoggerInterface $logger;
public function __construct(
ScanService $scanService,
TagUnscannedService $tagUnscannedService,
LoggerInterface $logger,
) {
parent::__construct();
$this->scanService = $scanService;
$this->tagUnscannedService = $tagUnscannedService;
$this->logger = $logger;
}
/**
* @return void
*/
protected function configure(): void {
$this->setName('gdatavaas:scan');
$this->setDescription('scan files for malware');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$logger = new ConsoleCommandLogger($this->logger, $output);
$logger->info('scanning files');
$start = microtime(true);
$this->tagUnscannedService
->withLogger($logger)
->run();
$scannedFilesCount = $this->scanService
->withLogger($logger)
->run();
$time_elapsed_secs = microtime(true) - $start;
$logger->info("Scanned $scannedFilesCount files in $time_elapsed_secs seconds");
return 0;
}
}