2014-02-07 2 views
2

Я сделал некоторый пользовательский прослушиватель исключений, поэтому в базе данных в таблице у меня есть старый url, который теперь является ошибкой 404 и другим URL-адресом, к которому пользователь должен быть перенаправлен, когда он достигнет старый url. Проблема в том, что все работает нормально в среде DEV, но у меня возникла проблема, чтобы заставить ее работать в среде PROD (она выбрасывает 503 Service Unavailable Error).Symfony2: пользовательский Exception Listener, не работающий над производством env

Кто-нибудь может знать, что может быть неправильным?

services.yml:

services: 
    coupons.exception.action_listener: 
     class: Coupons\WebBundle\EventListener\ExceptionListener 
     arguments: [@service_container, @templating] 
     tags: 
      - { name: kernel.event_listener, event: kernel.exception, method: onKernelException } 

ExecptionListener:

namespace Coupons\WebBundle\EventListener; 

use Symfony\Component\DependencyInjection\ContainerInterface; 
use Symfony\Bundle\TwigBundle\TwigEngine; 
use Symfony\Component\HttpFoundation\RedirectResponse; 
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 

class ExceptionListener 
{ 
    /** 
    * @var ContainerInterface 
    */ 
    protected $container; 

    /** 
    * @var TwigEngine 
    */ 
    protected $templating; 


    /** 
    * @param ContainerInterface $container 
    */ 
    public function __construct(ContainerInterface $container, TwigEngine $templating){ 
     // assign value(s) 
     $this->container = $container; 
     $this->templating = $templating; 
    } 

    /** 
    * 
    * @param GetResponseForExceptionEvent $event 
    */ 
    public function onKernelException(GetResponseForExceptionEvent $event) 
    { 
     // get exception 
     $exception = $event->getException(); 

     // get path 
     $path = $event->getRequest()->getPathInfo(); 
     $url = $event->getRequest()->getUri(); 

     $repository = $this->container->get('doctrine')->getRepository('CouponsWebBundle:SeoNotFound'); 


     $seonotfound = $repository->createQueryBuilder('s') 
      ->where('s.urlFrom LIKE :url') 
      ->andWhere('s.status = 1') 
      ->setParameter('url', $url.'%') 
      ->getQuery() 
      ->getOneOrNullResult(); 

     if($seonotfound != NULL){ 
      $event->setResponse(new RedirectResponse($seonotfound->getUrlTo(),$seonotfound->getRedirectType())); 
     } 

    } 
} 
+1

Очистить кеш? Есть ли что-либо в журналах сервера? –

ответ

2

Возможно, вы получаете еще одно исключение в вашем исключения слушателем, проверьте файл журнала Symfony в.

Смежные вопросы