From 4e915ffe6a71ac539236b39f505645d405e4ac01 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Wed, 3 Jul 2013 11:10:48 -0500 Subject: [PATCH] Add a dry-run feature to unpack and deploy This will allow an administrator to visualize the files changed in the deployment before actually copying out the new files --- setup/cli/modules/class.module.php | 2 +- setup/cli/modules/deploy.php | 12 +++++++++++- setup/cli/modules/unpack.php | 10 ++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/setup/cli/modules/class.module.php b/setup/cli/modules/class.module.php index bfe32969b..142a00283 100644 --- a/setup/cli/modules/class.module.php +++ b/setup/cli/modules/class.module.php @@ -162,7 +162,7 @@ class Module { $this->parseOptions(); if (isset($this->_options[$name])) return $this->_options[$name]; - elseif ($this->options[$name]->default) + elseif (isset($this->options[$name]) && $this->options[$name]->default) return $this->options[$name]->default; else return $default; diff --git a/setup/cli/modules/deploy.php b/setup/cli/modules/deploy.php index 585f5314a..4d4868992 100644 --- a/setup/cli/modules/deploy.php +++ b/setup/cli/modules/deploy.php @@ -11,6 +11,15 @@ class Deployment extends Unpacker { script to deploy changes made by you or upstream development to your installation target"; + function __construct() { + $this->options['dry-run'] = array('-t','--dry-run', + 'action'=>'store_true', + 'help'=>'Don\'t actually deploy new code. Just show the files + that would be copied'); + # super(*args); + call_user_func_array(array('parent', '__construct'), func_get_args()); + } + function find_root_folder() { # Hop up to the root folder of this repo $start = dirname(__file__); @@ -50,7 +59,8 @@ class Deployment extends Unpacker { # Unpack the include folder $this->unpackage("$root/include/{,.}*", $include, -1, array("*/include/ost-config.php")); - if (!$upgrade && $include != "{$this->destination}/include") + if (!$options['dry-run'] && !$upgrade + && $include != "{$this->destination}/include") $this->change_include_dir($include); } } diff --git a/setup/cli/modules/unpack.php b/setup/cli/modules/unpack.php index 318ac1d7d..e338c283a 100644 --- a/setup/cli/modules/unpack.php +++ b/setup/cli/modules/unpack.php @@ -97,21 +97,23 @@ class Unpacker extends Module { * to disable exclusions */ function unpackage($folder, $destination, $recurse=0, $exclude=false) { - $verbose = $this->getOption('verbose'); + $dryrun = $this->getOption('dry-run', false); + $verbose = $this->getOption('verbose') || $dryrun; if (substr($destination, -1) !== '/') $destination .= '/'; foreach (glob($folder, GLOB_BRACE|GLOB_NOSORT) as $file) { if ($this->exclude($exclude, $file)) continue; if (is_file($file)) { - if (!is_dir($destination)) + if (!is_dir($destination) && !$dryrun) mkdir($destination, 0751, true); $target = $destination . basename($file); - if (is_file($target) && md5_file($target) == md5_file($file)) + if (is_file($target) && (md5_file($target) == md5_file($file))) continue; if ($verbose) $this->stdout->write($target."\n"); - copy($file, $target); + if (!$dryrun) + copy($file, $target); } } if ($recurse) { -- GitLab