You are here

public function AssetRefreshManager::updateQueue in Media: Acquia DAM 8

Updates the asset refresh queue.

Adds changed (modified or deleted) assets to the queue.

Parameters

array $asset_id_fields: Associative array of source media entity fields keyed by entity bundle names.

Return value

int Number of assets added to the queue.

Overrides AssetRefreshManagerInterface::updateQueue

File

src/Service/AssetRefreshManager.php, line 166

Class

AssetRefreshManager
Class AssetRefreshManager.

Namespace

Drupal\media_acquiadam\Service

Code

public function updateQueue(array $asset_id_fields) {
  if (empty($asset_id_fields)) {

    // Nothing to process. Associated media bundles are not found.
    $this
      ->saveStartTime($this
      ->getEndTime());
    return 0;
  }

  // Get ids of the changed (updated/deleted) assets.
  $asset_ids = $this
    ->getAssetIds();
  if (!$asset_ids) {

    // Nothing to process.
    return 0;
  }

  // Add media entity ids to the queue.
  $total = 0;
  $media_query = $this->mediaStorage
    ->getQuery();
  foreach ($asset_id_fields as $bundle => $field) {
    $media_query
      ->condition($media_query
      ->orConditionGroup()
      ->condition('bundle', $bundle)
      ->condition($field, $asset_ids, 'IN'));
  }
  $media_ids = $media_query
    ->execute();
  foreach ($media_ids as $media_id) {
    $this->queue
      ->createItem([
      'media_id' => $media_id,
    ]);
    $total++;
  }
  return $total;
}