diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-10-25 12:53:10 +0200 |
---|---|---|
committer | backportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com> | 2022-10-27 13:51:28 +0000 |
commit | 677451427ef803b63893b1b5f0b4e0854deb233a (patch) | |
tree | 42be53be8a2a6142699e58b7f942114f69ad9357 /lib | |
parent | aab74bea4054261733d0617597974064ccef1887 (diff) | |
download | nextcloud-server-677451427ef803b63893b1b5f0b4e0854deb233a.tar.gz nextcloud-server-677451427ef803b63893b1b5f0b4e0854deb233a.zip |
Emit typed event when preview is requested
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/Preview/Generator.php | 21 | ||||
-rw-r--r-- | lib/private/PreviewManager.php | 25 | ||||
-rw-r--r-- | lib/private/Server.php | 1 | ||||
-rw-r--r-- | lib/public/Preview/BeforePreviewFetchedEvent.php | 51 |
6 files changed, 81 insertions, 19 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 779758eb9cc..3b5e63a56ff 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -494,6 +494,7 @@ return array( 'OCP\\Notification\\INotifier' => $baseDir . '/lib/public/Notification/INotifier.php', 'OCP\\OCS\\IDiscoveryService' => $baseDir . '/lib/public/OCS/IDiscoveryService.php', 'OCP\\PreConditionNotMetException' => $baseDir . '/lib/public/PreConditionNotMetException.php', + 'OCP\\Preview\\BeforePreviewFetchedEvent' => $baseDir . '/lib/public/Preview/BeforePreviewFetchedEvent.php', 'OCP\\Preview\\IProvider' => $baseDir . '/lib/public/Preview/IProvider.php', 'OCP\\Preview\\IProviderV2' => $baseDir . '/lib/public/Preview/IProviderV2.php', 'OCP\\Preview\\IVersionedPreviewFile' => $baseDir . '/lib/public/Preview/IVersionedPreviewFile.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index b39fadb0321..67ea952103c 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -527,6 +527,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Notification\\INotifier' => __DIR__ . '/../../..' . '/lib/public/Notification/INotifier.php', 'OCP\\OCS\\IDiscoveryService' => __DIR__ . '/../../..' . '/lib/public/OCS/IDiscoveryService.php', 'OCP\\PreConditionNotMetException' => __DIR__ . '/../../..' . '/lib/public/PreConditionNotMetException.php', + 'OCP\\Preview\\BeforePreviewFetchedEvent' => __DIR__ . '/../../..' . '/lib/public/Preview/BeforePreviewFetchedEvent.php', 'OCP\\Preview\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Preview/IProvider.php', 'OCP\\Preview\\IProviderV2' => __DIR__ . '/../../..' . '/lib/public/Preview/IProviderV2.php', 'OCP\\Preview\\IVersionedPreviewFile' => __DIR__ . '/../../..' . '/lib/public/Preview/IVersionedPreviewFile.php', diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index ef44188da74..a49cc8e522e 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 a2d34892c68..0d08ef3eba5 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; @@ -51,7 +52,8 @@ class PreviewManager implements IPreview { protected IConfig $config; protected IRootFolder $rootFolder; protected IAppData $appData; - protected EventDispatcherInterface $eventDispatcher; + protected IEventDispatcher $eventDispatcher; + protected EventDispatcherInterface $legacyEventDispatcher; private ?Generator $generator = null; private GeneratorHelper $helper; protected bool $providerListDirty = false; @@ -73,20 +75,22 @@ class PreviewManager implements IPreview { private IBinaryFinder $binaryFinder; public function __construct( - IConfig $config, - IRootFolder $rootFolder, - IAppData $appData, - EventDispatcherInterface $eventDispatcher, - GeneratorHelper $helper, - ?string $userId, - Coordinator $bootstrapCoordinator, - IServerContainer $container, - IBinaryFinder $binaryFinder + IConfig $config, + IRootFolder $rootFolder, + IAppData $appData, + IEventDispatcher $eventDispatcher, + EventDispatcherInterface $legacyEventDispatcher, + GeneratorHelper $helper, + ?string $userId, + Coordinator $bootstrapCoordinator, + IServerContainer $container, + IBinaryFinder $binaryFinder ) { $this->config = $config; $this->rootFolder = $rootFolder; $this->appData = $appData; $this->eventDispatcher = $eventDispatcher; + $this->legacyEventDispatcher = $legacyEventDispatcher; $this->helper = $helper; $this->userId = $userId; $this->bootstrapCoordinator = $bootstrapCoordinator; @@ -153,6 +157,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 4f2a93677c5..3099dd2b7b8 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -334,6 +334,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'), diff --git a/lib/public/Preview/BeforePreviewFetchedEvent.php b/lib/public/Preview/BeforePreviewFetchedEvent.php new file mode 100644 index 00000000000..37da63b95a1 --- /dev/null +++ b/lib/public/Preview/BeforePreviewFetchedEvent.php @@ -0,0 +1,51 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +namespace OCP\Preview; + +use OCP\Files\Node; + +/** + * @since 25.0.1 + */ +class BeforePreviewFetchedEvent extends \OCP\EventDispatcher\Event { + private Node $node; + + /** + * @since 25.0.1 + */ + public function __construct(Node $node) { + parent::__construct(); + $this->node = $node; + } + + /** + * @since 25.0.1 + */ + public function getNode(): Node { + return $this->node; + } +} |