As a followup to my previous post on how to enable subfolders in WordPress Hive domains I created the script that will go through and update the symlinks in the appropriate folder to keep your installation up to date. You’d run this after performing an update to WordPress to keep it running smoothly. I think this should keep working in the future but I can’t see the future (if only) so this is provided as is and I’m not responsible if you screw something up!
It’s a simple php script you’ll run from your command line with the parameters of the source folder and the destination folder. With the source being the wordpress installation of the hive and the destination is the domain that is run off of the hive but has its own subfolders. It should tell you about any symlinks it creates and warn you about any potential custom files you have which you should manually compare to the upgrade if needed to see if you need to edit them.
Another thing to keep in mind I’ve found you need to put the full path to the source directory that you want to copy or it will make relative symlinks that don’t seem to work.
<?php
// Updating the symlinks in the destination folder for the updated files in the source folder
// Get list of files for each folder
$srcDirName = $argv[1];
$destDirName = $argv[2];
if ($srcDirName == "" || $destDirName == "") {
echo "Usage: php update_symlinks_src_dest.php [source directory] [destination directory]";
echo " Please leave ending slashes off of directories / ";
}
echo "Updating symlink from source: " . $srcDirName . " \n";
echo "To destination: " . $destDirName . " \n";
$srcDir = opendir($srcDirName);
$destDir = opendir($destDirName);
$array_dest_files = array();
while ($dest_filename = readdir($destDir)) {
array_push($array_dest_files, $dest_filename);
}
while ($src_filename = readdir($srcDir)) {
// check for file in dest
if (in_array($src_filename, $array_dest_files) ){
// Test each file in both hash against the other
// echo "comparing: src- " . $srcDirName . "/" . $src_filename . " and dest- " . $destDirName . "/" . $src_filename . " \n";
$srcmd5 = md5_file( $srcDirName . "/" . $src_filename );
$destmd5 = md5_file( $destDirName . "/" . $src_filename );
// if pass then this is a symlink or copy and is ok
if ($srcmd5 != $destmd5) {
// if fail then probably this is a custom file so leave it alone but warn about it
echo "Warning potential custom file not handled: " . $destDirName . "/" . $src_filename . "\n";
}
}
else {
// if file in src and not dest create a symlink for it
echo "Creating symlink for file: " . $srcDirName . "/" . $src_filename . " \n";
symlink( $srcDirName . "/" . $src_filename , $destDirName . "/" . $src_filename );
}
}
// if file in dest and not src leave it alone
closedir($srcDir);
closedir($destDir);
?>
{ 1 comment }



