You are here

public static function PoolExport::validateBaseUrl 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::validateBaseUrl()
  2. 2.0.x src/Controller/PoolExport.php \Drupal\cms_content_sync\Controller\PoolExport::validateBaseUrl()

Ensure that the sites base url does not contain localhost or an IP.

Parameters

object $pool: The pool object

Return value

bool Returns true or false

Throws

\Exception

3 calls to PoolExport::validateBaseUrl()
CliService::configuration_export in src/Cli/CliService.php
Export the configuration to the Sync Core.
FlowExport::export in src/Controller/FlowExport.php
Export flow.
PoolExport::export in src/Controller/PoolExport.php
Export pool.

File

src/Controller/PoolExport.php, line 89

Class

PoolExport
Push changes controller.

Namespace

Drupal\cms_content_sync\Controller

Code

public static function validateBaseUrl($pool) : bool {
  $messenger = \Drupal::messenger();
  $settings = ContentSyncSettings::getInstance();
  $baseUrl = $settings
    ->getSiteBaseUrl(true);
  if (false !== strpos($pool->backend_url, 'cms-content-sync.io')) {
    if (false !== strpos($baseUrl, 'localhost') || !UrlHelper::isValid($baseUrl, true) || '/' === mb_substr($baseUrl, -1) || preg_match('@https?://[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+(/|$)@', $baseUrl)) {
      $messenger
        ->addMessage(t('The site does not have a valid base url. The base url must not contain "localhost", does not contain a trailing slash and is not allowed to be an IP address. The base url of the site can be configured <a href="@url">here.</a>', [
        '@url' => Url::fromRoute('cms_content_sync.settings_form')
          ->toString(),
      ]), $messenger::TYPE_ERROR);
      return false;
    }
  }
  return true;
}