pixelant / pxa_social_feed

Social feed as a TYPO3 CMS extension
23 stars 30 forks source link

[BUG] Unable to use signal/slot (v11) #134

Closed dogawaf closed 1 year ago

dogawaf commented 1 year ago

Describe the bug Unable to use signal/slot: the slot is never called.

To Reproduce

Register a slot in your ext_localconf.php:


$signalSlotDispatcher = GeneralUtility::makeInstance(Dispatcher::class);
    $signalSlotDispatcher->connect(
        \Pixelant\PxaSocialFeed\Feed\Update\TwitterFeedUpdater::class,
        'beforeUpdateTwitterFeed',
        \Site\PxaSocialFeed\Event\Slot\BeforeUpdateTwitterFeedSlot::class,
        'BeforeUpdateTwitterFeed'
    );

Then import a twitter feed.

Expected behavior

The registered slot should be called if the feed creates/updates a tweet. It is not.

Additional context

The issue is with DI and the way the Dispatcher is instanciated in \Pixelant\PxaSocialFeed\SignalSlot\EmitSignalTrait::getSignalSlotDispatcher()

In the ext_localconf.php, no constructor argument is passed to GeneralUtility::makeInstance. This way, the DI will use the symfony container, and the singleton will stay in it.

But, when the signal is emitted and the Dispatcher is retreived in \EmitSignalTrait::getSignalSlotDispatcher(), some constructor arguments are passed to GeneralUtility::makeInstance, and the singleton will be retreive from GeneralUtility::$singletonInstances.

To fix it, the Dispatcher should be instanciated with no constructor arguments in \EmitSignalTrait::getSignalSlotDispatcher(), in order to get the singleton from the symfony container.

MattiasNilsson commented 1 year ago

@dogawaf Thanks for your report, we will look into it. Do you have some more information about where to change the signal?

dogawaf commented 1 year ago

Hello

Here is a working patch:

--- a/Classes/SignalSlot/EmitSignalTrait.php    2022-11-23 20:29:43.074846382 +0100
+++ v/Classes/SignalSlot/EmitSignalTrait.php    2022-11-23 20:15:56.136000000 +0100
@@ -45,9 +45,7 @@
     {
         if ($this->signalSlotDispatcher === null) {
             $this->signalSlotDispatcher = GeneralUtility::makeInstance(
-                Dispatcher::class,
-                GeneralUtility::makeInstance(ObjectManager::class),
-                GeneralUtility::makeInstance(Logger::class, 'PxaSocialFeed')
+                Dispatcher::class
             );
         }
dogawaf commented 1 year ago

Fixed with https://github.com/pixelant/pxa_social_feed/pull/137