Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LegacyEventDispatcherProxy for BC support #1537

Merged
merged 5 commits into from Jun 25, 2019

Conversation

jamalo
Copy link
Contributor

@jamalo jamalo commented Jun 24, 2019

Fixes #1530 ?

See: #1531 (comment)

.gitignore Outdated Show resolved Hide resolved
src/Index/Resetter.php Outdated Show resolved Hide resolved
@giovannialbero1992
Copy link
Contributor

giovannialbero1992 commented Jun 25, 2019

@j-mywheels maybe to avoid BC you should add

if (!class_exists(Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy::class))

and use old syntax.

What do you think about this solution?

@jamalo
Copy link
Contributor Author

jamalo commented Jun 25, 2019

@j-mywheels maybe to avoid BC you should add

if (!class_exists(Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy::class))

and use old syntax.

What do you think about this solution?

Yes would be possible to do. I will look at it at the end of the day. Thanks for your feedback @giovannialbero1992

@jamalo
Copy link
Contributor Author

jamalo commented Jun 25, 2019

Done @giovannialbero1992 should work now, tested on SF 3.4 and 4.

@giovannialbero1992
Copy link
Contributor

@j-mywheels yeah :) ... You could rebase in one commit

@XWB
Copy link
Member

XWB commented Jun 25, 2019

Nice job @j-mywheels :)

@boroth
Copy link

boroth commented Jun 25, 2019

@j-mywheels thanks for your work!

@boroth
Copy link

boroth commented Jun 25, 2019

I pulled the new master for my Symfony installation, but I'm still getting the same error:

[
  "exception" => ErrorException {
    #message: "User Deprecated: Calling the "Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch()" method with the event name as first argument is deprecated since Symfony 4.3, pass it second and provide the event object first instead."
    #code: 0
    #file: "./vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php"
    #line: 148
    #severity: E_USER_DEPRECATED
    trace: {
      ./vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:148 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Persister/InPlacePagerPersister.php:78 { …}
      ./vendor/enqueue/elastica-bundle/Queue/PopulateProcessor.php:67 { …}
      ./vendor/enqueue/enqueue/Client/DelegateProcessor.php:38 { …}
      ./vendor/enqueue/enqueue/Consumption/QueueConsumer.php:197 { …}
      Enqueue\Consumption\QueueConsumer->Enqueue\Consumption\{closure}() {}
      ./vendor/enqueue/enqueue/Consumption/FallbackSubscriptionConsumer.php:47 { …}
      ./vendor/enqueue/enqueue/Consumption/QueueConsumer.php:264 { …}
      ./vendor/enqueue/enqueue/Symfony/Client/ConsumeCommand.php:148 { …}
      ./vendor/symfony/console/Command/Command.php:255 { …}
      ./vendor/symfony/console/Application.php:939 { …}
      ./vendor/symfony/framework-bundle/Console/Application.php:87 { …}
      ./vendor/symfony/console/Application.php:273 { …}
      ./vendor/symfony/framework-bundle/Console/Application.php:73 { …}
      ./vendor/symfony/console/Application.php:149 { …}
      ./bin/console:42 {
        › $application = new Application($kernel);
        › $application->run($input);
        ›
      }
    }
  }
]

@giovannialbero1992
Copy link
Contributor

giovannialbero1992 commented Jun 25, 2019 via email

@boroth
Copy link

boroth commented Jun 25, 2019

Yeah, I had to switch my composer.json back to using Symfony 4.3, and then ran composer update. It seems like I have all the right vesrions:

  • 4.3.1 for Symfony
  • friendsofsymfony/elastica-bundle (dev-master d4a2a67)
  • enqueue/enqueue-bundle (0.9.12)

I forgot that originally I did have to fork the enqueue/enqueue-bundle to make adjustments to their ->dispatch() calls, so maybe I need to do the same updates there with the LegacyEventDispatcherProxy for enqueue-bundle and use my forked version instead? I'm on the most recent dev branch for 0.9.* at the moment.

I thought the decorate would handle that for us, and I really like the solution. I can tell that decorate() is being run, so I'm not sure why it's giving me the error.

I'm also gonna try restarting my computer just incase something really weird is going on with my development environment/VMs. I'll have another update shortly.

@boroth
Copy link

boroth commented Jun 25, 2019

I'm not even sure what's going on anymore, but I need to move on so I guess I'm just going to have to run the populate command without the enqueue consumers.

I'm not sure where it broke, or how, but even after going back to the older version of elastica-bundle, my consumers now show no output when I start them, and they aren't monitoring the queue. I realize this is outside the scope of this Issue/PR, so I'll bring this up with the enqueue-bundle team at a later time when I have more time to look into it.

Thanks for your help!

@jamalo
Copy link
Contributor Author

jamalo commented Jun 26, 2019

I'm not even sure what's going on anymore, but I need to move on so I guess I'm just going to have to run the populate command without the enqueue consumers.

I'm not sure where it broke, or how, but even after going back to the older version of elastica-bundle, my consumers now show no output when I start them, and they aren't monitoring the queue. I realize this is outside the scope of this Issue/PR, so I'll bring this up with the enqueue-bundle team at a later time when I have more time to look into it.

Thanks for your help!

Thanks for your feedback. Keep me updated, i tried multiple installations with the PR and worked fine. If you have time you can create an example project? So we can have a look.

@tacman
Copy link
Contributor

tacman commented Jul 17, 2019

It doesn't seem like PopulateCommand is calling dispatcher using the new format.

That is, the LegacyEventDispatcherProxy exists and is being called, but the calls haven't been updated.

I'll create a PR for at least that command and InPlacePersister.

tacman added a commit to tacman/FOSElasticaBundle that referenced this pull request Jul 17, 2019
tacman added a commit to tacman/FOSElasticaBundle that referenced this pull request Jul 17, 2019
@OskarStark
Copy link
Contributor

OskarStark commented Oct 2, 2019

I am using 5.1.1 and have the same problem:

elasticsearch/elasticsearch         v6.7.2  PHP Client for Elasticsearch
friendsofsymfony/elastica-bundle    v5.1.1  Elasticsearch PHP integration for your Symfony project...
ruflin/elastica                     6.1.1   Elasticsearch Client
12:35:30 INFO      [php] User Deprecated: Calling the "Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3, pass it as the second argument and provide the event object as the first argument instead.
[
  "exception" => ErrorException {
    #message: "User Deprecated: Calling the "Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3, pass it as the second argument and provide the event object as the first argument instead."
    #code: 0
    #file: "./vendor/symfony/event-dispatcher/EventDispatcher.php"
    #line: 58
    #severity: E_USER_DEPRECATED
    trace: {
      ./vendor/symfony/event-dispatcher/EventDispatcher.php:58 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Transformer/ModelToElasticaAutoTransformer.php:212 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Transformer/ModelToElasticaAutoTransformer.php:112 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Transformer/ModelToElasticaAutoTransformer.php:191 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Transformer/ModelToElasticaAutoTransformer.php:112 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Transformer/ModelToElasticaAutoTransformer.php:191 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Transformer/ModelToElasticaAutoTransformer.php:90 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Persister/ObjectPersister.php:170 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Persister/ObjectPersister.php:105 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Persister/InPlacePagerPersister.php:113 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Persister/InPlacePagerPersister.php:72 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Command/PopulateCommand.php:265 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Command/PopulateCommand.php:195 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Command/PopulateCommand.php:170 { …}
      ./vendor/symfony/console/Command/Command.php:255 { …}
      ./vendor/symfony/console/Application.php:933 { …}
      ./vendor/symfony/framework-bundle/Console/Application.php:87 { …}
      ./vendor/symfony/console/Application.php:272 { …}
      ./vendor/symfony/framework-bundle/Console/Application.php:73 { …}
      ./vendor/symfony/console/Application.php:148 { …}
      ./bin/console:42 {
        › $application = new Application($kernel);
        › $application->run($input);
        ›
      }
    }
  }
]

@chypriote
Copy link

chypriote commented Oct 21, 2019

Bumping this cause I get the same deprecation error on master.

From my understanding, the point of the LegacyEventDispatcherProxy is to allow you to update your code to the Symfony 4.3 syntax, while still having backward compatibility.
It's still triggering a deprecation error because you are still using the old dispatch() syntax.

If you agree with this, I can probably make a PR to update the syntax

@OskarStark
Copy link
Contributor

OskarStark commented Oct 21, 2019

I think its exactly this and agree with reworking the code to the current state of the art.
A PR would be super awesome 👍

@OskarStark
Copy link
Contributor

@chypriote any news on preparing a PR?

@chypriote
Copy link

I was hoping to get a comment from @XWB or @giovannialbero1992 before working on it

@giovannialbero1992
Copy link
Contributor

Hi @chypriote, yes i believe that it is useful an update on dispatch methods.
I've found this Symfony blog's article https://symfony.com/blog/new-in-symfony-4-3-simpler-event-dispatching#supporting-both-dispatchers , maybe it should be useful.
Let me know, thanks

@XWB
Copy link
Member

XWB commented Oct 23, 2019

I think this:

    public function __construct(EventDispatcherInterface $dispatcher)
    {
        $this->dispatcher = $dispatcher;

        if (class_exists(LegacyEventDispatcherProxy::class)) {
            $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
        }
    }

Should be replaced by this:

    public function __construct(EventDispatcherInterface $dispatcher)
    {
        if (class_exists(LegacyEventDispatcherProxy::class)) {
            $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
        } else {
            $this->dispatcher = $dispatcher;
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues with and the dispatch() method in Symfony 4.3 when using EnqueueBundle
7 participants