You are here

public function PoolExport::export in CMS Content Sync 8

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

Export pool.

Parameters

string $cms_content_sync_pool: The id of the pool

Return value

null|\Symfony\Component\HttpFoundation\RedirectResponse

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\EdgeBox\SyncCore\Exception\SyncCoreException

\Exception

1 string reference to 'PoolExport::export'
cms_content_sync.routing.yml in ./cms_content_sync.routing.yml
cms_content_sync.routing.yml

File

src/Controller/PoolExport.php, line 31

Class

PoolExport
Push changes controller.

Namespace

Drupal\cms_content_sync\Controller

Code

public function export(string $cms_content_sync_pool, Request $request) : RedirectResponse {

  /**
   * @var \Drupal\cms_content_sync\Entity\Pool $pool
   */
  $pool = \Drupal::entityTypeManager()
    ->getStorage('cms_content_sync_pool')
    ->load($cms_content_sync_pool);
  $messenger = \Drupal::messenger();
  if (!PoolExport::validateBaseUrl($pool)) {
    return new RedirectResponse(Url::fromRoute('entity.cms_content_sync_pool.collection')
      ->toString());
  }
  $exporter = new SyncCorePoolExport($pool);
  $sites = $exporter
    ->verifySiteId();
  if ('false' === $request->query
    ->get('force', 'false') && $sites && count($sites)) {
    $url = Url::fromRoute('entity.cms_content_sync_pool.export', [
      'cms_content_sync_pool' => $pool
        ->id(),
    ], [
      'query' => [
        'force' => 'true',
      ],
    ])
      ->toString();
    $messenger
      ->addMessage($this
      ->t('This site id is not unique, site with id %id is already registered with base url %base_url. If you changed the site URL and want to force the export, <a href="@url">click here</a>.', [
      '@url' => Markup::create($url),
      '%id' => array_keys($sites)[0],
      '%base_url' => array_values($sites)[0],
    ]), $messenger::TYPE_ERROR);
    return new RedirectResponse(Url::fromRoute('entity.cms_content_sync_pool.collection')
      ->toString());
  }
  $batch = $exporter
    ->prepareBatch(false, !empty($_GET['force']) && 'true' === $_GET['force']);
  $operations = [];
  for ($i = 0; $i < $batch
    ->count(); ++$i) {
    $operations[] = [
      [
        $batch
          ->get($i),
        'execute',
      ],
      [],
    ];
  }
  $batch = [
    'title' => t('Export configuration'),
    'operations' => $operations,
    'finished' => '\\Drupal\\cms_content_sync\\Controller\\PoolExport::batchFinished',
  ];
  batch_set($batch);
  return batch_process(Url::fromRoute('entity.cms_content_sync_pool.collection'));
}