Codeception\Module\WPDb::replaceSiteDomainInSql PHP Method

replaceSiteDomainInSql() public method

Replaces the WordPress domains in a SQL dump string.
public replaceSiteDomainInSql ( string $sql ) : string
$sql string The input SQL dump string.
return string The modified SQL string.
    public function replaceSiteDomainInSql($sql)
    {
        $optionsTable = $this->config['tablePrefix'] . 'options';
        $matches = [];
        preg_match("/INSERT\\s+INTO\\s+`{$optionsTable}`.*'home'\\s*,\\s*'(.*)',/uiU", $sql, $matches);
        if (empty($matches) || empty($matches[1])) {
            codecept_debug('Tried to replace WordPress site domain but dump file does not contain an `options` table INSERT instruction.');
            return $sql;
        }
        $dumpSiteUrl = $matches[1];
        if (empty($dumpSiteUrl)) {
            codecept_debug('Tried to replace WordPress site domain but dump file does not contain dump of `home` option.');
            return $sql;
        }
        $thisSiteUrl = $this->config['url'];
        if ($dumpSiteUrl === $thisSiteUrl) {
            codecept_debug('Dump file domain not replaced as identical to the one specified in the configuration.');
            return $sql;
        }
        codecept_debug('Dump file domain [' . $dumpSiteUrl . '] replaced with [' . $thisSiteUrl . ']');
        return str_replace($dumpSiteUrl, $thisSiteUrl, $sql);
    }
WPDb