You are here

class SendUsageData in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/QueueWorker/SendUsageData.php \Drupal\social_lets_connect_usage\Plugin\QueueWorker\SendUsageData
  2. 8.5 modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/QueueWorker/SendUsageData.php \Drupal\social_lets_connect_usage\Plugin\QueueWorker\SendUsageData
  3. 8.6 modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/QueueWorker/SendUsageData.php \Drupal\social_lets_connect_usage\Plugin\QueueWorker\SendUsageData
  4. 8.7 modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/QueueWorker/SendUsageData.php \Drupal\social_lets_connect_usage\Plugin\QueueWorker\SendUsageData
  5. 8.8 modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/QueueWorker/SendUsageData.php \Drupal\social_lets_connect_usage\Plugin\QueueWorker\SendUsageData
  6. 10.3.x modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/QueueWorker/SendUsageData.php \Drupal\social_lets_connect_usage\Plugin\QueueWorker\SendUsageData
  7. 10.1.x modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/QueueWorker/SendUsageData.php \Drupal\social_lets_connect_usage\Plugin\QueueWorker\SendUsageData
  8. 10.2.x modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/QueueWorker/SendUsageData.php \Drupal\social_lets_connect_usage\Plugin\QueueWorker\SendUsageData

Send usage data.

@QueueWorker( id = "send_usage_data", title = @Translation("Send usage data."), cron = {"time" = 300} )

This QueueWorker is responsible for sending usage data.

Hierarchy

Expanded class hierarchy of SendUsageData

File

modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/QueueWorker/SendUsageData.php, line 25

Namespace

Drupal\social_lets_connect_usage\Plugin\QueueWorker
View source
class SendUsageData extends QueueWorkerBase implements ContainerFactoryPluginInterface {
  use StringTranslationTrait;

  /**
   * The config.
   *
   * @var \Drupal\Core\Config\ConfigFactory
   */
  public $config;

  /**
   * The http client.
   *
   * @var \GuzzleHttp\Client
   */
  public $client;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactory $config, Client $client) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->config = $config;
    $this->client = $client;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('config.factory'), $container
      ->get('http_client'));
  }

  /**
   * Will process a queue item.
   *
   *   $send_data['site_key'] = $site_key;
   *   $send_data['send_info'] = [
   *     'last_send' => $last_send,
   *     'times_send' => $times_send,
   *     'current_time' => $current_time,
   *   ];
   *   $send_data['usage_data'] = array $usage_data;
   */
  public function processItem($data) {
    $config = $this->config
      ->get('social_lets_connect_usage.settings');
    $usage_data_url = $config
      ->get('url');
    try {
      $response = $this->client
        ->post($usage_data_url, [
        'json' => $data,
      ]);
    } catch (RequestException $e) {
      return FALSE;
    }
    return Json::decode($response
      ->getBody()
      ->getContents());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SendUsageData::$client public property The http client.
SendUsageData::$config public property The config.
SendUsageData::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
SendUsageData::processItem public function Will process a queue item. Overrides QueueWorkerInterface::processItem
SendUsageData::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.