fix!: Remove legacy event dispatching Symfony's GenericEvent

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/39571/head
Joas Schilling 1 year ago
parent 582e655c01
commit 4f7de8ed60
No known key found for this signature in database
GPG Key ID: C400AAF20C1BB6FC
  1. 10
      lib/private/Preview/Generator.php
  2. 5
      lib/private/PreviewManager.php
  3. 1
      lib/private/Server.php
  4. 6
      lib/public/IPreview.php
  5. 79
      tests/lib/Preview/GeneratorTest.php

@ -44,8 +44,6 @@ use OCP\IStreamImage;
use OCP\Preview\BeforePreviewFetchedEvent;
use OCP\Preview\IProviderV2;
use OCP\Preview\IVersionedPreviewFile;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class Generator {
public const SEMAPHORE_ID_ALL = 0x0a11;
@ -59,8 +57,6 @@ class Generator {
private $appData;
/** @var GeneratorHelper */
private $helper;
/** @var EventDispatcherInterface */
private $legacyEventDispatcher;
/** @var IEventDispatcher */
private $eventDispatcher;
@ -69,14 +65,12 @@ class Generator {
IPreview $previewManager,
IAppData $appData,
GeneratorHelper $helper,
EventDispatcherInterface $legacyEventDispatcher,
IEventDispatcher $eventDispatcher
) {
$this->config = $config;
$this->previewManager = $previewManager;
$this->appData = $appData;
$this->helper = $helper;
$this->legacyEventDispatcher = $legacyEventDispatcher;
$this->eventDispatcher = $eventDispatcher;
}
@ -104,10 +98,6 @@ class Generator {
'mode' => $mode,
];
$this->legacyEventDispatcher->dispatch(
IPreview::EVENT,
new GenericEvent($file, $specification)
);
$this->eventDispatcher->dispatchTyped(new BeforePreviewFetchedEvent(
$file,
$width,

@ -46,7 +46,6 @@ 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 {
@ -54,7 +53,6 @@ class PreviewManager implements IPreview {
protected IRootFolder $rootFolder;
protected IAppData $appData;
protected IEventDispatcher $eventDispatcher;
protected EventDispatcherInterface $legacyEventDispatcher;
private ?Generator $generator = null;
private GeneratorHelper $helper;
protected bool $providerListDirty = false;
@ -81,7 +79,6 @@ class PreviewManager implements IPreview {
IRootFolder $rootFolder,
IAppData $appData,
IEventDispatcher $eventDispatcher,
EventDispatcherInterface $legacyEventDispatcher,
GeneratorHelper $helper,
?string $userId,
Coordinator $bootstrapCoordinator,
@ -93,7 +90,6 @@ 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;
@ -161,7 +157,6 @@ class PreviewManager implements IPreview {
$this->rootFolder,
$this->config
),
$this->legacyEventDispatcher,
$this->eventDispatcher
);
}

@ -340,7 +340,6 @@ class Server extends ServerContainer implements IServerContainer {
$c->get(SystemConfig::class)
),
$c->get(IEventDispatcher::class),
$c->get(SymfonyAdapter::class),
$c->get(GeneratorHelper::class),
$c->get(ISession::class)->get('user_id'),
$c->get(Coordinator::class),

@ -38,12 +38,6 @@ use OCP\Files\SimpleFS\ISimpleFile;
* @since 6.0.0
*/
interface IPreview {
/**
* @since 9.2.0
* @deprecated 22.0.0
*/
public const EVENT = self::class . ':' . 'PreviewRequested';
public const MODE_FILL = 'fill';
public const MODE_COVER = 'cover';

@ -35,8 +35,6 @@ use OCP\IConfig;
use OCP\IPreview;
use OCP\Preview\BeforePreviewFetchedEvent;
use OCP\Preview\IProviderV2;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class GeneratorTest extends \Test\TestCase {
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
@ -54,9 +52,6 @@ class GeneratorTest extends \Test\TestCase {
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
private $eventDispatcher;
/** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */
private $legacyEventDispatcher;
/** @var Generator */
private $generator;
@ -68,14 +63,12 @@ class GeneratorTest extends \Test\TestCase {
$this->appData = $this->createMock(IAppData::class);
$this->helper = $this->createMock(GeneratorHelper::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->legacyEventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->generator = new Generator(
$this->config,
$this->previewManager,
$this->appData,
$this->helper,
$this->legacyEventDispatcher,
$this->eventDispatcher
);
}
@ -112,17 +105,6 @@ class GeneratorTest extends \Test\TestCase {
$previewFolder->method('getDirectoryListing')
->willReturn([$maxPreview, $previewFile]);
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file) {
return $event->getSubject() === $file &&
$event->getArgument('width') === 100 &&
$event->getArgument('height') === 100;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL));
@ -251,17 +233,6 @@ class GeneratorTest extends \Test\TestCase {
->method('putContent')
->with('my resized data');
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file) {
return $event->getSubject() === $file &&
$event->getArgument('width') === 100 &&
$event->getArgument('height') === 100;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL));
@ -301,19 +272,6 @@ class GeneratorTest extends \Test\TestCase {
->with($this->equalTo('1024-512-crop.png'))
->willThrowException(new NotFoundException());
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file) {
return $event->getSubject() === $file &&
$event->getArgument('width') === 1024 &&
$event->getArgument('height') === 512 &&
$event->getArgument('crop') === true &&
$event->getArgument('mode') === IPreview::MODE_COVER;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER));
@ -351,19 +309,6 @@ class GeneratorTest extends \Test\TestCase {
$this->previewManager->expects($this->never())
->method('isMimeSupported');
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file) {
return $event->getSubject() === $file &&
$event->getArgument('width') === 1024 &&
$event->getArgument('height') === 512 &&
$event->getArgument('crop') === true &&
$event->getArgument('mode') === IPreview::MODE_COVER;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER));
@ -392,17 +337,6 @@ class GeneratorTest extends \Test\TestCase {
$this->previewManager->method('getProviders')
->willReturn([]);
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file) {
return $event->getSubject() === $file &&
$event->getArgument('width') === 100 &&
$event->getArgument('height') === 100;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL));
@ -528,19 +462,6 @@ class GeneratorTest extends \Test\TestCase {
->with($this->equalTo($filename))
->willReturn($preview);
$this->legacyEventDispatcher->expects($this->once())
->method('dispatch')
->with(
$this->equalTo(IPreview::EVENT),
$this->callback(function (GenericEvent $event) use ($file, $reqX, $reqY, $crop, $mode) {
return $event->getSubject() === $file &&
$event->getArgument('width') === $reqX &&
$event->getArgument('height') === $reqY &&
$event->getArgument('crop') === $crop &&
$event->getArgument('mode') === $mode;
})
);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with(new BeforePreviewFetchedEvent($file, $reqX, $reqY, $crop, $mode));

Loading…
Cancel
Save