From 65269bba1907dd53519282d7ab7aaa8d50ebf058 Mon Sep 17 00:00:00 2001 From: evilbloodydemon Date: Sat, 11 Dec 2010 18:13:21 +0300 Subject: [PATCH] upgrade shell - helpers subcommand --- cake/console/shells/upgrade.php | 76 ++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/cake/console/shells/upgrade.php b/cake/console/shells/upgrade.php index 6e63549c5f4..64da7613478 100644 --- a/cake/console/shells/upgrade.php +++ b/cake/console/shells/upgrade.php @@ -8,6 +8,41 @@ class UpgradeShell extends Shell { protected $_files = array(); protected $_paths = array(); + + +/** + * Update helpers. + * + * - Converts helpers usage to new format. + * + * @return void + */ + function helpers() { + if (!empty($this->params['plugin'])) { + $this->_paths = array(App::pluginPath($this->params['plugin'])); + } else { + $this->_paths = array( + VIEWS + ); + } + + $patterns = array(); + foreach(App::objects('helper') as $helper) { + $oldHelper = strtolower(substr($helper, 0, 1)).substr($helper, 1); + $patterns[] = array( + "\${$oldHelper} to \$this->{$helper}", + "/\\\${$oldHelper}->/", + "\\\$this->{$helper}->" + ); + } + + $this->_findFiles(); + foreach ($this->_files as $file) { + $this->out('Updating ' . $file . '...', 1, Shell::VERBOSE); + $this->_updateFile($file, $patterns); + } + } + /** * Update i18n. * @@ -25,10 +60,25 @@ function i18n() { VIEWS ); } + + $patterns = array( + array( + '_findFiles(); foreach ($this->_files as $file) { $this->out('Updating ' . $file . '...', 1, Shell::VERBOSE); - $this->_updateFile($file); + $this->_updateFile($file, $patterns); } } @@ -53,21 +103,9 @@ protected function _findFiles($pattern = '') { * * @return void */ - protected function _updateFile($file) { + protected function _updateFile($file, $patterns) { $contents = file_get_contents($file); - $patterns = array( - array( - 'out(' * Updating ' . $pattern[0], 1, Shell::VERBOSE); $contents = preg_replace($pattern[1], $pattern[2], $contents); @@ -91,6 +129,14 @@ function getOptionParser() { 'plugin' => array('short' => 'p', 'help' => __('The plugin to update.')) ) ) + )) + ->addSubcommand('helpers', array( + 'help' => 'Update calls to helpers.', + 'parser' => array( + 'options' => array( + 'plugin' => array('short' => 'p', 'help' => __('The plugin to update.')) + ) + ) )); } } \ No newline at end of file