You are here

public function CliService::pull_entities in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 8 src/Cli/CliService.php \Drupal\cms_content_sync\Cli\CliService::pull_entities()
  2. 2.1.x src/Cli/CliService.php \Drupal\cms_content_sync\Cli\CliService::pull_entities()

Kindly ask the Sync Core to pull all entities for a specific flow.

Parameters

ICLIIO $io: The CLI service which allows interoperability

string $flow_id: The flow the entities should be pulled from

array $options: An array containing the option parameters provided by Drush

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\EdgeBox\SyncCore\Exception\SyncCoreException

Deprecated

Function is deprecated and is going to be removed in 2.0, use pull() instead.

File

src/Cli/CliService.php, line 211

Class

CliService

Namespace

Drupal\cms_content_sync\Cli

Code

public function pull_entities($io, $flow_id, $options) {
  $io
    ->warning('Function is deprecated and is going to be removed in 2.0, use "cs-pull" instead.');
  $force = $options['force'];
  $flows = Flow::getAll();
  foreach ($flows as $id => $flow) {
    if ($flow_id && $id != $flow_id) {
      continue;
    }
    $result = FlowPull::pullAll($flow, $force);
    if (empty($result)) {
      $io
        ->text('No automated pull configured for Flow: ' . $flow
        ->label());
      continue;
    }
    $io
      ->text('Started pulling for Flow: ' . $flow
      ->label());
    foreach ($result as $operation) {
      $operation
        ->execute();
      if (!($goal = $operation
        ->total())) {
        $io
          ->text('> Nothing to do for: ' . $operation
          ->getTypeMachineName() . '.' . $operation
          ->getBundleMachineName() . ' from ' . $operation
          ->getSourceName());
        continue;
      }
      $progress = 0;
      while ($progress < $goal) {
        if ($progress > 0) {
          sleep(5);
        }
        try {
          $progress = $operation
            ->progress();
        } catch (TimeoutException $e) {
          $io
            ->text('> Timeout when asking the Sync Core to report on the progress of pulling ' . $goal . ' ' . $operation
            ->getTypeMachineName() . '.' . $operation
            ->getBundleMachineName() . ' from ' . $operation
            ->getSourceName() . '. Will try again in 15 seconds...');
          sleep(15);
          continue;
        }
        if ($progress == $goal) {
          $io
            ->text('> Finished ' . $goal . ' operations for ' . $operation
            ->getTypeMachineName() . '.' . $operation
            ->getBundleMachineName() . ' from ' . $operation
            ->getSourceName());
        }
        elseif (0 == $progress) {
          sleep(5);
        }
        else {
          $io
            ->text('> Finished ' . $progress . ' / ' . $goal . ' operations for  ' . $operation
            ->getTypeMachineName() . '.' . $operation
            ->getBundleMachineName() . ' from ' . $operation
            ->getSourceName() . ': ' . floor($progress / $goal * 100) . '%');
        }
      }
    }
  }
}