You are here

public function SyncCoreFlowExport::prepareBatch in CMS Content Sync 8

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

Create all entity types, connections and synchronizations as required.

Parameters

bool $force:

Return value

\EdgeBox\SyncCore\Interfaces\IBatch

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\EdgeBox\SyncCore\Exception\SyncCoreException

Overrides SyncCoreExport::prepareBatch

File

src/SyncCoreFlowExport.php, line 49

Class

SyncCoreFlowExport
Class SyncCoreFlowExport used to export the Synchronization config to the Sync Core backend.

Namespace

Drupal\cms_content_sync

Code

public function prepareBatch($force = false) {
  $pool_configurations = [];
  $batch = $this->client
    ->batch();
  $flow_definition = $this->client
    ->getConfigurationService()
    ->defineFlow($this->flow->id, $this->flow
    ->label(), Yaml::encode(\Drupal::service('config.storage')
    ->read('cms_content_sync.flow.' . $this->flow
    ->id())))
    ->addToBatch($batch);
  $this
    ->addConfiguration($flow_definition, $pool_configurations, $batch, false, $force);

  // v1 of the Sync Core can't handle overlapping configuration independently,
  // so we need to add the configuration from Flows that overlap with the
  // Flow that is to be exported now.
  if (!$this->client
    ->canHandleFlowConfigurationIndependently()) {
    foreach (Flow::getAll() as $id => $flow) {
      if ($this->flow->id === $id) {
        continue;
      }
      $sub = new SyncCoreFlowExport($flow);
      $sub
        ->addConfiguration($flow_definition, $pool_configurations, $batch, true, $force);
    }
  }

  // Adding these must be done last so that the entity types are always
  // defined before being used. Otherwise the Sync Core will throw an exception.
  foreach ($pool_configurations as $pool_id => $operations) {

    /**
     * @var \EdgeBox\SyncCore\Interfaces\IBatchOperation $pool
     */
    $pool = $operations['pool_definition'];
    $pool
      ->addToBatch($batch);
  }
  return $batch;
}