aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2019-12-11 11:27:05 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2019-12-13 09:41:05 +0100
commitb81b824da138281d904c775664c82f060ba4fbec (patch)
tree0194aea2aabe08a168bc32ccf964b94f31db6ae5 /apps/files/lib
parent642606754b133a36d7715b45b243155cbb006f95 (diff)
downloadnextcloud-server-b81b824da138281d904c775664c82f060ba4fbec.tar.gz
nextcloud-server-b81b824da138281d904c775664c82f060ba4fbec.zip
Add typed events for the filesystem/scanner
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/files/lib')
-rw-r--r--apps/files/lib/BackgroundJob/ScanFiles.php33
-rw-r--r--apps/files/lib/Command/Scan.php3
-rw-r--r--apps/files/lib/Command/ScanAppData.php3
3 files changed, 17 insertions, 22 deletions
diff --git a/apps/files/lib/BackgroundJob/ScanFiles.php b/apps/files/lib/BackgroundJob/ScanFiles.php
index c1ebad0214c..a2d35ba9868 100644
--- a/apps/files/lib/BackgroundJob/ScanFiles.php
+++ b/apps/files/lib/BackgroundJob/ScanFiles.php
@@ -24,8 +24,8 @@
namespace OCA\Files\BackgroundJob;
use OC\Files\Utils\Scanner;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
-use OCP\IDBConnection;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;
@@ -41,39 +41,31 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob {
private $config;
/** @var IUserManager */
private $userManager;
- /** @var IDBConnection */
- private $dbConnection;
+ /** @var IEventDispatcher */
+ private $dispatcher;
/** @var ILogger */
private $logger;
+
/** Amount of users that should get scanned per execution */
const USERS_PER_SESSION = 500;
/**
* @param IConfig|null $config
* @param IUserManager|null $userManager
- * @param IDBConnection|null $dbConnection
+ * @param IEventDispatcher|null $dispatcher
* @param ILogger|null $logger
*/
public function __construct(IConfig $config = null,
IUserManager $userManager = null,
- IDBConnection $dbConnection = null,
+ IEventDispatcher $dispatcher = null,
ILogger $logger = null) {
// Run once per 10 minutes
$this->setInterval(60 * 10);
- if (is_null($userManager) || is_null($config)) {
- $this->fixDIForJobs();
- } else {
- $this->config = $config;
- $this->userManager = $userManager;
- $this->logger = $logger;
- }
- }
-
- protected function fixDIForJobs() {
- $this->config = \OC::$server->getConfig();
- $this->userManager = \OC::$server->getUserManager();
- $this->logger = \OC::$server->getLogger();
+ $this->config = $config ?? \OC::$server->getConfig();
+ $this->userManager = $userManager ?? \OC::$server->getUserManager();
+ $this->dispatcher = $dispatcher ?? \OC::$server->query(IEventDispatcher::class);
+ $this->logger = $logger ?? \OC::$server->getLogger();
}
/**
@@ -83,7 +75,8 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob {
try {
$scanner = new Scanner(
$user->getUID(),
- $this->dbConnection,
+ null,
+ $this->dispatcher,
$this->logger
);
$scanner->backgroundScan('');
@@ -101,7 +94,7 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob {
if ($this->config->getSystemValueBool('files_no_background_scan', false)) {
return;
}
-
+
$offset = $this->config->getAppValue('files', 'cronjob_scan_files', 0);
$users = $this->userManager->search('', self::USERS_PER_SESSION, $offset);
if (!count($users)) {
diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php
index c0c7ecdb8f0..b32e670ffc2 100644
--- a/apps/files/lib/Command/Scan.php
+++ b/apps/files/lib/Command/Scan.php
@@ -36,6 +36,7 @@ use Doctrine\DBAL\Connection;
use OC\Core\Command\Base;
use OC\Core\Command\InterruptedException;
use OC\ForbiddenException;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\StorageNotAvailableException;
@@ -114,7 +115,7 @@ class Scan extends Base {
protected function scanFiles($user, $path, OutputInterface $output, $backgroundScan = false, $recursive = true, $homeOnly = false) {
$connection = $this->reconnectToDatabase($output);
- $scanner = new \OC\Files\Utils\Scanner($user, $connection, \OC::$server->getLogger());
+ $scanner = new \OC\Files\Utils\Scanner($user, $connection, \OC::$server->query(IEventDispatcher::class), \OC::$server->getLogger());
# check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception
diff --git a/apps/files/lib/Command/ScanAppData.php b/apps/files/lib/Command/ScanAppData.php
index c8609b57b73..38d6ed2d425 100644
--- a/apps/files/lib/Command/ScanAppData.php
+++ b/apps/files/lib/Command/ScanAppData.php
@@ -30,6 +30,7 @@ use Doctrine\DBAL\Connection;
use OC\Core\Command\Base;
use OC\Core\Command\InterruptedException;
use OC\ForbiddenException;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\StorageNotAvailableException;
@@ -85,7 +86,7 @@ class ScanAppData extends Base {
}
$connection = $this->reconnectToDatabase($output);
- $scanner = new \OC\Files\Utils\Scanner(null, $connection, \OC::$server->getLogger());
+ $scanner = new \OC\Files\Utils\Scanner(null, $connection, \OC::$server->query(IEventDispatcher::class), \OC::$server->getLogger());
# check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {