aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfenn-cs <fenn25.fn@gmail.com>2023-07-07 02:52:39 +0100
committerfenn-cs <fenn25.fn@gmail.com>2023-08-13 11:37:34 +0100
commitdc8d25c2742220b3c199c31e0e703470799090f1 (patch)
tree4c06590e6827ec40e54d1366739601a1c70e0807
parent4a2fbf72802e8b92422bccbfde8dc270f89be420 (diff)
downloadnextcloud-server-dc8d25c2742220b3c199c31e0e703470799090f1.tar.gz
nextcloud-server-dc8d25c2742220b3c199c31e0e703470799090f1.zip
Migrate parts of files app away from depecrated Ilogger
- Migrate some backgrounds jobs, `TransferOwnership` & `DeleteOrphanedItems` - Migrate `DirectEditingController` Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
-rw-r--r--apps/files/lib/BackgroundJob/DeleteOrphanedItems.php22
-rw-r--r--apps/files/lib/BackgroundJob/TransferOwnership.php51
-rw-r--r--apps/files/lib/Controller/DirectEditingController.php58
-rw-r--r--apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php18
4 files changed, 64 insertions, 85 deletions
diff --git a/apps/files/lib/BackgroundJob/DeleteOrphanedItems.php b/apps/files/lib/BackgroundJob/DeleteOrphanedItems.php
index 669c2a4cde6..6163955ddfd 100644
--- a/apps/files/lib/BackgroundJob/DeleteOrphanedItems.php
+++ b/apps/files/lib/BackgroundJob/DeleteOrphanedItems.php
@@ -27,34 +27,26 @@ namespace OCA\Files\BackgroundJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use Psr\Log\LoggerInterface;
/**
* Delete all share entries that have no matching entries in the file cache table.
*/
class DeleteOrphanedItems extends TimedJob {
public const CHUNK_SIZE = 200;
-
- /** @var \OCP\IDBConnection */
- protected $connection;
-
- /** @var \OCP\ILogger */
- protected $logger;
-
- /**
- * Default interval in minutes
- *
- * @var int $defaultIntervalMin
- **/
protected $defaultIntervalMin = 60;
/**
* sets the correct interval for this timed job
*/
- public function __construct(ITimeFactory $time) {
+ public function __construct(
+ ITimeFactory $time,
+ protected IDBConnection $connection,
+ protected LoggerInterface $logger,
+ ) {
parent::__construct($time);
$this->interval = $this->defaultIntervalMin * 60;
- $this->connection = \OC::$server->getDatabaseConnection();
- $this->logger = \OC::$server->getLogger();
}
/**
diff --git a/apps/files/lib/BackgroundJob/TransferOwnership.php b/apps/files/lib/BackgroundJob/TransferOwnership.php
index 8c96fcf8385..9103c307b76 100644
--- a/apps/files/lib/BackgroundJob/TransferOwnership.php
+++ b/apps/files/lib/BackgroundJob/TransferOwnership.php
@@ -33,46 +33,23 @@ use OCA\Files\Service\OwnershipTransferService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\Files\IRootFolder;
-use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Notification\IManager as NotificationManager;
+use Psr\Log\LoggerInterface;
use function ltrim;
class TransferOwnership extends QueuedJob {
-
- /** @var IUserManager $userManager */
- private $userManager;
-
- /** @var OwnershipTransferService */
- private $transferService;
-
- /** @var ILogger */
- private $logger;
-
- /** @var NotificationManager */
- private $notificationManager;
-
- /** @var TransferOwnershipMapper */
- private $mapper;
- /** @var IRootFolder */
- private $rootFolder;
-
- public function __construct(ITimeFactory $timeFactory,
- IUserManager $userManager,
- OwnershipTransferService $transferService,
- ILogger $logger,
- NotificationManager $notificationManager,
- TransferOwnershipMapper $mapper,
- IRootFolder $rootFolder) {
+ public function __construct(
+ ITimeFactory $timeFactory,
+ private IUserManager $userManager,
+ private OwnershipTransferService $transferService,
+ private LoggerInterface $logger,
+ private NotificationManager $notificationManager,
+ private TransferOwnershipMapper $mapper,
+ private IRootFolder $rootFolder,
+ ) {
parent::__construct($timeFactory);
-
- $this->userManager = $userManager;
- $this->transferService = $transferService;
- $this->logger = $logger;
- $this->notificationManager = $notificationManager;
- $this->mapper = $mapper;
- $this->rootFolder = $rootFolder;
}
protected function run($argument) {
@@ -116,7 +93,12 @@ class TransferOwnership extends QueuedJob {
);
$this->successNotification($transfer);
} catch (TransferOwnershipException $e) {
- $this->logger->logException($e);
+ $this->logger->error(
+ $e->getMessage(),
+ [
+ 'exception' => $e,
+ ],
+ );
$this->failedNotication($transfer);
}
@@ -136,7 +118,6 @@ class TransferOwnership extends QueuedJob {
])
->setObject('transfer', (string)$transfer->getId());
$this->notificationManager->notify($notification);
-
// Send notification to source user
$notification = $this->notificationManager->createNotification();
$notification->setUser($transfer->getTargetUser())
diff --git a/apps/files/lib/Controller/DirectEditingController.php b/apps/files/lib/Controller/DirectEditingController.php
index d58be166e79..5cc98e7ff1d 100644
--- a/apps/files/lib/Controller/DirectEditingController.php
+++ b/apps/files/lib/Controller/DirectEditingController.php
@@ -30,35 +30,24 @@ use OCP\AppFramework\OCSController;
use OCP\DirectEditing\IManager;
use OCP\DirectEditing\RegisterDirectEditorEvent;
use OCP\EventDispatcher\IEventDispatcher;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
+use Psr\Log\LoggerInterface;
class DirectEditingController extends OCSController {
- /** @var IEventDispatcher */
- private $eventDispatcher;
-
- /** @var IManager */
- private $directEditingManager;
-
- /** @var IURLGenerator */
- private $urlGenerator;
-
- /** @var ILogger */
- private $logger;
-
- /** @var DirectEditingService */
- private $directEditingService;
-
- public function __construct($appName, IRequest $request, $corsMethods, $corsAllowedHeaders, $corsMaxAge,
- IEventDispatcher $eventDispatcher, IURLGenerator $urlGenerator, IManager $manager, DirectEditingService $directEditingService, ILogger $logger) {
+ public function __construct(
+ string $appName,
+ IRequest $request,
+ string $corsMethods,
+ string $corsAllowedHeaders,
+ int $corsMaxAge,
+ private IEventDispatcher $eventDispatcher,
+ private IURLGenerator $urlGenerator,
+ private IManager $directEditingManager,
+ private DirectEditingService $directEditingService,
+ private LoggerInterface $logger
+ ) {
parent::__construct($appName, $request, $corsMethods, $corsAllowedHeaders, $corsMaxAge);
-
- $this->eventDispatcher = $eventDispatcher;
- $this->directEditingManager = $manager;
- $this->directEditingService = $directEditingService;
- $this->logger = $logger;
- $this->urlGenerator = $urlGenerator;
}
/**
@@ -100,7 +89,12 @@ class DirectEditingController extends OCSController {
'url' => $this->urlGenerator->linkToRouteAbsolute('files.DirectEditingView.edit', ['token' => $token])
]);
} catch (Exception $e) {
- $this->logger->logException($e, ['message' => 'Exception when creating a new file through direct editing']);
+ $this->logger->error(
+ 'Exception when creating a new file through direct editing',
+ [
+ 'exception' => $e
+ ],
+ );
return new DataResponse(['message' => 'Failed to create file: ' . $e->getMessage()], Http::STATUS_FORBIDDEN);
}
}
@@ -131,7 +125,12 @@ class DirectEditingController extends OCSController {
'url' => $this->urlGenerator->linkToRouteAbsolute('files.DirectEditingView.edit', ['token' => $token])
]);
} catch (Exception $e) {
- $this->logger->logException($e, ['message' => 'Exception when opening a file through direct editing']);
+ $this->logger->error(
+ 'Exception when opening a file through direct editing',
+ [
+ 'exception' => $e
+ ],
+ );
return new DataResponse(['message' => 'Failed to open file: ' . $e->getMessage()], Http::STATUS_FORBIDDEN);
}
}
@@ -159,7 +158,12 @@ class DirectEditingController extends OCSController {
try {
return new DataResponse($this->directEditingManager->getTemplates($editorId, $creatorId));
} catch (Exception $e) {
- $this->logger->logException($e);
+ $this->logger->error(
+ $e->getMessage(),
+ [
+ 'exception' => $e
+ ],
+ );
return new DataResponse(['message' => 'Failed to obtain template list: ' . $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}
diff --git a/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php b/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php
index f7562345d8a..fcc665a80ca 100644
--- a/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php
+++ b/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php
@@ -26,6 +26,8 @@ namespace OCA\Files\Tests\BackgroundJob;
use OCA\Files\BackgroundJob\DeleteOrphanedItems;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use Psr\Log\LoggerInterface;
/**
* Class DeleteOrphanedItemsJobTest
@@ -35,15 +37,15 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
* @package Test\BackgroundJob
*/
class DeleteOrphanedItemsJobTest extends \Test\TestCase {
- /** @var \OCP\IDBConnection */
- protected $connection;
-
+ protected IDBConnection $connection;
+ protected LoggerInterface $logger;
protected ITimeFactory $timeFactory;
protected function setUp(): void {
parent::setUp();
- $this->connection = \OC::$server->getDatabaseConnection();
+ $this->connection = \OC::$server->get(IDBConnection::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->logger = \OC::$server->get(LoggerInterface::class);
}
protected function cleanMapping($table) {
@@ -98,7 +100,7 @@ class DeleteOrphanedItemsJobTest extends \Test\TestCase {
$mapping = $this->getMappings('systemtag_object_mapping');
$this->assertCount(2, $mapping);
- $job = new DeleteOrphanedItems($this->timeFactory);
+ $job = new DeleteOrphanedItems($this->timeFactory, $this->connection, $this->logger);
$this->invokePrivate($job, 'cleanSystemTags');
$mapping = $this->getMappings('systemtag_object_mapping');
@@ -147,7 +149,7 @@ class DeleteOrphanedItemsJobTest extends \Test\TestCase {
$mapping = $this->getMappings('vcategory_to_object');
$this->assertCount(2, $mapping);
- $job = new DeleteOrphanedItems($this->timeFactory);
+ $job = new DeleteOrphanedItems($this->timeFactory, $this->connection, $this->logger);
$this->invokePrivate($job, 'cleanUserTags');
$mapping = $this->getMappings('vcategory_to_object');
@@ -198,7 +200,7 @@ class DeleteOrphanedItemsJobTest extends \Test\TestCase {
$mapping = $this->getMappings('comments');
$this->assertCount(2, $mapping);
- $job = new DeleteOrphanedItems($this->timeFactory);
+ $job = new DeleteOrphanedItems($this->timeFactory, $this->connection, $this->logger);
$this->invokePrivate($job, 'cleanComments');
$mapping = $this->getMappings('comments');
@@ -247,7 +249,7 @@ class DeleteOrphanedItemsJobTest extends \Test\TestCase {
$mapping = $this->getMappings('comments_read_markers');
$this->assertCount(2, $mapping);
- $job = new DeleteOrphanedItems($this->timeFactory);
+ $job = new DeleteOrphanedItems($this->timeFactory, $this->connection, $this->logger);
$this->invokePrivate($job, 'cleanCommentMarkers');
$mapping = $this->getMappings('comments_read_markers');