You are here

protected static function Migration::setFlowV2Ready in CMS Content Sync 2.1.x

Same name and namespace in other branches
  1. 2.0.x src/Controller/Migration.php \Drupal\cms_content_sync\Controller\Migration::setFlowV2Ready()
1 call to Migration::setFlowV2Ready()
Migration::runFlowExport in src/Controller/Migration.php

File

src/Controller/Migration.php, line 405

Class

Migration
Migration Embed provides methods and a UI to migrate from Content Sync v1 to Content Sync v2.

Namespace

Drupal\cms_content_sync\Controller

Code

protected static function setFlowV2Ready($flow) {
  $previous = self::getStoredFlowStatus($flow
    ->id()) ?? [];
  $all_types = $flow
    ->getController()
    ->getEntityTypeConfig(null, null, true);
  $types = [];
  foreach ($all_types as $type => $bundles) {
    foreach ($bundles as $bundle => $config) {
      $version = $config['version'];
      $existing = [];
      if (isset($previous['types'])) {
        foreach ($previous['types'] as $existing_type) {
          if ($existing_type['namespaceMachineName'] === $type && $existing_type['machineName'] === $bundle) {
            $existing = $existing_type;
            break;
          }
        }
      }
      $types[] = [
        'namespaceMachineName' => $type,
        'machineName' => $bundle,
        'versionId' => $version,
        'pushMode' => PushIntent::PUSH_AUTOMATICALLY === $config['export'] ? FlowSyndicationMode::ALL : (PushIntent::PUSH_MANUALLY === $config['export'] ? FlowSyndicationMode::MANUALLY : (PushIntent::PUSH_AS_DEPENDENCY === $config['export'] ? FlowSyndicationMode::DEPENDENT : null)),
        'pullMode' => PullIntent::PULL_AUTOMATICALLY === $config['import'] ? FlowSyndicationMode::ALL : (PullIntent::PULL_MANUALLY === $config['import'] ? FlowSyndicationMode::MANUALLY : (PullIntent::PULL_AS_DEPENDENCY === $config['import'] ? FlowSyndicationMode::DEPENDENT : null)),
        'pushedEntity' => isset($existing['pushedEntity']) ? $existing['pushedEntity'] : null,
        'pulledEntity' => isset($existing['pulledEntity']) ? $existing['pulledEntity'] : null,
        'skipTest' => !empty($existing['skipTest']) ? $existing['skipTest'] : false,
        'skipPush' => !empty($existing['skipPush']) ? $existing['skipPush'] : false,
        'skipPull' => !empty($existing['skipPull']) ? $existing['skipPull'] : false,
      ];
    }
  }
  self::setFlowStatus($flow->id, [
    'exported' => true,
    'active' => false,
    'skipTest' => !empty($previous['skipTest']) ? $previous['skipTest'] : false,
    'skipPush' => !empty($previous['skipPush']) ? $previous['skipPush'] : false,
    'skipPull' => !empty($previous['skipPull']) ? $previous['skipPull'] : false,
    'types' => $types,
  ]);
}