From 4505afe18478274fcdbaf55109a7fbd6699f71de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?=
 <skjnldsv@protonmail.com>
Date: Wed, 3 Jul 2019 12:02:31 +0200
Subject: [PATCH] Allow IProviderV2 for previews as well
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
---
 lib/private/Preview/Generator.php |  3 +--
 lib/private/PreviewManager.php    | 13 +++++++++----
 lib/private/Server.php            | 25 ++++++++++++++++++-------
 3 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php
index 2f9401af385..f9c020389f9 100644
--- a/lib/private/Preview/Generator.php
+++ b/lib/private/Preview/Generator.php
@@ -25,6 +25,7 @@
 
 namespace OC\Preview;
 
+use OC\Preview\GeneratorHelper;
 use OCP\Files\File;
 use OCP\Files\IAppData;
 use OCP\Files\NotFoundException;
@@ -34,9 +35,7 @@ use OCP\Files\SimpleFS\ISimpleFolder;
 use OCP\IConfig;
 use OCP\IImage;
 use OCP\IPreview;
-use OCP\Preview\IProvider;
 use OCP\Preview\IProviderV2;
-use OCP\Preview\IVersionedPreviewFile;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Symfony\Component\EventDispatcher\GenericEvent;
 
diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php
index 6635d919fb7..621c45f28c5 100644
--- a/lib/private/PreviewManager.php
+++ b/lib/private/PreviewManager.php
@@ -35,7 +35,7 @@ use OCP\Files\NotFoundException;
 use OCP\Files\SimpleFS\ISimpleFile;
 use OCP\IConfig;
 use OCP\IPreview;
-use OCP\Preview\IProvider;
+use OCP\Preview\IProviderV2;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
 class PreviewManager implements IPreview {
@@ -53,6 +53,9 @@ class PreviewManager implements IPreview {
 
 	/** @var Generator */
 	private $generator;
+	
+	/** @var GeneratorHelper */
+	private $helper;
 
 	/** @var bool */
 	protected $providerListDirty = false;
@@ -85,11 +88,13 @@ class PreviewManager implements IPreview {
 								IRootFolder $rootFolder,
 								IAppData $appData,
 								EventDispatcherInterface $eventDispatcher,
+								GeneratorHelper $helper,
 								$userId) {
 		$this->config = $config;
 		$this->rootFolder = $rootFolder;
 		$this->appData = $appData;
 		$this->eventDispatcher = $eventDispatcher;
+		$this->helper = $helper;
 		$this->userId = $userId;
 	}
 
@@ -255,9 +260,9 @@ class PreviewManager implements IPreview {
 
 		foreach ($this->providers as $supportedMimeType => $providers) {
 			if (preg_match($supportedMimeType, $file->getMimetype())) {
-				foreach ($providers as $closure) {
-					$provider = $closure();
-					if (!($provider instanceof IProvider)) {
+				foreach ($providers as $providerClosure) {
+					$provider = $this->helper->getProvider($providerClosure);
+					if (!($provider instanceof IProviderV2)) {
 						continue;
 					}
 
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 2b08b0bab15..ac0a4ab8a41 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -68,6 +68,7 @@ use OC\Command\CronBus;
 use OC\Comments\ManagerFactory as CommentsManagerFactory;
 use OC\Contacts\ContactsMenu\ActionFactory;
 use OC\Contacts\ContactsMenu\ContactsStore;
+use OC\Dashboard\DashboardManager;
 use OC\Diagnostics\EventLogger;
 use OC\Diagnostics\QueryLogger;
 use OC\Federation\CloudFederationFactory;
@@ -99,19 +100,20 @@ use OC\Memcache\ArrayCache;
 use OC\Memcache\Factory;
 use OC\Notification\Manager;
 use OC\OCS\DiscoveryService;
+use OC\Preview\GeneratorHelper;
 use OC\Remote\Api\ApiFactory;
 use OC\Remote\InstanceFactory;
 use OC\RichObjectStrings\Validator;
 use OC\Security\Bruteforce\Throttler;
 use OC\Security\CertificateManager;
-use OC\Security\CSP\ContentSecurityPolicyManager;
+use OC\Security\CredentialsManager;
 use OC\Security\Crypto;
+use OC\Security\CSP\ContentSecurityPolicyManager;
 use OC\Security\CSP\ContentSecurityPolicyNonceManager;
 use OC\Security\CSRF\CsrfTokenGenerator;
 use OC\Security\CSRF\CsrfTokenManager;
 use OC\Security\CSRF\TokenStorage\SessionStorage;
 use OC\Security\Hasher;
-use OC\Security\CredentialsManager;
 use OC\Security\SecureRandom;
 use OC\Security\TrustedDomainHelper;
 use OC\Session\CryptoWrapper;
@@ -122,21 +124,20 @@ use OC\Tagging\TagMapper;
 use OC\Template\IconsCacher;
 use OC\Template\JSCombiner;
 use OC\Template\SCSSCacher;
-use OC\Dashboard\DashboardManager;
 use OCA\Theming\ImageManager;
 use OCA\Theming\ThemingDefaults;
-
+use OCA\Theming\Util;
 use OCP\Accounts\IAccountManager;
 use OCP\App\IAppManager;
+use OCP\Authentication\LoginCredentials\IStore;
 use OCP\Collaboration\AutoComplete\IManager;
+use OCP\Contacts\ContactsMenu\IActionFactory;
 use OCP\Contacts\ContactsMenu\IContactsStore;
 use OCP\Dashboard\IDashboardManager;
 use OCP\Defaults;
-use OCA\Theming\Util;
 use OCP\Federation\ICloudFederationFactory;
 use OCP\Federation\ICloudFederationProviderManager;
 use OCP\Federation\ICloudIdManager;
-use OCP\Authentication\LoginCredentials\IStore;
 use OCP\Files\NotFoundException;
 use OCP\Files\Storage\IStorageFactory;
 use OCP\FullTextSearch\IFullTextSearchManager;
@@ -148,7 +149,6 @@ use OCP\IInitialStateService;
 use OCP\IL10N;
 use OCP\IServerContainer;
 use OCP\ITempManager;
-use OCP\Contacts\ContactsMenu\IActionFactory;
 use OCP\IUser;
 use OCP\Lock\ILockingProvider;
 use OCP\Log\ILogFactory;
@@ -207,6 +207,7 @@ class Server extends ServerContainer implements IServerContainer {
 				$c->getRootFolder(),
 				$c->getAppDataDir('preview'),
 				$c->getEventDispatcher(),
+				$c->getGeneratorHelper(),
 				$c->getSession()->get('user_id')
 			);
 		});
@@ -2060,4 +2061,14 @@ class Server extends ServerContainer implements IServerContainer {
 	public function getStorageFactory() {
 		return $this->query(IStorageFactory::class);
 	}
+
+	/**
+	 * Get the Preview GeneratorHelper
+	 *
+	 * @return GeneratorHelper
+	 * @since 17.0.0
+	 */
+	public function getGeneratorHelper() {
+		return $this->query(\OC\Preview\GeneratorHelper::class);
+	}
 }
-- 
GitLab