public function CliService::pull in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/Cli/CliService.php \Drupal\cms_content_sync\Cli\CliService::pull()
- 2.0.x src/Cli/CliService.php \Drupal\cms_content_sync\Cli\CliService::pull()
Kindly ask the Sync Core to pull all entities for a specific flow, or to force pull one specific entity.
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
File
- src/
Cli/ CliService.php, line 105
Class
Namespace
Drupal\cms_content_sync\CliCode
public function pull($io, $flow_id, $options) {
$force = $options['force'];
$entity_type = $options['entity_type'];
$entity_uuid = $options['entity_uuid'];
if ('' != $entity_uuid && null == $entity_type) {
$io
->error('If a specific entity_uuid should be pulled, the entity_type also has to be set.');
return;
}
// @todo Allow pulling of all entities of a specific type for one specific flow.
if ('' != $entity_type && null == $entity_uuid) {
$io
->error('If the entity_type option is set, the entity_uuid to be pulled also has to be specified.');
return;
}
if (!is_null($entity_uuid) && !is_null($entity_uuid)) {
if (UUID::isValid($entity_uuid)) {
// Pull a single entity.
// @todo Allow pull for single entities which have not been pulled before.
FlowPull::force_pull_entity($flow_id, $entity_type, $entity_uuid);
}
else {
$io
->error('The specified entity_uuid is invalid.');
}
}
else {
// Pull all entities for the specified flow.
$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
->getPoolMachineName());
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
->getPoolMachineName() . '. Will try again in 15 seconds...');
sleep(15);
continue;
}
if ($progress == $goal) {
$io
->text('> Pulled ' . $goal . ' ' . $operation
->getTypeMachineName() . '.' . $operation
->getBundleMachineName() . ' from ' . $operation
->getPoolMachineName());
}
elseif (0 == $progress) {
sleep(5);
}
else {
$io
->text('> Pulled ' . $progress . ' of ' . $goal . ' ' . $operation
->getTypeMachineName() . '.' . $operation
->getBundleMachineName() . ' from ' . $operation
->getPoolMachineName() . ': ' . floor($progress / $goal * 100) . '%');
}
}
}
}
}
}