You are here

public static function FlowPull::batch in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 8 src/Controller/FlowPull.php \Drupal\cms_content_sync\Controller\FlowPull::batch()
  2. 2.1.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 310

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'];
  try {
    $progress = $operation
      ->progress();
    $total = $operation
      ->total();
    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
      ->getSourceName() . '...';
  } catch (TimeoutException $e) {
  }
}