<commit_before><?php
/**
 * @package     Mautic
 * @copyright   2014 Mautic Contributors. All rights reserved.
 * @author      Mautic
 * @link        http://mautic.org
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */

namespace Mautic\WebhookBundle\EventListener;

use JMS\Serializer\Serializer;
use Mautic\WebhookBundle\EventListener\WebhookSubscriberBase;
use Mautic\CoreBundle\Factory\MauticFactory;
use Doctrine\ORM\NoResultException;
use Mautic\CoreBundle\EventListener\CommonSubscriber;
use Mautic\LeadBundle\LeadEvents;
use Mautic\LeadBundle\Event\LeadEvent;
use Mautic\LeadBundle\Event\PointsChangeEvent;
use Mautic\ApiBundle\Serializer\Exclusion\PublishDetailsExclusionStrategy;


/**
 * Class LeadSubscriber
 *
 * @package Mautic\Webhook\EventListener
 */
class LeadSubscriber extends WebhookSubscriberBase
{
    // the groups for leads
    protected $serializerGroups = array("leadDetails", "userList", "publishDetails", "ipAddress");

    /**
     * @return array
     */
    static public function getSubscribedEvents ()
    {
        return array(
            LeadEvents::LEAD_POST_SAVE            => array('onLeadNewUpdate', 0),
            LeadEvents::LEAD_POINTS_CHANGE        => array('onLeadPointChange', 0),
            LeadEvents::LEAD_POST_DELETE          => array('onLeadDelete', 0),
            //LeadEvents::LEAD_LIST_BATCH_CHANGE  => array('onLeadEvent', 0),
            //LeadEvents::LEAD_POST_MERGE         => array('onLeadEvent', 0),
            //LeadEvents::LEAD_IDENTIFIED         => array('onLeadEvent', 0),
            //LeadEvents::CURRENT_LEAD_CHANGED    => array('onLeadEvent', 0)
        );
    }

    /*
     * Generic method to execute when a lead does something
     */
    public function onLeadNewUpdate(LeadEvent $event)
    {
        $entity = $event->getLead();

        // serializer gives us json
        $payload = $this->serializeData($entity);

        // get the leads
        if ($event->isNew()) {
            // get our new lead webhook events first
            $webhookEvents = $this->getEventWebooksByType(LeadEvents::LEAD_POST_SAVE . '.new');
            $this->webhookModel->QueueWebhooks($webhookEvents, $payload, true);
        }

        // now deal with webhooks for the update event
        if (! $event->isNew()) {
            $webhookEvents = $this->getEventWebooksByType(LeadEvents::LEAD_POST_SAVE . '.update');
            $this->webhookModel->QueueWebhooks($webhookEvents, $payload, true);
        }
    }

    /*
     * Method to execute when the lead point value changes.abstract
     * Queues the event payload into the webhook queue so it can be processed
     */
    public function onLeadPointChange(PointsChangeEvent $event)
    {
        /** @var \Mautic\LeadBundle\Entity\Lead $lead */
        $lead                 = $event->getLead();
        $leadArray            = $lead->convertToArray();
        $points['old_points'] = $event->getOldPoints();
        $points['new_points'] = $event->getNewPoints();

        // build the payload
        $payload = json_encode(array_merge($leadArray, $points));

        $types    = array(LeadEvents::LEAD_POINTS_CHANGE);
        $webhooks = $this->getWebhooksByTypes($types);
        $this->webhookModel->QueueWebhooks($webhooks, $payload, true);
    }

    /*
     * Delete lead event
     */
    public function onLeadDelete($event)
    {
        // content
    }
}<commit_msg>clean up point change function<commit_after><?php
/**
 * @package     Mautic
 * @copyright   2014 Mautic Contributors. All rights reserved.
 * @author      Mautic
 * @link        http://mautic.org
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */

namespace Mautic\WebhookBundle\EventListener;

use JMS\Serializer\Serializer;
use Mautic\WebhookBundle\EventListener\WebhookSubscriberBase;
use Mautic\CoreBundle\Factory\MauticFactory;
use Doctrine\ORM\NoResultException;
use Mautic\CoreBundle\EventListener\CommonSubscriber;
use Mautic\LeadBundle\LeadEvents;
use Mautic\LeadBundle\Event\LeadEvent;
use Mautic\LeadBundle\Event\PointsChangeEvent;
use Mautic\ApiBundle\Serializer\Exclusion\PublishDetailsExclusionStrategy;


/**
 * Class LeadSubscriber
 *
 * @package Mautic\Webhook\EventListener
 */
class LeadSubscriber extends WebhookSubscriberBase
{
    // the groups for leads
    protected $serializerGroups = array("leadDetails", "userList", "publishDetails", "ipAddress");

    /**
     * @return array
     */
    static public function getSubscribedEvents ()
    {
        return array(
            LeadEvents::LEAD_POST_SAVE            => array('onLeadNewUpdate', 0),
            LeadEvents::LEAD_POINTS_CHANGE        => array('onLeadPointChange', 0),
            LeadEvents::LEAD_POST_DELETE          => array('onLeadDelete', 0),
            //LeadEvents::LEAD_LIST_BATCH_CHANGE  => array('onLeadEvent', 0),
            //LeadEvents::LEAD_POST_MERGE         => array('onLeadEvent', 0),
            //LeadEvents::LEAD_IDENTIFIED         => array('onLeadEvent', 0),
            //LeadEvents::CURRENT_LEAD_CHANGED    => array('onLeadEvent', 0)
        );
    }

    /*
     * Generic method to execute when a lead does something
     */
    public function onLeadNewUpdate(LeadEvent $event)
    {
        $entity = $event->getLead();

        // serializer gives us json
        $payload = $this->serializeData($entity);

        // get the leads
        if ($event->isNew()) {
            // get our new lead webhook events first
            $webhookEvents = $this->getEventWebooksByType(LeadEvents::LEAD_POST_SAVE . '.new');
            $this->webhookModel->QueueWebhooks($webhookEvents, $payload, true);
        }

        // now deal with webhooks for the update event
        if (! $event->isNew()) {
            $webhookEvents = $this->getEventWebooksByType(LeadEvents::LEAD_POST_SAVE . '.update');
            $this->webhookModel->QueueWebhooks($webhookEvents, $payload, true);
        }
    }

    /*
     * Method to execute when the lead point value changes.abstract
     * Queues the event payload into the webhook queue so it can be processed
     */
    public function onLeadPointChange(PointsChangeEvent $event)
    {
        /** @var \Mautic\LeadBundle\Entity\Lead $lead */
        $lead = $event->getLead();

        $payload = array(
            'lead' => json_decode($this->serializeData($lead)),
            'points' => array(
                'old_points' => $event->getOldPoints(),
                'new_points' => $event->getNewPoints()
            )
        );

        $types    = array(LeadEvents::LEAD_POINTS_CHANGE);
        $webhooks = $this->getEventWebooksByType($types);
        $this->webhookModel->QueueWebhooks($webhooks, json_encode($payload), true);
    }

    /*
     * Delete lead event
     */
    public function onLeadDelete($event)
    {
        // content
    }
}
{'fraction_non_alphanumeric': 0.12189781021897811, 'fraction_numerical': 0.004087591240875913, 'mean_word_length': 2.636411889596603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3224742', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1992, 'n_words': 394}