Created
April 5, 2014 12:46
-
-
Save uuf6429/9991507 to your computer and use it in GitHub Desktop.
Synchronizes a set of wordpress plugins with several wordpress installations (great for testing a plugin across different wordpress versions).
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
<?php | |
try { | |
$srcPluginPattern = 'C:\Users\Christian\Documents\GitHub\WP-*'; | |
$dstWpSitePattern = 'C:/wamp/www/wordpress-*/wp-content/plugins/'; | |
if(!isset($argv))throw new Exception('Program must be run through CLI'); | |
function deleteDir($path) { | |
if(file_exists($path)){ | |
if(is_file($path)){ | |
if(!unlink($path)) | |
throw new Exception("$path could not be deleted."); | |
}elseif(is_dir($path)){ | |
$path = rtrim($path, '/\\'); | |
foreach(scandir($path) as $sub) | |
if($sub != '.' && $sub != '..') | |
deleteDir("$path/$sub"); | |
if(!rmdir($path)) | |
throw new Exception("$path could not be deleted."); | |
}else{ | |
throw new InvalidArgumentException("$path is not a file or directory."); | |
} | |
} | |
} | |
function copyDir($source, $dest, $permissions = 0755) { | |
if (basename($source) == '.git') return; | |
if (is_link($source)) { | |
return symlink(readlink($source), $dest); | |
} | |
if (is_file($source)) { | |
return copy($source, $dest); | |
} | |
if (!is_dir($dest)) { | |
mkdir($dest, $permissions); | |
} | |
$dir = dir($source); | |
while (false !== $entry = $dir->read()) { | |
if ($entry == '.' || $entry == '..') { | |
continue; | |
} | |
copyDir("$source/$entry", "$dest/$entry"); | |
} | |
$dir->close(); | |
return true; | |
} | |
foreach(glob($srcPluginPattern) as $src){ | |
foreach(glob($dstWpSitePattern) as $dst){ | |
$dst = $dst . basename($src); | |
echo 'Copying ' . basename($src) . ' -> ' . basename(dirname(str_replace('/wp-content/plugins/', '/', $dst))) . ': '; | |
deleteDir($dst); | |
copyDir($src, $dst); | |
echo 'OK' . PHP_EOL; | |
} | |
} | |
}catch(Exception $ex){ | |
echo get_class($ex). ' [' . $ex->getCode() . ']: ' . $ex->getMessage() . PHP_EOL; | |
echo $ex->getFile(). ':' . $ex->getLine() . PHP_EOL; | |
echo $ex->getTraceAsString() . PHP_EOL; | |
die(1); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment