src/tad/WPBrowser/Module/Support/DbDump.php
public function replaceSiteDomainInMultisiteSqlString($sql, $debug = false)
    {
        $tables = [
            'blogs' => "VALUES\\s+\\(\\d+,\\s*\\d+,\\s*'(.*)',/uiU",
            'site'  => "VALUES\\s+\\(\\d+,\\s*'(.*)',/uiU",
        ];

        $thisSiteUrl = preg_replace('~https?:\\/\\/~', '', $this->url);

        foreach ($tables as $table => $pattern) {
            $currentTable = $this->tablePrefix . $table;
            $matches      = [];
            preg_match("/INSERT\\s+INTO\\s+`{$currentTable}`\\s+{$pattern}", $sql, $matches);

            if (empty($matches) || empty($matches[1])) {
                if ($debug) {
                    codecept_debug('Dump file does not contain a table INSERT instruction for table ['.
                     $table . '], not replacing.');
                }
                continue;
            }

            $dumpSiteUrl = $matches[1];
            if (empty($dumpSiteUrl)) {
                if ($debug) {
                    codecept_debug('Dump file does not contain dump of [domain] option, not replacing.');
                }
                continue;
            }

            if ($dumpSiteUrl === $thisSiteUrl) {
                if ($debug) {
                    codecept_debug('Dump file domain identical to the one specified in the configuration ['
                                   . $dumpSiteUrl . ']; not replacing');
                }
                continue;
            }

            if ($debug) {
                codecept_debug('Dump file domain [' . $dumpSiteUrl . '] replaced with [' . $thisSiteUrl . '].');
            }

            $sql = str_replace($dumpSiteUrl, $thisSiteUrl, $sql);
        }

        return $sql;
    }
public function replaceSiteDomainInMultisiteSqlString($sql, $debug = false)
    {
        $tables = [
            'blogs' => "VALUES\\s+\\(\\d+,\\s*\\d+,\\s*'(.*)',/uiU",
            'site'  => "VALUES\\s+\\(\\d+,\\s*'(.*)',/uiU",
        ];

        $thisSiteUrl = preg_replace('~https?:\\/\\/~', '', $this->url);

        foreach ($tables as $table => $pattern) {
            $currentTable = $this->tablePrefix . $table;
            $matches      = [];
            preg_match("/INSERT\\s+INTO\\s+`{$currentTable}`\\s+{$pattern}", $sql, $matches);

            if (empty($matches) || empty($matches[1])) {
                if ($debug) {
                    codecept_debug('Dump file does not contain a table INSERT instruction for table ['.
                     $table . '], not replacing.');
                }
                continue;
            }

            $dumpSiteUrl = $matches[1];
            if (empty($dumpSiteUrl)) {
                if ($debug) {
                    codecept_debug('Dump file does not contain dump of [domain] option, not replacing.');
                }
                continue;
            }

            if ($dumpSiteUrl === $thisSiteUrl) {
                if ($debug) {
                    codecept_debug('Dump file domain identical to the one specified in the configuration ['
                                   . $dumpSiteUrl . ']; not replacing');
                }
                continue;
            }

            if ($debug) {
                codecept_debug('Dump file domain [' . $dumpSiteUrl . '] replaced with [' . $thisSiteUrl . '].');
            }

            $sql = str_replace($dumpSiteUrl, $thisSiteUrl, $sql);
        }

        return $sql;
    }
public function replaceSiteDomainInMultisiteSqlString ( $ sql , $ debug = false ) { $ tables = [ 'blogs' => "VALUES\\s+\\(\\d+,\\s*\\d+,\\s*'(.*)',/uiU" , 'site' => "VALUES\\s+\\(\\d+,\\s*'(.*)',/uiU" , ] ; $ thisSiteUrl = preg_replace ( '~https?:\\/\\/~' , '' , $ this -> url ) ; foreach ( $ tables as $ table => $ pattern ) { $ currentTable = $ this -> tablePrefix . $ table ; $ matches = [ ] ; preg_match ( "/INSERT\\s+INTO\\s+`{$currentTable}`\\s+{$pattern}" , $ sql , $ matches ) ; if ( empty ( $ matches ) || empty ( $ matches [ 1 ] ) ) { if ( $ debug ) { codecept_debug ( 'Dump file does not contain a table INSERT instruction for table [' . $ table . '], not replacing.' ) ; } continue ; } $ dumpSiteUrl = $ matches [ 1 ] ; if ( empty ( $ dumpSiteUrl ) ) { if ( $ debug ) { codecept_debug ( 'Dump file does not contain dump of [domain] option, not replacing.' ) ; } continue ; } if ( $ dumpSiteUrl === $ thisSiteUrl ) { if ( $ debug ) { codecept_debug ( 'Dump file domain identical to the one specified in the configuration [' . $ dumpSiteUrl . ']; not replacing' ) ; } continue ; } if ( $ debug ) { codecept_debug ( 'Dump file domain [' . $ dumpSiteUrl . '] replaced with [' . $ thisSiteUrl . '].' ) ; } $ sql = str_replace ( $ dumpSiteUrl , $ thisSiteUrl , $ sql ) ; } return $ sql ; }
Replaces the site domain in the multisite tables of a SQL dump.

@param string $sql

@return string
Replaces the site domain in the multisite tables of a SQL dump .