You are here

public static function FlowPull::batch in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Controller/FlowPull.php \Drupal\cms_content_sync\Controller\FlowPull::batch()
  2. 2.0.x src/Controller/FlowPull.php \Drupal\cms_content_sync\Controller\FlowPull::batch()

Batch pull callback for the pull-all operation.

Parameters

\EdgeBox\SyncCore\Interfaces\Syndication\IPullAll $operation:

array $context:

Throws

\EdgeBox\SyncCore\Exception\SyncCoreException

File

src/Controller/FlowPull.php, line 297

Class

FlowPull
Pull controller.

Namespace

Drupal\cms_content_sync\Controller

Code

public static function batch($operation, &$context) {
  if (empty($context['sandbox']['operation'])) {
    $context['sandbox']['operation'] = $operation
      ->execute();
    if (!$operation
      ->total()) {
      $context['results'][] = [
        'type' => 'EMPTY',
      ];
      return;
    }
  }

  /**
   * @var \EdgeBox\SyncCore\Interfaces\Syndication\IPullAll $operation
   */
  $operation = $context['sandbox']['operation'];
  $total = $operation
    ->total();
  try {
    $progress = $operation
      ->progress();
    if ($progress < $total) {

      // Don't spam the Sync Core...
      sleep(5);
    }
    if ($progress == $total) {
      $context['results'][] = [
        'type' => 'success',
        'total' => $total,
      ];
    }
    $context['finished'] = $progress / $operation
      ->total();
    $context['message'] = 'Pulled ' . $progress . ' of ' . $operation
      ->total() . ' ' . $operation
      ->getTypeMachineName() . '.' . $operation
      ->getBundleMachineName() . ' from ' . $operation
      ->getPoolMachineName() . '...';
  } catch (TimeoutException $e) {
  }
}