You are here

public function ActivityLoggerFactory::checkIfMessageExist in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::checkIfMessageExist()
  2. 8.2 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::checkIfMessageExist()
  3. 8.3 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::checkIfMessageExist()
  4. 8.4 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::checkIfMessageExist()
  5. 8.5 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::checkIfMessageExist()
  6. 8.6 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::checkIfMessageExist()
  7. 8.7 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::checkIfMessageExist()
  8. 8.8 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::checkIfMessageExist()
  9. 10.3.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::checkIfMessageExist()
  10. 10.1.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::checkIfMessageExist()
  11. 10.2.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::checkIfMessageExist()

Checks if a message already exists.

Parameters

string $message_type: The message type.

string $context: The context of the message.

array $destination: The array of destinations to check for, include delta as well.

array $related_object: The related object, include target_type and target_id in array.

string $uid: The uid of the message.

Return value

int Returns true if the message exists.

1 call to ActivityLoggerFactory::checkIfMessageExist()
ActivityLoggerFactory::createMessages in modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php
Create message entities.

File

modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php, line 266

Class

ActivityLoggerFactory
Class ActivityLoggerFactory.

Namespace

Drupal\activity_logger\Service

Code

public function checkIfMessageExist($message_type, $context, array $destination, array $related_object, $uid) {
  $exists = FALSE;
  $query = $this->entityTypeManager
    ->getStorage('message')
    ->getQuery();
  $query
    ->condition('template', $message_type);
  $query
    ->condition('field_message_related_object.target_id', $related_object['target_id']);
  $query
    ->condition('field_message_related_object.target_type', $related_object['target_type']);
  $query
    ->condition('field_message_context', $context);
  $query
    ->condition('uid', $uid);
  if (is_array($destination)) {
    foreach ($destination as $delta => $dest_value) {
      $query
        ->condition('field_message_destination.' . $delta . '.value', $dest_value['value']);
    }
  }
  $query
    ->accessCheck(FALSE);

  // Fix duplicates for create_bundle_group && moved_content_between_groups
  // create_bundle_group is run on cron, it could be there is already a
  // message for moving content between groups. So we need to make sure we
  // check if either create_bundle_group or move_content is already there
  // before we add another message that content is created in a group.
  $types = [
    'moved_content_between_groups',
    'create_topic_group',
    'create_event_group',
  ];
  if (in_array($message_type, $types, TRUE)) {
    $query = $this->entityTypeManager
      ->getStorage('message')
      ->getQuery();
    $query
      ->condition('template', $types, 'IN');
    $query
      ->condition('field_message_related_object.target_id', $related_object['target_id']);
    $query
      ->condition('field_message_related_object.target_type', $related_object['target_type']);
    $query
      ->condition('field_message_context', $context);
    $query
      ->condition('uid', $uid);
    $query
      ->accessCheck(FALSE);
  }
  $ids = $query
    ->execute();
  $allowed_duplicates = [
    'moved_content_between_groups',
  ];
  $this->moduleHandler
    ->alter('activity_allowed_duplicates', $allowed_duplicates);
  if (!empty($ids) && !in_array($message_type, $allowed_duplicates)) {
    $exists = TRUE;
  }
  return $exists;
}