summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2022-11-04 17:20:43 +0100
committerGitHub <noreply@github.com>2022-11-04 17:20:43 +0100
commit8b4fe66c14db07b11f713c5566e99fc4c078b5e8 (patch)
tree296b961ee7fdaa046b5b9c9b300d893715e1b4f5 /lib/private
parent89d3c2227e021e2851cd9901945d328087a8f0a1 (diff)
parent6dc2b162c588fa9f9c2ff1989f489cf8b34dab8a (diff)
downloadnextcloud-server-8b4fe66c14db07b11f713c5566e99fc4c078b5e8.tar.gz
nextcloud-server-8b4fe66c14db07b11f713c5566e99fc4c078b5e8.zip
Merge pull request #34855 from nextcloud/backport/34799/stable24
[stable24] Emit typed event when preview is requested
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Preview/Generator.php21
-rw-r--r--lib/private/PreviewManager.php17
-rw-r--r--lib/private/Server.php1
3 files changed, 27 insertions, 12 deletions
diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php
index 2edea868ed0..20a39380568 100644
--- a/lib/private/Preview/Generator.php
+++ b/lib/private/Preview/Generator.php
@@ -29,6 +29,7 @@
*/
namespace OC\Preview;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\IAppData;
use OCP\Files\InvalidPathException;
@@ -40,6 +41,7 @@ use OCP\IConfig;
use OCP\IImage;
use OCP\IPreview;
use OCP\IStreamImage;
+use OCP\Preview\BeforePreviewFetchedEvent;
use OCP\Preview\IProviderV2;
use OCP\Preview\IVersionedPreviewFile;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -56,26 +58,23 @@ class Generator {
/** @var GeneratorHelper */
private $helper;
/** @var EventDispatcherInterface */
+ private $legacyEventDispatcher;
+ /** @var IEventDispatcher */
private $eventDispatcher;
- /**
- * @param IConfig $config
- * @param IPreview $previewManager
- * @param IAppData $appData
- * @param GeneratorHelper $helper
- * @param EventDispatcherInterface $eventDispatcher
- */
public function __construct(
IConfig $config,
IPreview $previewManager,
IAppData $appData,
GeneratorHelper $helper,
- EventDispatcherInterface $eventDispatcher
+ EventDispatcherInterface $legacyEventDispatcher,
+ IEventDispatcher $eventDispatcher
) {
$this->config = $config;
$this->previewManager = $previewManager;
$this->appData = $appData;
$this->helper = $helper;
+ $this->legacyEventDispatcher = $legacyEventDispatcher;
$this->eventDispatcher = $eventDispatcher;
}
@@ -102,10 +101,14 @@ class Generator {
'crop' => $crop,
'mode' => $mode,
];
- $this->eventDispatcher->dispatch(
+
+ $this->legacyEventDispatcher->dispatch(
IPreview::EVENT,
new GenericEvent($file, $specification)
);
+ $this->eventDispatcher->dispatchTyped(new BeforePreviewFetchedEvent(
+ $file
+ ));
// since we only ask for one preview, and the generate method return the last one it created, it returns the one we want
return $this->generatePreviews($file, [$specification], $mimeType);
diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php
index 6c17dd58b4b..c347ceafb92 100644
--- a/lib/private/PreviewManager.php
+++ b/lib/private/PreviewManager.php
@@ -34,6 +34,7 @@ use OC\AppFramework\Bootstrap\Coordinator;
use OC\Preview\Generator;
use OC\Preview\GeneratorHelper;
use OCP\AppFramework\QueryException;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\IAppData;
use OCP\Files\IRootFolder;
@@ -56,9 +57,12 @@ class PreviewManager implements IPreview {
/** @var IAppData */
protected $appData;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
protected $eventDispatcher;
+ /** @var EventDispatcherInterface */
+ protected $legacyEventDispatcher;
+
/** @var Generator */
private $generator;
@@ -103,13 +107,18 @@ class PreviewManager implements IPreview {
* @param IConfig $config
* @param IRootFolder $rootFolder
* @param IAppData $appData
- * @param EventDispatcherInterface $eventDispatcher
+ * @param IEventDispatcher $eventDispatcher
+ * @param EventDispatcherInterface $legacyEventDispatcher
+ * @param GeneratorHelper $helper
* @param string $userId
+ * @param Coordinator $bootstrapCoordinator
+ * @param IServerContainer $container
*/
public function __construct(IConfig $config,
IRootFolder $rootFolder,
IAppData $appData,
- EventDispatcherInterface $eventDispatcher,
+ IEventDispatcher $eventDispatcher,
+ EventDispatcherInterface $legacyEventDispatcher,
GeneratorHelper $helper,
$userId,
Coordinator $bootstrapCoordinator,
@@ -118,6 +127,7 @@ class PreviewManager implements IPreview {
$this->rootFolder = $rootFolder;
$this->appData = $appData;
$this->eventDispatcher = $eventDispatcher;
+ $this->legacyEventDispatcher = $legacyEventDispatcher;
$this->helper = $helper;
$this->userId = $userId;
$this->bootstrapCoordinator = $bootstrapCoordinator;
@@ -185,6 +195,7 @@ class PreviewManager implements IPreview {
$this->rootFolder,
$this->config
),
+ $this->legacyEventDispatcher,
$this->eventDispatcher
);
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index e70d9d2a7b2..0d67012e70d 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -328,6 +328,7 @@ class Server extends ServerContainer implements IServerContainer {
$c->get(IRootFolder::class),
$c->get(SystemConfig::class)
),
+ $c->get(IEventDispatcher::class),
$c->get(SymfonyAdapter::class),
$c->get(GeneratorHelper::class),
$c->get(ISession::class)->get('user_id'),