Hello,

I've been trying to figure out an issue with an event in one of my 
controllers for a few days now and I'm a bit stuck. First of all, this event 
is triggered just fine on my local system in both my dev and prod 
environments. But I can't get the event to trigger on my server. The event 
gets triggered when data gets posted to my controller. It's supposed to 
update some information in the database based on the data that's posted to 
it.

This is the line of code that is failing to execute (see approvedAction() 
below):
$this->dispatcher->dispatch(Events::onSaveSubscription, new 
SaveSubscriptionEvent($subscription, $signup));

The problem is that the data gets posted in the background via an external 
payment processor script. So I'm unable to easily debug this. Any debugging 
info that gets output on the server is lost. I've confirmed that the data is 
correctly being posted to the server and that all of my objects are being 
constructed correctly. But the event is never dispatched. I've cleared my 
cache, completely reinstalled my entire site on the server, and repeatedly 
tested each component of this thing and everything appears to be 
fine...except the event is never dispatched. The problem is never logged in 
either my production environment or development environment. I'm at a 
complete loss as to why the event is never getting dispatched.

Some help would be greatly appreciated. The relevant code is below:

class BillingController extends ContainerAware
{
// ...    
    private $subscriptionManager;
    private $security;
    private $session;
    private $dispatcher;
    
    public function __construct(SubscriptionManagerInterface 
$subscriptionManager, SecurityContextInterface $security, Session $session, 
EventDispatcherInterface $dispatcher)
    {
        $this->subscriptionManager = $subscriptionManager;
        $this->security            = $security;
        $this->session             = $session;
        $this->dispatcher          = $dispatcher;
    }

    public function approvedAction()
    {
        $request      = $this->container->get('request');
        $subscription = null;
        $user         = null;
        
        if ($request->getMethod() == 'POST')
        {
            $subscription = 
$this->subscriptionManager->createFromPost($request->request);
            $subscription->setReasonForDecline(null);
            $subscription->setReasonForDeclineCode(null);

            $signup = new Signup();
            $signup->setId($request->request->get('sid'));
            $signup->setSubscriptionId($subscription->getId());
          
            $this->dispatcher->dispatch(Events::onSaveSubscription, new 
SaveSubscriptionEvent($subscription, $signup));

            return new Response('Subscription added', 302);
        }
        else
        {
            if ($this->session->has('signup_id'))
            {
                $signupId = $this->session->get('signup_id');
                $user = $this->security->getToken()->getUser();
                
                $subscription = 
$this->subscriptionManager->findBySignupId($signupId);
                $this->subscriptionManager->removeSignup(new 
Signup($signupId));
                $this->session->remove('signup_id');
            }

            if (!($subscription instanceof SubscriptionInterface))
            {
                throw new RuntimeException('Unable to find sign-up ID');
            }

            return 
$this->container->get('templating')->renderResponse('LWProdCCBillBundle:Billing:subscription_approved.html.twig',
 
array(
                'subscription' => $subscription,
                'user'         => $user
            ));
        }
    }
}

Here's my Event class:

class SaveSubscriptionEvent extends Event
{
    protected $subscription;
    protected $signup;
    
    public function __construct(SubscriptionInterface $subscription, 
SignupInterface $signup)
    {
        $this->subscription = $subscription;
        $this->signup       = $signup;
    }
    
    public function getSubscription()
    {
        return $this->subscription;
    }
    
    public function getSignup()
    {
        return $this->signup;
    }
}

Here's my listener:

class SaveSubscriptionListener extends ContainerAware
{
    private $subscriptionManager;
    
    public function __construct(SubscriptionManagerInterface 
$subscriptionManager)
    {
        $this->subscriptionManager = $subscriptionManager;
    }
    
    public function onSaveSubscription(SaveSubscriptionEvent $event)
    {
        $subscription = $event->getSubscription();
        $signup       = $event->getSignup();

        $subscription->setUserId(-1);
        $subscription->setActive(false);
        $subscription->setExpired(false);
        
        $this->subscriptionManager->updateSubscription($subscription);
        $this->subscriptionManager->updateSignup($signup);
    }
}

My Events class:

final class Events
{
    const onNewSubscription      = 'onNewSubscription';
    const onSaveSubscription     = 'onSaveSubscription';
    const onActivateSubscription = 'onActivateSubscription';
    const onCancelSubscription   = 'onCancelSubscription';
}

And finally, here's my service definition:

<?xml version="1.0" encoding="UTF-8"?>

<container xmlns="http://symfony.com/schema/dic/services";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://symfony.com/schema/dic/services 
http://symfony.com/schema/dic/services/services-1.0.xsd";>

    <parameters>
        <parameter 
key="lw_prod_cc_bill.billing.subscription_listener.save.class">LWProd\Bundle\CCBillBundle\Billing\SaveSubscriptionListener</parameter>
    </parameters>

    <services>       
        <service id="lw_prod_cc_bill.billing.subscription_listener.save" 
class="%lw_prod_cc_bill.billing.subscription_listener.save.class%">
            <argument type="service" 
id="lw_prod_cc_bill.subscription_manager" />
            <call method="setContainer">
                <argument type="service" id="service_container" />
            </call>
            <tag name="kernel.listener" event="onSaveSubscription" 
priority="0" />
        </service>
    </services>

</container>

Thanks!

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to