refactor: Migrate away from deprecated ILogger interface to PSR-3
Mostly replace `ILogger` with `LoggerInterface` and some minor cleanup (constructor property promotion). Some places used the deprecated `logException` this is easy to migrate by simply use the appropriate loglevel on the logger and place the exception under the `exception` key in the context. Also the manual checking of the configured log level is not needed, as this is already done by the logger. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
@@ -17,26 +17,22 @@ use OCP\Comments\IComment;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\Comments\MessageTooLongException;
|
||||
use OCP\Comments\NotFoundException as CommentNotFoundException;
|
||||
use OCP\ILogger;
|
||||
use OCP\IUserManager;
|
||||
use OutOfBoundsException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
use function is_numeric;
|
||||
|
||||
class CommentService {
|
||||
private ICommentsManager $commentsManager;
|
||||
private IUserManager $userManager;
|
||||
private CardMapper $cardMapper;
|
||||
private PermissionService $permissionService;
|
||||
private ILogger $logger;
|
||||
private ?string $userId;
|
||||
|
||||
public function __construct(ICommentsManager $commentsManager, PermissionService $permissionService, CardMapper $cardMapper, IUserManager $userManager, ILogger $logger, ?string $userId) {
|
||||
$this->commentsManager = $commentsManager;
|
||||
$this->permissionService = $permissionService;
|
||||
$this->cardMapper = $cardMapper;
|
||||
$this->userManager = $userManager;
|
||||
$this->logger = $logger;
|
||||
$this->userId = $userId;
|
||||
public function __construct(
|
||||
private ICommentsManager $commentsManager,
|
||||
private PermissionService $permissionService,
|
||||
private CardMapper $cardMapper,
|
||||
private IUserManager $userManager,
|
||||
private LoggerInterface $logger,
|
||||
private ?string $userId,
|
||||
) {
|
||||
}
|
||||
|
||||
public function list(string $cardId, int $limit = 20, int $offset = 0): DataResponse {
|
||||
@@ -187,8 +183,8 @@ class CommentService {
|
||||
try {
|
||||
$displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']);
|
||||
} catch (OutOfBoundsException $e) {
|
||||
$this->logger->logException($e);
|
||||
// No displayname, upon client's discretion what to display.
|
||||
$this->logger->warning('Mention type not registered, can not resolve display name.', ['exception' => $e, 'mention_type' => $mention['type']]);
|
||||
// No display name, upon client's discretion what to display.
|
||||
$displayName = '';
|
||||
}
|
||||
|
||||
|
||||
@@ -20,37 +20,21 @@ use OCP\Files\SimpleFS\ISimpleFile;
|
||||
use OCP\Files\SimpleFS\ISimpleFolder;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use OCP\IRequest;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class FileService implements IAttachmentService {
|
||||
private $l10n;
|
||||
private $appData;
|
||||
private $request;
|
||||
private $logger;
|
||||
private $rootFolder;
|
||||
private $config;
|
||||
private $attachmentMapper;
|
||||
private $mimeTypeDetector;
|
||||
|
||||
public function __construct(
|
||||
IL10N $l10n,
|
||||
IAppData $appData,
|
||||
IRequest $request,
|
||||
ILogger $logger,
|
||||
IRootFolder $rootFolder,
|
||||
IConfig $config,
|
||||
AttachmentMapper $attachmentMapper,
|
||||
IMimeTypeDetector $mimeTypeDetector
|
||||
private IL10N $l10n,
|
||||
private IAppData $appData,
|
||||
private IRequest $request,
|
||||
private LoggerInterface $logger,
|
||||
private IRootFolder $rootFolder,
|
||||
private IConfig $config,
|
||||
private AttachmentMapper $attachmentMapper,
|
||||
private IMimeTypeDetector $mimeTypeDetector
|
||||
) {
|
||||
$this->l10n = $l10n;
|
||||
$this->appData = $appData;
|
||||
$this->request = $request;
|
||||
$this->logger = $logger;
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->config = $config;
|
||||
$this->attachmentMapper = $attachmentMapper;
|
||||
$this->mimeTypeDetector = $mimeTypeDetector;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,6 +177,7 @@ class FileService implements IAttachmentService {
|
||||
/**
|
||||
* Workaround until ISimpleFile can be fetched as a resource
|
||||
*
|
||||
* @return \OCP\Files\File
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getFileFromRootFolder(Attachment $attachment) {
|
||||
|
||||
Reference in New Issue
Block a user