From 93cbe1098a873a2df707c53b02aa29020d49d41e Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 15 Oct 2010 01:38:38 +0000 Subject: [PATCH] API CHANGE: Added RsyncMultiHostPublisher::set_excluded_folders(). (from r104673) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@112456 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- .../RsyncMultiHostPublisher.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/code/staticpublisher/RsyncMultiHostPublisher.php b/code/staticpublisher/RsyncMultiHostPublisher.php index b59a5895..55ac87ff 100644 --- a/code/staticpublisher/RsyncMultiHostPublisher.php +++ b/code/staticpublisher/RsyncMultiHostPublisher.php @@ -15,6 +15,8 @@ class RsyncMultiHostPublisher extends FilesystemPublisher { */ protected static $targets = array(); + protected static $excluded_folders = array(); + /** * Set the targets to publish to. * If target is an scp-style remote path, no password is accepted - we assume key-based authentication to be set up on the application server @@ -25,6 +27,14 @@ class RsyncMultiHostPublisher extends FilesystemPublisher { static function set_targets($targets) { self::$targets = $targets; } + + /** + * Specify folders to exclude from the rsync + * For example, you could exclude assets. + */ + static function set_excluded_folders($folders) { + self::$excluded_folders = $folders; + } function publishPages($urls) { parent::publishPages($urls); @@ -33,11 +43,16 @@ class RsyncMultiHostPublisher extends FilesystemPublisher { // Get variable that can turn off the rsync component of publication if(isset($_GET['norsync']) && $_GET['norsync']) return; + $extraArg = ""; + if(self::$excluded_folders) foreach(self::$excluded_folders as $folder) { + $extraArg .= " --exclude " . escapeshellarg($folder); + } + foreach(self::$targets as $target) { // Transfer non-PHP content from everything to the target; that will ensure that we have all the JS/CSS/etc - $rsyncOutput = `cd $base; rsync -av -e ssh --exclude /.htaccess --exclude '*.php' --exclude '*.svn' --exclude '*~' --delete . $target`; + $rsyncOutput = `cd $base; rsync -av -e ssh --exclude /.htaccess --exclude /web.config --exclude '*.php' --exclude '*.svn' --exclude '*.git' --exclude '*~' $extraArg --delete . $target`; // Then transfer "safe" PHP from the cache/ directory - $rsyncOutput .= `cd $base; rsync -av -e ssh --exclude '*.svn' --exclude '*~' --delete cache $target`; + $rsyncOutput .= `cd $base; rsync -av -e ssh --exclude '*.svn' --exclude '*~' $extraArg --delete cache $target`; if(StaticPublisher::echo_progress()) echo $rsyncOutput; } }