Skip to content

Commit

Permalink
Making the request method not update things in the models directory. …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
markstory committed Jan 2, 2011
1 parent 78a376e commit 814142e
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions cake/console/shells/upgrade.php
Expand Up @@ -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('<warning>Dry-run mode enabled!</warning>', 1, Shell::QUIET);
}
}
/**
* Update helpers.
*
Expand All @@ -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);
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
}

/**
Expand All @@ -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
)
)
);

Expand Down

0 comments on commit 814142e

Please sign in to comment.