Fixing plugin helper updates.

Adding docblocks
Using native iterators instead of Folder class.
Adding more to the help.
This commit is contained in:
mark_story 2010-12-11 23:13:21 -05:00
parent fe81b84bcb
commit 2d1dea1692

View file

@ -9,7 +9,6 @@ class UpgradeShell extends Shell {
protected $_files = array(); protected $_files = array();
protected $_paths = array(); protected $_paths = array();
/** /**
* Update helpers. * Update helpers.
* *
@ -21,6 +20,9 @@ class UpgradeShell extends Shell {
$this->_paths = array( $this->_paths = array(
VIEWS VIEWS
); );
if (!empty($this->params['plugin'])) {
$this->_paths = array(App::pluginPath($this->params['plugin']) . 'views' . DS);
}
$patterns = array(); $patterns = array();
foreach (App::objects('helper') as $helper) { foreach (App::objects('helper') as $helper) {
@ -39,15 +41,17 @@ class UpgradeShell extends Shell {
* Update i18n. * Update i18n.
* *
* - Removes extra true param. * - Removes extra true param.
* - Add the echo to __*() calls that didn't need them before.
* *
* @return void * @return void
*/ */
function i18n() { function i18n() {
$this->_paths = array( $this->_paths = array(
CONTROLLERS, APP
MODELS,
VIEWS
); );
if (!empty($this->params['plugin'])) {
$this->_paths = array(App::pluginPath($this->params['plugin']));
}
$patterns = array( $patterns = array(
array( array(
@ -66,35 +70,39 @@ class UpgradeShell extends Shell {
$this->_filesRegexpUpdate($patterns); $this->_filesRegexpUpdate($patterns);
} }
/**
* Updates files based on regular expressions.
*
* @param array $patterns Array of search and replacement patterns.
* @return void
*/
protected function _filesRegexpUpdate($patterns) { protected function _filesRegexpUpdate($patterns) {
if (!empty($this->params['plugin'])) { $this->_findFiles($this->params['ext']);
$this->_paths = array(App::pluginPath($this->params['plugin']));
}
$extensions = 'php|ctp|thtml|inc|tpl';
if (!empty($this->params['ext'])) {
$extensions = $this->params['ext'];
}
$this->_findFiles($extensions);
foreach ($this->_files as $file) { foreach ($this->_files as $file) {
$this->out('Updating ' . $file . '...', 1, Shell::VERBOSE); $this->out('Updating ' . $file . '...', 1, Shell::VERBOSE);
$this->_updateFile($file, $patterns); $this->_updateFile($file, $patterns);
} }
} }
protected function _findFiles($extensions = '', $pattern = '') { /**
* Searches the paths and finds files based on extension.
*
* @param string $extensions
* @return void
*/
protected function _findFiles($extensions = '') {
foreach ($this->_paths as $path) { foreach ($this->_paths as $path) {
$Folder = new Folder($path); $files = array();
$files = $Folder->findRecursive(".*\.($extensions)", true); $Iterator = new RegexIterator(
if (!empty($pattern)) { new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)),
foreach ($files as $i => $file) { '/^.+\.(' . $extensions . ')$/i',
if (preg_match($pattern, $file)) { RegexIterator::MATCH
unset($files[$i]); );
foreach ($Iterator as $file) {
if ($file->isFile()) {
$files[] = $file->getPathname();
} }
} }
$files = array_values($files);
}
$this->_files = array_merge($this->_files, $files); $this->_files = array_merge($this->_files, $files);
} }
} }
@ -102,6 +110,8 @@ class UpgradeShell extends Shell {
/** /**
* Update a single file. * Update a single file.
* *
* @param string $file The file to update
* @param array $patterns The replacement patterns to run.
* @return void * @return void
*/ */
protected function _updateFile($file, $patterns) { protected function _updateFile($file, $patterns) {
@ -119,13 +129,20 @@ class UpgradeShell extends Shell {
/** /**
* get the option parser * get the option parser
* *
* @return void * @return ConsoleOptionParser
*/ */
function getOptionParser() { function getOptionParser() {
$subcommandParser = array( $subcommandParser = array(
'options' => array( 'options' => array(
'plugin' => array('short' => 'p', 'help' => __('The plugin to update.')), 'plugin' => array(
'ext' => array('short' => 'e', 'help' => __('The extension(s) to search.')), 'short' => 'p',
'help' => __('The plugin to update. Only the specified plugin will be updated.'
)),
'ext' => array(
'short' => 'e',
'help' => __('The extension(s) to search. A pipe delimited list, or a preg_match compatible subpattern'),
'default' => 'php|ctp|thtml|inc|tpl'
),
) )
); );