public function Job::getConflictingItems

Returns conflicting job item IDs along with the jobs causing the conflicts.

Conflicting job items are those that already have an identical item in another job that is not yet finished.

Return value

array List of conflicting job item IDs and existing jobs.

Overrides JobInterface::getConflictingItems

1 call to Job::getConflictingItems()
Job::getConflictingItemIds in src/Entity/Job.php
Returns conflicting job item IDs.

File

src/Entity/Job.php, line 1051

Class

Job
Entity class for the tmgmt_job entity.

Namespace

Drupal\tmgmt\Entity

Code

public function getConflictingItems() {
  $conflicting_items = [];
  foreach ($this
    ->getItems() as $item) {

    // Get existing job items that are have the same languages, same source,
    // are active or in review and are not the job item that we are checking.
    $existing_items = \Drupal::entityQuery('tmgmt_job_item')
      ->accessCheck(TRUE)
      ->condition('state', [
      JobItemInterface::STATE_ACTIVE,
      JobItemInterface::STATE_REVIEW,
    ], 'IN')
      ->condition('plugin', $item
      ->getPlugin())
      ->condition('item_type', $item
      ->getItemType())
      ->condition('item_id', $item
      ->getItemId())
      ->condition('tjiid', $item
      ->id(), '<>')
      ->condition('tjid.entity.source_language', $this
      ->getSourceLangcode())
      ->condition('tjid.entity.target_language', $this
      ->getTargetLangcode())
      ->execute();

    // If there are any, this is a conflicting job item, so get the existing
    // items that are causing the conflict.
    if ($existing_items) {
      $conflicting_items[$item
        ->id()] = $existing_items;
    }
  }
  return $conflicting_items;
}