You are here

public function ContentSyncSettings::isDirectSyncCoreAccessEnabled in CMS Content Sync 8

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

Whether or not users can directly communicate with the Sync Core. This only makes sense if the Sync Core is exposed publicly so right it's restricted to the Cloud version of Content Sync. The setting is saved in the Sync Core, not locally at this site. Otherwise the configuration of multiple sites would conflict and lead to undesired outcomes.

Parameters

bool $default: What to assume as the default value if no explicit settings are saved yet

Return value

bool

Throws

\EdgeBox\SyncCore\Exception\SyncCoreException

File

src/Controller/ContentSyncSettings.php, line 261

Class

ContentSyncSettings
Class ContentSyncSettings.

Namespace

Drupal\cms_content_sync\Controller

Code

public function isDirectSyncCoreAccessEnabled($default = true) {
  static $cache = null;
  if (null !== $cache) {
    return $cache;
  }
  $checked = [];

  // We don't distinguish between multiple Sync Cores. If it's enabled for one, it's enabled for all.
  foreach (Pool::getAll() as $pool) {
    $url = $pool
      ->getSyncCoreUrl();
    if (in_array($url, $checked)) {
      continue;
    }
    $checked[] = $url;
    try {
      $setting = $pool
        ->getClient()
        ->isDirectUserAccessEnabled();
      if ($setting) {
        return $cache = true;
      }
      if (false === $setting && null === $cache) {
        $cache = false;
      }
    } catch (NotFoundException $e) {

      // No config exported yet, so skip this.
      continue;
    }
  }

  // If it's not set at all, we default it to TRUE so people benefit from the increased performance.
  if (null === $cache) {
    return $cache = $default;
  }
  return $cache = false;
}