<commit_before><?php
/**
 * MBC_LoggingProcessor_UserTransactions_Consumer:
 * 
 */

namespace DoSomething\MBC_LoggingProcessor;

use DoSomething\MB_Toolbox\MB_Configuration;
use DoSomething\StatHat\Client as StatHat;
use DoSomething\MB_Toolbox\MB_Toolbox_cURL;
use DoSomething\MB_Toolbox\MB_Toolbox_BaseConsumer;
use \Exception;

/**
 * MBC_LoggingProcessor_UserTransactions_Consumer class - .
 */
class MBC_LoggingProcessor_UserTransactions_Consumer extends MB_Toolbox_BaseConsumer
{

  /**
   * Connection to loggingGatewayExchange.
   *
   * @var object $mbLoggingGateway
   */
  private $mbLoggingGateway;

  /**
   * Values for message to be sent to LoggingGatewayExchange.
   *
   * @var array $submission
   */
  private $submission;

  /**
   * Constructor for MBC_LoggingGateway
   */
  public function __construct() {

    parent::__construct();
    $this->mbLoggingGateway = $this->mbConfig->getProperty('messageBroker_LoggingGateway');
  }

  /**
   * Callback for messages arriving in the LoggingQueue.
   *
   * @param string $payload
   *   A seralized message to be processed.
   */
  public function consumeLoggingQueue($payload) {

    echo '-------  mbc-logging-processor_userTransactionals -  MBC_LoggingProcessor_UserTransactions_Consumer->consumeLoggingQueue() START -------', PHP_EOL;

    parent::consumeQueue($payload);
    $this->logConsumption('email');

    if ($this->canProcess()) {

      try {

        $this->setter($this->message);
        $this->process();
      }
      catch(Exception $e) {
        echo 'Error logging transaction for email address: ' . $this->message['email'] . '. Error: ' . $e->getMessage();

        // @todo: Send copy of message to "dead message queue" with details of the original processing: date,
        // origin queue, processing app. The "dead messages" queue can be used to monitor health.
      }

    }
    else {
      echo '- ' . $this->message['email'] . ' can\'t be processed, removing from queue.', PHP_EOL;
      $this->messageBroker->sendAck($this->message['payload']);

      // @todo: Send copy of message to "dead message queue" with details of the original processing: date,
      // origin queue, processing app. The "dead messages" queue can be used to monitor health.
    }

    echo '-------  mbc-logging-processor_userTransactionals -  MBC_LoggingProcessor_UserTransactions_Consumer->consumeLoggingQueue() END -------', PHP_EOL . PHP_EOL;
  }

  /**
   * Conditions to test before processing the message.
   *
   * @return boolean
   */
  protected function canProcess() {

    if (!(isset($this->message['email']))) {
      echo '- canProcess(), email not set.', PHP_EOL;
      return FALSE;
    }
    if (!(isset($this->message['activity']))) {
      echo '- canProcess(), activity not set.', PHP_EOL;
      return FALSE;
    }

    $transactionActivities = [
      'user_register',
      'user_password',
      'campaign_signup',
      'campaign_reportback',
    ];
    if (!(in_array($this->message['activity'], $transactionActivities))) {
      echo '- canProcess(), activity not user transaction.', PHP_EOL;
      return FALSE;
    }

    return TRUE;
  }

  /**
   * Construct values for submission to email service.
   *
   * @param array $message
   *   The message to process based on what was collected from the queue being processed.
   */
  protected function setter($message) {

    $this->submission = [];<commit_msg>Add support for logging user import transactionals<commit_after><?php
/**
 * MBC_LoggingProcessor_UserTransactions_Consumer:
 * 
 */

namespace DoSomething\MBC_LoggingProcessor;

use DoSomething\MB_Toolbox\MB_Configuration;
use DoSomething\StatHat\Client as StatHat;
use DoSomething\MB_Toolbox\MB_Toolbox_cURL;
use DoSomething\MB_Toolbox\MB_Toolbox_BaseConsumer;
use \Exception;

/**
 * MBC_LoggingProcessor_UserTransactions_Consumer class - .
 */
class MBC_LoggingProcessor_UserTransactions_Consumer extends MB_Toolbox_BaseConsumer
{

  /**
   * Connection to loggingGatewayExchange.
   *
   * @var object $mbLoggingGateway
   */
  private $mbLoggingGateway;

  /**
   * Values for message to be sent to LoggingGatewayExchange.
   *
   * @var array $submission
   */
  private $submission;

  /**
   * Constructor for MBC_LoggingGateway
   */
  public function __construct() {

    parent::__construct();
    $this->mbLoggingGateway = $this->mbConfig->getProperty('messageBroker_LoggingGateway');
  }

  /**
   * Callback for messages arriving in the LoggingQueue.
   *
   * @param string $payload
   *   A seralized message to be processed.
   */
  public function consumeLoggingQueue($payload) {

    echo '-------  mbc-logging-processor_userTransactionals -  MBC_LoggingProcessor_UserTransactions_Consumer->consumeLoggingQueue() START -------', PHP_EOL;

    parent::consumeQueue($payload);
    $this->logConsumption('email');

    if ($this->canProcess()) {

      try {

        $this->setter($this->message);
        $this->process();
      }
      catch(Exception $e) {
        echo 'Error logging transaction for email address: ' . $this->message['email'] . '. Error: ' . $e->getMessage();

        // @todo: Send copy of message to "dead message queue" with details of the original processing: date,
        // origin queue, processing app. The "dead messages" queue can be used to monitor health.
      }

    }
    else {
      echo '- ' . $this->message['email'] . ' can\'t be processed, removing from queue.', PHP_EOL;
      $this->messageBroker->sendAck($this->message['payload']);

      // @todo: Send copy of message to "dead message queue" with details of the original processing: date,
      // origin queue, processing app. The "dead messages" queue can be used to monitor health.
    }

    echo '-------  mbc-logging-processor_userTransactionals -  MBC_LoggingProcessor_UserTransactions_Consumer->consumeLoggingQueue() END -------', PHP_EOL . PHP_EOL;
  }

  /**
   * Conditions to test before processing the message.
   *
   * @return boolean
   */
  protected function canProcess() {

    if (!(isset($this->message['email']))) {
      echo '- canProcess(), email not set.', PHP_EOL;
      return FALSE;
    }
    if (!(isset($this->message['activity']))) {
      echo '- canProcess(), activity not set.', PHP_EOL;
      return FALSE;
    }

    $transactionActivities = [
      'user_register',
      'user_password',
      'campaign_signup',
      'campaign_reportback',
      'user_welcome-niche',
      'user_password-niche',
    ];
    if (!(in_array($this->message['activity'], $transactionActivities))) {
      echo '- canProcess(), activity not user transaction.', PHP_EOL;
      return FALSE;
    }

    return TRUE;
  }

  /**
   * Construct values for submission to email service.
   *
   * @param array $message
   *   The message to process based on what was collected from the queue being processed.
   */
  protected function setter($message) {

    $this->submission = [];
{'fraction_non_alphanumeric': 0.12608193883439123, 'fraction_numerical': 0.0, 'mean_word_length': 3.1391044776119403, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5938713', 'n_tokens_mistral': 2047, 'n_tokens_neox': 2006, 'n_words': 510}