From 48d9c4d2b093e12ec3bf3cd29295da0f2277028f Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 28 Jun 2022 12:55:26 +0200 Subject: Port existing server code to new interface Signed-off-by: Carl Schwan --- apps/files/lib/BackgroundJob/ScanFiles.php | 23 +++++++++++------------ apps/files/tests/BackgroundJob/ScanFilesTest.php | 2 ++ 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'apps/files') diff --git a/apps/files/lib/BackgroundJob/ScanFiles.php b/apps/files/lib/BackgroundJob/ScanFiles.php index 07794a28774..8dc9dcf37ff 100644 --- a/apps/files/lib/BackgroundJob/ScanFiles.php +++ b/apps/files/lib/BackgroundJob/ScanFiles.php @@ -25,6 +25,8 @@ namespace OCA\Files\BackgroundJob; use OC\Files\Utils\Scanner; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\TimedJob; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; @@ -37,13 +39,11 @@ use Psr\Log\LoggerInterface; * * @package OCA\Files\BackgroundJob */ -class ScanFiles extends \OC\BackgroundJob\TimedJob { - /** @var IConfig */ - private $config; - /** @var IEventDispatcher */ - private $dispatcher; +class ScanFiles extends TimedJob { + private IConfig $config; + private IEventDispatcher $dispatcher; private LoggerInterface $logger; - private $connection; + private IDBConnection $connection; /** Amount of users that should get scanned per execution */ public const USERS_PER_SESSION = 500; @@ -52,8 +52,10 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob { IConfig $config, IEventDispatcher $dispatcher, LoggerInterface $logger, - IDBConnection $connection + IDBConnection $connection, + ITimeFactory $time ) { + parent::__construct($time); // Run once per 10 minutes $this->setInterval(60 * 10); @@ -63,10 +65,7 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob { $this->connection = $connection; } - /** - * @param string $user - */ - protected function runScanner(string $user) { + protected function runScanner(string $user): void { try { $scanner = new Scanner( $user, @@ -95,7 +94,7 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob { ->andWhere($query->expr()->gt('parent', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT))) ->setMaxResults(1); - return $query->execute()->fetchOne(); + return $query->executeQuery()->fetchOne(); } /** diff --git a/apps/files/tests/BackgroundJob/ScanFilesTest.php b/apps/files/tests/BackgroundJob/ScanFilesTest.php index 5b2d52b48d3..cf0120da09d 100644 --- a/apps/files/tests/BackgroundJob/ScanFilesTest.php +++ b/apps/files/tests/BackgroundJob/ScanFilesTest.php @@ -26,6 +26,7 @@ namespace OCA\Files\Tests\BackgroundJob; use OC\Files\Mount\MountPoint; use OC\Files\Storage\Temporary; use OCA\Files\BackgroundJob\ScanFiles; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IUser; @@ -64,6 +65,7 @@ class ScanFilesTest extends TestCase { $dispatcher, $logger, $connection, + $this->createMock(ITimeFactory::class) ]) ->setMethods(['runScanner']) ->getMock(); -- cgit v1.2.3