More logging
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Родитель
ce0d6abe95
Коммит
3e02332f6c
|
@ -72,7 +72,7 @@ class BackgroundScanner extends TimedJob {
|
|||
// Run once per 15 minutes
|
||||
$this->setInterval(60 * 15);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Background scanner main job
|
||||
*/
|
||||
|
@ -85,6 +85,7 @@ class BackgroundScanner extends TimedJob {
|
|||
return;
|
||||
}
|
||||
|
||||
$this->logger->debug('Start background scan');
|
||||
$batchSize = $this->getBatchSize();
|
||||
|
||||
// Run for unscanned files
|
||||
|
@ -178,6 +179,9 @@ class BackgroundScanner extends TimedJob {
|
|||
if ($this->isCLI) {
|
||||
$batchSize = 100;
|
||||
}
|
||||
|
||||
$this->logger->debug('Batch size is: ' . $batchSize);
|
||||
|
||||
return $batchSize;
|
||||
}
|
||||
|
||||
|
@ -240,7 +244,9 @@ class BackgroundScanner extends TimedJob {
|
|||
}
|
||||
|
||||
protected function scanOneFile(File $file): void {
|
||||
$item = $this->itemFactory->newItem($file);
|
||||
$this->logger->debug('Scanning file with fileid: ' . $file->getId());
|
||||
|
||||
$item = $this->itemFactory->newItem($file, true);
|
||||
$scanner = $this->scannerFactory->getScanner();
|
||||
$status = $scanner->scan($item);
|
||||
$status->dispatch($item);
|
||||
|
|
22
lib/Item.php
22
lib/Item.php
|
@ -43,6 +43,7 @@ class Item {
|
|||
|
||||
/** @var File */
|
||||
private $file;
|
||||
private $isCron;
|
||||
|
||||
/**
|
||||
* Item constructor.
|
||||
|
@ -53,19 +54,22 @@ class Item {
|
|||
* @param ILogger $logger
|
||||
* @param IRootFolder $rootFolder
|
||||
* @param File $file
|
||||
* @param bool $isCron
|
||||
*/
|
||||
public function __construct(AppConfig $appConfig,
|
||||
ActivityManager $activityManager,
|
||||
ItemMapper $itemMapper,
|
||||
ILogger $logger,
|
||||
IRootFolder $rootFolder,
|
||||
File $file) {
|
||||
File $file,
|
||||
$isCron) {
|
||||
$this->config = $appConfig;
|
||||
$this->activityManager = $activityManager;
|
||||
$this->itemMapper = $itemMapper;
|
||||
$this->logger = $logger;
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->file = $file;
|
||||
$this->isCron = $isCron;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,7 +98,7 @@ class Item {
|
|||
$infectedAction = $this->config->getAvInfectedAction();
|
||||
|
||||
$shouldDelete = $infectedAction === 'delete';
|
||||
|
||||
|
||||
$message = $shouldDelete ? Provider::MESSAGE_FILE_DELETED : '';
|
||||
|
||||
$userFolder = $this->rootFolder->getUserFolder($this->file->getOwner()->getUID());
|
||||
|
@ -110,10 +114,20 @@ class Item {
|
|||
$this->activityManager->publish($activity);
|
||||
|
||||
if ($shouldDelete) {
|
||||
$this->logError('Infected file deleted. ' . $status->getDetails());
|
||||
if ($this->isCron) {
|
||||
$msg = 'Infected file deleted (during background scan)';
|
||||
} else {
|
||||
$msg = 'Infected file deleted.';
|
||||
}
|
||||
$this->logError($msg . ' ' . $status->getDetails());
|
||||
$this->deleteFile();
|
||||
} else {
|
||||
$this->logError('File is infected. ' . $status->getDetails());
|
||||
if ($this->isCron) {
|
||||
$msg = 'Infected file found (during background scan)';
|
||||
} else {
|
||||
$msg = 'Infected file found.';
|
||||
}
|
||||
$this->logError($msg . ' ' . $status->getDetails());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,14 +70,15 @@ class ItemFactory {
|
|||
* @param File $file
|
||||
* @return Item
|
||||
*/
|
||||
public function newItem(File $file) {
|
||||
public function newItem(File $file, $isCron = false) {
|
||||
return new Item(
|
||||
$this->config,
|
||||
$this->activityManager,
|
||||
$this->itemMapper,
|
||||
$this->logger,
|
||||
$this->rootFolder,
|
||||
$file
|
||||
$file,
|
||||
$isCron
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче