0

Trying to deploy my updated Symfony2 application, I ran into the following problem.

(note that my application uses the new Symfony 3 directory structure. replace bin/console with app/console and var/cache with app/cache if you're using the current directory structure)

I have recently renamed one of my service classes (VariantSlugListener). When deploying the application on the staging server, I got the following error when running bin/console assetic:dump --env=prod:

PHP Fatal error: Class 'MyBundle\Listener\VariantSlugListener' not found in /var/www/example.com/staging/var/cache/prod/appProdProjectContainer.php on line 494

Line 494 of appProdProjectContainer.php contains the following code:

return $this->services['3f288d4f09c9906944ba7e17358f669b942397baf9d79d5ff0737bb756df7023_1'] = new \MyBundle\Listener\VariantSlugListener();

It is no surprise that \MyBundle\Listener\VariantSlugListener can not be found, since it has been renamed to \MyBundle\EventListener\VariantSlugSubscriber with the latest update. The solution would be to simply clear Symfony's cache.

However, when trying to clear the cache (using bin/console cache:clear --env=prod) I get the exact same error as with the assetic:dump command. So I get an error because my Symfony cache is outdated, but I can not clear the cache because of the error.

I can probably get around this by manually deleting the contents of the var/cache directory, but that doesn't feel like the best solution.

Am I missing something?

Community
  • 1
  • 1
Nic Wortel
  • 11,155
  • 6
  • 60
  • 79
  • 1
    the prod environment is not designed to change php filenames, so sduo rm -rf var/cache* – john Smith Jan 15 '15 at 13:19
  • Hey John, I forgot to mention. I made the changes on my local development machine and then deployed them to the server using git. Is Symfony's cache not able to handle this? – Nic Wortel Jan 16 '15 at 09:27
  • maybe you forgot to add var/cache to .gitignore ? personally i would prefer to let your deployment script remove the contents of var/cache after deployment – john Smith Jan 16 '15 at 11:09
  • @johnSmith maybe that is a good idea. I just thought that `cache:clear` would suffice. It also feels a bit cleaner than removing the cache directory's contents. – Nic Wortel Jan 16 '15 at 12:27

1 Answers1

1

Probably you are triggering some events that are handled in your VariantSlugListener when doing 'cache:clear'. So your only choice is to just remove contents of the cache directory or to replace the value manually and then run cache:clear to warm up the cache.

nikita2206
  • 1,129
  • 2
  • 10
  • 17
  • The `VariantSlugListener` class was a Doctrine event listener that was being triggered on the `prePersist` event. So it shouldn't be called during the `cache:clear` command...? – Nic Wortel Jan 16 '15 at 09:52
  • @Nic You'll have to debug it with xdebug. Just go the line of where container tries to instantiate new VariantSlugListener and set a breakpoint. Run the script and by the stack trace you'll able to get a grasp of who is calling it... – nikita2206 Jan 16 '15 at 11:27