Skip to content

Commit

Permalink
upgrade shell - helpers subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbloodydemon committed Dec 11, 2010
1 parent 92f92ac commit 65269bb
Showing 1 changed file with 61 additions and 15 deletions.
76 changes: 61 additions & 15 deletions cake/console/shells/upgrade.php
Expand Up @@ -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.
*
Expand All @@ -25,10 +60,25 @@ function i18n() {
VIEWS
);
}

$patterns = array(
array(
'<?php __*(*) to <?php echo __*(*)',
'/<\?php\s*(__[a-z]*\(.*?\))/',
'<?php echo \1'
),
array(
'<?php __*(*, true) to <?php echo __*()',
'/<\?php\s*(__[a-z]*\(.*?)(,\s*true)(\))/',
'<?php echo \1\3'
),
array('__*(*, true) to __*(*)', '/(__[a-z]*\(.*?)(,\s*true)(\))/', '\1\3')
);

$this->_findFiles();
foreach ($this->_files as $file) {
$this->out('Updating ' . $file . '...', 1, Shell::VERBOSE);
$this->_updateFile($file);
$this->_updateFile($file, $patterns);
}
}

Expand All @@ -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(
'<?php __*(*) to <?php echo __*(*)',
'/<\?php\s*(__[a-z]*\(.*?\))/',
'<?php echo \1'
),
array(
'<?php __*(*, true) to <?php echo __*()',
'/<\?php\s*(__[a-z]*\(.*?)(,\s*true)(\))/',
'<?php echo \1\3'
),
array('__*(*, true) to __*(*)', '/(__[a-z]*\(.*?)(,\s*true)(\))/', '\1\3')
);

foreach ($patterns as $pattern) {
$this->out(' * Updating ' . $pattern[0], 1, Shell::VERBOSE);
$contents = preg_replace($pattern[1], $pattern[2], $contents);
Expand All @@ -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.'))
)
)
));
}
}

0 comments on commit 65269bb

Please sign in to comment.