Skip to content

Commit

Permalink
chore: Move away from deprecated ILogger and Server::query
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Jun 6, 2023
1 parent 92ca360 commit 561ae2e
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 66 deletions.
22 changes: 12 additions & 10 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use OCA\Richdocuments\Template\CollaboraTemplateProvider;
use OCA\Richdocuments\WOPI\DiscoveryManager;
use OCA\Viewer\Event\LoadViewer;
use OCP\App\IAppManager;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
Expand All @@ -55,6 +56,7 @@
use OCP\IPreview;
use OCP\Preview\BeforePreviewFetchedEvent;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
use OCP\Server;

class Application extends App implements IBootstrap {
public const APPNAME = 'richdocuments';
Expand Down Expand Up @@ -142,26 +144,26 @@ public function registerProvider() {
$container = $this->getContainer();

/** @var IPreview $previewManager */
$previewManager = $container->query(IPreview::class);
$previewManager = $container->get(IPreview::class);

$previewManager->registerProvider('/application\/vnd.ms-excel/', function () use ($container) {
return $container->query(MSExcel::class);
return $container->get(MSExcel::class);
});

$previewManager->registerProvider('/application\/msword/', function () use ($container) {
return $container->query(MSWord::class);
return $container->get(MSWord::class);
});

$previewManager->registerProvider('/application\/vnd.openxmlformats-officedocument.*/', function () use ($container) {
return $container->query(OOXML::class);
return $container->get(OOXML::class);
});

$previewManager->registerProvider('/application\/vnd.oasis.opendocument.*/', function () use ($container) {
return $container->query(OpenDocument::class);
return $container->get(OpenDocument::class);
});

$previewManager->registerProvider('/application\/pdf/', function () use ($container) {
return $container->query(Pdf::class);
return $container->get(Pdf::class);
});
}

Expand All @@ -175,8 +177,8 @@ public function checkAndEnableCODEServer() {

$CODEAppID = (php_uname('m') === 'x86_64') ? 'richdocumentscode' : 'richdocumentscode_arm64';

if ($this->getContainer()->getServer()->getAppManager()->isEnabledForUser($CODEAppID)) {
$appConfig = $this->getContainer()->query(AppConfig::class);
if (Server::get(IAppManager::class)->isEnabledForUser($CODEAppID)) {
$appConfig = $this->getContainer()->get(AppConfig::class);
$wopi_url = $appConfig->getAppValue('wopi_url');
$isCODEEnabled = strpos($wopi_url, 'proxy.php?req=') !== false;

Expand All @@ -198,8 +200,8 @@ public function checkAndEnableCODEServer() {
$appConfig->setAppValue('wopi_url', $new_wopi_url);
$appConfig->setAppValue('disable_certificate_verification', 'yes');

$discoveryManager = $this->getContainer()->query(DiscoveryManager::class);
$capabilitiesService = $this->getContainer()->query(CapabilitiesService::class);
$discoveryManager = $this->getContainer()->get(DiscoveryManager::class);
$capabilitiesService = $this->getContainer()->get(CapabilitiesService::class);

$discoveryManager->refetch();
$capabilitiesService->clear();
Expand Down
10 changes: 5 additions & 5 deletions lib/Controller/DirectViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IRequest;
use Psr\Log\LoggerInterface;

class DirectViewController extends Controller {
use DocumentTrait;
Expand All @@ -67,7 +67,7 @@ class DirectViewController extends Controller {
/** @var FederationService */
private $federationService;

/** @var ILogger */
/** @var LoggerInterface */
private $logger;

/** @var InitialStateService */
Expand All @@ -84,7 +84,7 @@ public function __construct(
AppConfig $appConfig,
TemplateManager $templateManager,
FederationService $federationService,
ILogger $logger
LoggerInterface $logger
) {
parent::__construct($appName, $request);

Expand Down Expand Up @@ -180,7 +180,7 @@ public function show($token) {

return $this->documentTemplateResponse($wopi, $params);
} catch (\Exception $e) {
$this->logger->logException($e);
$this->logger->error($e->getMessage(), ['exception' => $e]);
return $this->renderErrorPage('Failed to open the requested file.');
}
}
Expand Down Expand Up @@ -229,7 +229,7 @@ public function showPublicShare(Direct $direct) {
return $this->documentTemplateResponse($wopi, $params);
}
} catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'richdocuments']);
$this->logger->error($e->getMessage(), ['exception' => $e]);
return $this->renderErrorPage('Failed to open the requested file.');
}

Expand Down
14 changes: 7 additions & 7 deletions lib/Controller/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use \OCP\AppFramework\Controller;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\IConfig;
use \OCP\ILogger;
use \OCP\IRequest;
use OCA\Richdocuments\Service\FederationService;
use OCA\Richdocuments\Service\InitialStateService;
Expand All @@ -32,6 +31,7 @@
use OCP\ISession;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;

class DocumentController extends Controller {
use DocumentTrait;
Expand All @@ -42,7 +42,7 @@ class DocumentController extends Controller {
private $config;
/** @var AppConfig */
private $appConfig;
/** @var ILogger */
/** @var LoggerInterface */
private $logger;
/** @var IManager */
private $shareManager;
Expand All @@ -69,7 +69,7 @@ public function __construct(
IRootFolder $rootFolder,
ISession $session,
$UserId,
ILogger $logger,
LoggerInterface $logger,
TemplateManager $templateManager,
FederationService $federationService,
InitialStateService $initialState
Expand Down Expand Up @@ -122,7 +122,7 @@ public function extAppGetData(int $fileId) {
'token' => $token
];
} catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'richdocuments']);
$this->logger->error($e->getMessage(), ['exception' => $e]);
}
}
}
Expand Down Expand Up @@ -194,7 +194,7 @@ public function index($fileId, $path = null) {

return $this->documentTemplateResponse($wopi, $params);
} catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'richdocuments']);
$this->logger->error($e->getMessage(), ['exception' => $e]);
return $this->renderErrorPage('Failed to open the requested file.');
}
}
Expand Down Expand Up @@ -308,7 +308,7 @@ public function publicPage($shareToken, $fileName, $fileId) {
return $this->documentTemplateResponse($wopi, $params);
}
} catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'richdocuments']);
$this->logger->error($e->getMessage(), ['exception' => $e]);
return $this->renderErrorPage('Failed to open the requested file.');
}

Expand Down Expand Up @@ -378,7 +378,7 @@ public function remote($shareToken, $remoteServer, $remoteServerToken, $filePath
} catch (ShareNotFound $e) {
return new TemplateResponse('core', '404', [], 'guest');
} catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'richdocuments']);
$this->logger->error($e->getMessage(), ['exception' => $e]);
return $this->renderErrorPage('Failed to open the requested file.');
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Controller/FederationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

class FederationController extends OCSController {
/** @var IConfig */
private $config;

/** @var ILogger */
/** @var LoggerInterface */
private $logger;

/** @var WopiMapper */
Expand All @@ -55,7 +55,7 @@ public function __construct(
string $appName,
IRequest $request,
IConfig $config,
ILogger $logger,
LoggerInterface $logger,
WopiMapper $wopiMapper,
IUserManager $userManager,
IURLGenerator $urlGenerator
Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/OCSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;

class OCSController extends \OCP\AppFramework\OCSController {
/** @var IRootFolder */
Expand All @@ -72,7 +72,7 @@ class OCSController extends \OCP\AppFramework\OCSController {
/** @var FederationService */
private $federationService;

/** @var ILogger */
/** @var LoggerInterface */
private $logger;

public function __construct(string $appName,
Expand All @@ -85,7 +85,7 @@ public function __construct(string $appName,
TokenManager $tokenManager,
IManager $shareManager,
FederationService $federationService,
ILogger $logger
LoggerInterface $logger
) {
parent::__construct($appName, $request);

Expand Down Expand Up @@ -340,7 +340,7 @@ public function createFromTemplate($path, $template) {
} catch (NotFoundException $e) {
throw new OCSNotFoundException();
} catch (\Exception $e) {
$this->logger->logException($e);
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new OCSException('Failed to create new file from template.');
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig;
use OCP\ILogger;
use OCP\PreConditionNotMetException;
use OCP\Util;
use Psr\Log\LoggerInterface;

class SettingsController extends Controller {
// TODO adapt overview generation if we add more font mimetypes
Expand Down Expand Up @@ -60,7 +60,7 @@ class SettingsController extends Controller {
private $capabilitiesService;
/** @var DemoService */
private $demoService;
/** @var ILogger */
/** @var LoggerInterface */
private $logger;
/**
* @var FontService
Expand All @@ -77,7 +77,7 @@ public function __construct($appName,
CapabilitiesService $capabilitiesService,
DemoService $demoService,
FontService $fontService,
ILogger $logger,
LoggerInterface $logger,
$userId
) {
parent::__construct($appName, $request);
Expand All @@ -103,7 +103,7 @@ public function checkSettings() {
try {
$response = $this->discoveryManager->fetchFromRemote();
} catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'richdocuments']);
$this->logger->error($e->getMessage(), ['exception' => $e]);
return new DataResponse([
'status' => $e->getCode(),
'message' => 'Could not fetch discovery details'
Expand Down
Loading

0 comments on commit 561ae2e

Please sign in to comment.