From 0b42761b135881623c1e4940cba04c51862fc9b7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 5 Dec 2010 00:48:38 -0500 Subject: [PATCH] Adding a ghetto start to what will be the 2.0 upgrade shell. i18n updating mostly works. --- cake/console/shells/upgrade.php | 90 +++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 cake/console/shells/upgrade.php diff --git a/cake/console/shells/upgrade.php b/cake/console/shells/upgrade.php new file mode 100644 index 000000000..81d780049 --- /dev/null +++ b/cake/console/shells/upgrade.php @@ -0,0 +1,90 @@ +params['plugin']) { + $this->_paths = array(App::pluginPath($this->params['plugin'])); + } + $this->_findFiles(); + foreach ($this->_files as $file) { + $this->out('Updating ' . $file . '...', 1, Shell::VERBOSE); + $this->_updateFile($file); + } + } + + protected function _findFiles() { + foreach ($this->_paths as $path) { + $Folder = new Folder($path); + $files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true); + if (!empty($pattern)) { + foreach ($files as $i => $file) { + if (preg_match($pattern, $file)) { + unset($files[$i]); + } + } + $files = array_values($files); + } + $this->_files = array_merge($this->_files, $files); + } + } + +/** + * Update a single file. + * + * @return void + */ + protected function _updateFile($file) { + $contents = file_get_contents($file); + $patterns = array( + array( + 'out(' * Updating ' . $pattern[0], 1, Shell::VERBOSE); + $contents = preg_replace($pattern[1], $pattern[2], $contents); + } + + $this->out('Done updating ' . $file, 1); + file_put_contents($file, $contents); + } + +/** + * get the option parser + * + * @return void + */ + function getOptionParser() { + return parent::getOptionParser() + ->addSubcommand('i18n', array( + 'help' => 'Update the i18n translation method calls.', + 'parser' => array( + 'options' => array( + 'plugin' => array('short' => 'p', 'help' => __('The plugin to update.')) + ) + ) + )); + } +} \ No newline at end of file