diff options
Diffstat (limited to 'apps/files/lib/BackgroundJob/TransferOwnership.php')
-rw-r--r-- | apps/files/lib/BackgroundJob/TransferOwnership.php | 78 |
1 files changed, 21 insertions, 57 deletions
diff --git a/apps/files/lib/BackgroundJob/TransferOwnership.php b/apps/files/lib/BackgroundJob/TransferOwnership.php index 8c96fcf8385..de8d1989733 100644 --- a/apps/files/lib/BackgroundJob/TransferOwnership.php +++ b/apps/files/lib/BackgroundJob/TransferOwnership.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Files\BackgroundJob; @@ -33,46 +16,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) { @@ -84,14 +44,14 @@ class TransferOwnership extends QueuedJob { $fileId = $transfer->getFileId(); $userFolder = $this->rootFolder->getUserFolder($sourceUser); - $nodes = $userFolder->getById($fileId); + $node = $userFolder->getFirstNodeById($fileId); - if (empty($nodes)) { + if (!$node) { $this->logger->alert('Could not transfer ownership: Node not found'); $this->failedNotication($transfer); return; } - $path = $userFolder->getRelativePath($nodes[0]->getPath()); + $path = $userFolder->getRelativePath($node->getPath()); $sourceUserObject = $this->userManager->get($sourceUser); $destinationUserObject = $this->userManager->get($destinationUser); @@ -116,7 +76,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 +101,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()) |