mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding a ghetto start to what will be the 2.0 upgrade shell. i18n updating mostly works.
This commit is contained in:
parent
093d7f1064
commit
0b42761b13
1 changed files with 90 additions and 0 deletions
90
cake/console/shells/upgrade.php
Normal file
90
cake/console/shells/upgrade.php
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* A shell class to help developers upgrade applications to CakePHP 2.0
|
||||||
|
*
|
||||||
|
* @package cake.console/shells
|
||||||
|
*/
|
||||||
|
class UpgradeShell extends Shell {
|
||||||
|
|
||||||
|
protected $_files = array();
|
||||||
|
protected $_paths = array();
|
||||||
|
/**
|
||||||
|
* Update i18n.
|
||||||
|
*
|
||||||
|
* - Removes extra true param.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function i18n() {
|
||||||
|
if ($this->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(
|
||||||
|
'<?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);
|
||||||
|
}
|
||||||
|
|
||||||
|
$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.'))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue