summaryrefslogtreecommitdiffstats
path: root/lib/private/PreviewManager.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2020-10-04 14:41:08 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-10-21 10:35:18 +0200
commit8bc25e33243a914a44e86ef4ba060ab6a8bd3237 (patch)
tree299537ccec1a02f20e7de6119a0d2325865ab79f /lib/private/PreviewManager.php
parent732a05716719dfcb866ba14863500cfb357fe543 (diff)
downloadnextcloud-server-8bc25e33243a914a44e86ef4ba060ab6a8bd3237.tar.gz
nextcloud-server-8bc25e33243a914a44e86ef4ba060ab6a8bd3237.zip
Move preview provider registration to bootstrap
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/PreviewManager.php')
-rw-r--r--lib/private/PreviewManager.php53
1 files changed, 52 insertions, 1 deletions
diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php
index a381ec8c23d..02d017a5017 100644
--- a/lib/private/PreviewManager.php
+++ b/lib/private/PreviewManager.php
@@ -30,8 +30,10 @@
*/
namespace OC;
+use OC\AppFramework\Bootstrap\Coordinator;
use OC\Preview\Generator;
use OC\Preview\GeneratorHelper;
+use OCP\AppFramework\QueryException;
use OCP\Files\File;
use OCP\Files\IAppData;
use OCP\Files\IRootFolder;
@@ -39,8 +41,10 @@ use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig;
use OCP\IPreview;
+use OCP\IServerContainer;
use OCP\Preview\IProviderV2;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use function array_key_exists;
class PreviewManager implements IPreview {
/** @var IConfig */
@@ -79,6 +83,20 @@ class PreviewManager implements IPreview {
/** @var string */
protected $userId;
+ /** @var Coordinator */
+ private $bootstrapCoordinator;
+
+ /**
+ * Hash map (without value) of loaded bootstrap providers
+ *
+ * @var null[]
+ * @psalm-var array<string, null>
+ */
+ private $loadedBootstrapProviders = [];
+
+ /** @var IServerContainer */
+ private $container;
+
/**
* PreviewManager constructor.
*
@@ -93,13 +111,17 @@ class PreviewManager implements IPreview {
IAppData $appData,
EventDispatcherInterface $eventDispatcher,
GeneratorHelper $helper,
- $userId) {
+ $userId,
+ Coordinator $bootstrapCoordinator,
+ IServerContainer $container) {
$this->config = $config;
$this->rootFolder = $rootFolder;
$this->appData = $appData;
$this->eventDispatcher = $eventDispatcher;
$this->helper = $helper;
$this->userId = $userId;
+ $this->bootstrapCoordinator = $bootstrapCoordinator;
+ $this->container = $container;
}
/**
@@ -134,6 +156,7 @@ class PreviewManager implements IPreview {
}
$this->registerCoreProviders();
+ $this->registerBootstrapProviders();
if ($this->providerListDirty) {
$keys = array_map('strlen', array_keys($this->providers));
array_multisort($keys, SORT_DESC, $this->providers);
@@ -220,6 +243,7 @@ class PreviewManager implements IPreview {
}
$this->registerCoreProviders();
+ $this->registerBootstrapProviders();
$providerMimeTypes = array_keys($this->providers);
foreach ($providerMimeTypes as $supportedMimeType) {
if (preg_match($supportedMimeType, $mimeType)) {
@@ -431,4 +455,31 @@ class PreviewManager implements IPreview {
}
}
}
+
+ private function registerBootstrapProviders(): void {
+ $context = $this->bootstrapCoordinator->getRegistrationContext();
+
+ if ($context === null) {
+ // Just ignore for now
+ return;
+ }
+
+ $providers = $context->getPreviewProviders();
+ foreach ($providers as $provider) {
+ $key = $provider->getMimeTypeRegex() . '-' . $provider->getService();
+ if (array_key_exists($key, $this->loadedBootstrapProviders)) {
+ // Do not load the provider more than once
+ continue;
+ }
+ $this->loadedBootstrapProviders[$key] = null;
+
+ $this->registerProvider($provider->getMimeTypeRegex(), function () use ($provider) {
+ try {
+ return $this->container->query($provider->getService());
+ } catch (QueryException $e) {
+ return null;
+ }
+ });
+ }
+ }
}