You are here

public function EntityShareClientCommands::pullAllChannels in Entity Share 8.3

Pull all channels from a remote website.

@command entity-share-client:pull-all @usage drush entity-share-client:pull-all site_1 default Pull all channels from a remote website. The "Include count in collection queries" option should be enabled on the server website. This option is provided by the JSON:API Extras module.

Parameters

string $remote_id: The remote entity ID.

string $import_config_id: The import config entity ID.

File

modules/entity_share_client/src/Commands/EntityShareClientCommands.php, line 123

Class

EntityShareClientCommands
Class EntityShareClientCommands.

Namespace

Drupal\entity_share_client\Commands

Code

public function pullAllChannels(string $remote_id, string $import_config_id) : void {
  try {

    /** @var \Drupal\entity_share_client\Entity\RemoteInterface $remote */
    $remote = $this->entityTypeManager
      ->getStorage('remote')
      ->load($remote_id);
  } catch (\Exception $exception) {
    $this
      ->io()
      ->error('Impossible to load the remote website with the ID: ' . $remote_id);
  }
  if ($remote === NULL) {
    return;
  }
  $channels = $this->remoteManager
    ->getChannelsInfos($remote);
  if (empty($channels)) {
    $this
      ->io()
      ->warning('Channel list is empty.');
    return;
  }
  $selfRecord = $this
    ->siteAliasManager()
    ->getSelf();
  $args = [];
  $options = [
    'remote-id' => $remote_id,
    'channel-id' => '',
    'import-config-id' => $import_config_id,
  ];
  foreach (array_keys($channels) as $channel_id) {
    $this
      ->io()
      ->write('Synchronizing ' . $channel_id, TRUE);
    $options['channel-id'] = $channel_id;
    $sub_process = Drush::drush($selfRecord, 'entity-share-client:pull', $args, $options);
    $sub_process
      ->run();
  }
}