From 814142e3dd96f0167e7fa1323b021d0311d77fd2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 1 Jan 2011 22:13:45 -0500 Subject: [PATCH] Making the request method not update things in the models directory. They don't have a request object so those changes will always be wrong. Adding a dry-run mode and some additional output for it. Making both the helpers and request tasks hit all the bootstrapped paths. --- cake/console/shells/upgrade.php | 42 ++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/cake/console/shells/upgrade.php b/cake/console/shells/upgrade.php index bd278daa669..e7e291d3a9a 100644 --- a/cake/console/shells/upgrade.php +++ b/cake/console/shells/upgrade.php @@ -9,6 +9,17 @@ class UpgradeShell extends Shell { protected $_files = array(); protected $_paths = array(); +/** + * Shell startup, prints info message about dry run. + * + * @return void + */ + function startup() { + parent::startup(); + if ($this->params['dry-run']) { + $this->out('Dry-run mode enabled!', 1, Shell::QUIET); + } + } /** * Update helpers. * @@ -17,9 +28,8 @@ class UpgradeShell extends Shell { * @return void */ function helpers() { - $this->_paths = array( - VIEWS - ); + $this->_paths = array_diff(App::path('views'), App::core('views')); + if (!empty($this->params['plugin'])) { $this->_paths = array(App::pluginPath($this->params['plugin']) . 'views' . DS); } @@ -147,11 +157,20 @@ public function basics() { * @return void */ public function request() { - $this->_paths = array( - APP - ); + $core = App::core(); + $views = array_diff(App::path('views'), App::core('views')); + $controllers = array_diff(App::path('controllers'), App::core('controllers'), array(APP)); + $components = array_diff(App::path('components'), App::core('components')); + + $this->_paths = array_merge($views, $controllers, $components); + if (!empty($this->params['plugin'])) { - $this->_paths = array(App::pluginPath($this->params['plugin'])); + $pluginPath = App::pluginPath($this->params['plugin']); + $this->_paths = array( + $pluginPath . 'controllers' . DS, + $pluginPath . 'controllers' . DS . 'components' .DS, + $pluginPath . 'views' . DS, + ); } $patterns = array( array( @@ -263,7 +282,9 @@ protected function _updateFile($file, $patterns) { } $this->out('Done updating ' . $file, 1); - file_put_contents($file, $contents); + if (!$this->params['dry-run']) { + file_put_contents($file, $contents); + } } /** @@ -283,6 +304,11 @@ function getOptionParser() { 'help' => __('The extension(s) to search. A pipe delimited list, or a preg_match compatible subpattern'), 'default' => 'php|ctp|thtml|inc|tpl' ), + 'dry-run'=> array( + 'short' => 'd', + 'help' => __('Dry run the update, no files will actually be modified.'), + 'boolean' => true + ) ) );