Last active
December 16, 2015 08:19
-
-
Save mircobabini/5405073 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/** | |
* @param string $olddomain | |
* @param string $newdomain | |
* @param string $infile | |
* @param string $outfile | |
* @return int|bool | |
*/ | |
function wp_sql_domain_changer ($olddomain, $newdomain, $infile = null, $outfile = null) { | |
$infile = ($infile === null) ? 'input.sql' : $infile; | |
$outfile = ($outfile === null) ? 'output.sql' : $outfile; | |
$c = file_get_contents ($infile); | |
$c = str_replace ($olddomain, $newdomain, $c); | |
return file_put_contents ($outfile, $c); | |
} | |
/** | |
* @return array | |
*/ | |
function get_argv () | |
{ | |
$argvs = array (); | |
$params = $_SERVER['argv']; | |
if (sizeof ($params) > 1) { | |
array_shift ($params); | |
foreach ($params as $param) { | |
@list ($key, $value) = @explode ("=", $param); | |
if ($value === null) | |
$argvs[ ] = $key; | |
else | |
$argvs[ $key ] = $value; | |
} | |
} | |
return $argvs; | |
} | |
$argvs = get_argv (); | |
if (sizeof ($argvs) < 2) { | |
die ("Usage: php ".basename(__FILE__)." old.domain.it new.domain.it [input.sql] [output.sql]" . PHP_EOL . PHP_EOL); | |
} | |
wp_sql_domain_changer ($argvs[0], $argvs[1], @$argvs[2], @$argvs[3]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment