You are here

protected function AssetRefreshManager::getAssetIds in Media: Acquia DAM 8

Returns the most recent media asset ids.

Requests Notifications API and gets the most recent asset ids available.

Return value

array List of unique asset ids.

1 call to AssetRefreshManager::getAssetIds()
AssetRefreshManager::updateQueue in src/Service/AssetRefreshManager.php
Updates the asset refresh queue.

File

src/Service/AssetRefreshManager.php, line 208

Class

AssetRefreshManager
Class AssetRefreshManager.

Namespace

Drupal\media_acquiadam\Service

Code

protected function getAssetIds() : array {
  try {
    $page = $this
      ->getNextPage() ? $this
      ->getNextPage() : 1;

    // Calculate the offset value as a number of previously processed items.
    $offset = $this
      ->getRequestLimit() * ($page - 1);
    $response = $this->acquiadam
      ->getNotifications([
      'limit' => $this
        ->getRequestLimit(),
      'offset' => $offset,
      'starttime' => $this
        ->getStartTime(),
      'endtime' => $this
        ->getEndTime(),
    ]);
  } catch (GuzzleException|InvalidCredentialsException $e) {
    $this->logger
      ->error('Failed to fetch asset ids: @message.', [
      '@message' => $e
        ->getMessage(),
    ]);
    return [];
  }
  if (empty($response['notifications'])) {
    $continue_fetch = FALSE;
    $asset_ids = [];
  }
  else {
    $continue_fetch = $response['total'] > $this
      ->getRequestLimit() * $page;
    $asset_ids = $this
      ->extractAssetIds($response['notifications']);
  }
  if ($continue_fetch) {
    $this
      ->saveNextPage(++$page);
    $this
      ->saveEndTime($this
      ->getEndTime());
    return $asset_ids;
  }
  $this
    ->saveStartTime($this
    ->getEndTime());
  $this
    ->resetEndTime();
  $this
    ->resetNextPage();
  return $asset_ids;
}