mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #304 from jamiemill/2.0-upgradefix2
Add exception migration to the upgrade shell.
This commit is contained in:
commit
e8e2bbc4d7
1 changed files with 45 additions and 1 deletions
|
@ -214,6 +214,9 @@ class UpgradeShell extends Shell {
|
|||
}
|
||||
|
||||
$patterns = array();
|
||||
App::build(array(
|
||||
'View/Helper' => App::core('View/Helper'),
|
||||
), App::APPEND);
|
||||
$helpers = App::objects('helper');
|
||||
$plugins = App::objects('plugin');
|
||||
$pluginHelpers = array();
|
||||
|
@ -513,6 +516,43 @@ class UpgradeShell extends Shell {
|
|||
$this->_filesRegexpUpdate($patterns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace cakeError with built-in exceptions.
|
||||
* NOTE: this ignores calls where you've passed your own secondary parameters to cakeError().
|
||||
* @return void
|
||||
*/
|
||||
public function exceptions() {
|
||||
$controllers = array_diff(App::path('controllers'), App::core('controllers'), array(APP));
|
||||
$components = array_diff(App::path('components'), App::core('components'));
|
||||
|
||||
$this->_paths = array_merge($controllers, $components);
|
||||
|
||||
if (!empty($this->params['plugin'])) {
|
||||
$pluginPath = App::pluginPath($this->params['plugin']);
|
||||
$this->_paths = array(
|
||||
$pluginPath . 'controllers' . DS,
|
||||
$pluginPath . 'controllers' . DS . 'components' .DS,
|
||||
);
|
||||
}
|
||||
$patterns = array(
|
||||
array(
|
||||
'$this->cakeError("error400") -> throw new BadRequestException()',
|
||||
'/(\$this->cakeError\(["\']error400["\']\));/',
|
||||
'throw new BadRequestException();'
|
||||
),
|
||||
array(
|
||||
'$this->cakeError("error404") -> throw new NotFoundException()',
|
||||
'/(\$this->cakeError\(["\']error404["\']\));/',
|
||||
'throw new NotFoundException();'
|
||||
),
|
||||
array(
|
||||
'$this->cakeError("error500") -> throw new InternalErrorException()',
|
||||
'/(\$this->cakeError\(["\']error500["\']\));/',
|
||||
'throw new InternalErrorException();'
|
||||
),
|
||||
);
|
||||
$this->_filesRegexpUpdate($patterns);
|
||||
}
|
||||
/**
|
||||
* Move application views files to where they now should be
|
||||
*
|
||||
|
@ -662,11 +702,11 @@ class UpgradeShell extends Shell {
|
|||
* @return void
|
||||
*/
|
||||
protected function _findFiles($extensions = '') {
|
||||
$this->_files = array();
|
||||
foreach ($this->_paths as $path) {
|
||||
if (!is_dir($path)) {
|
||||
continue;
|
||||
}
|
||||
$this->_files = array();
|
||||
$Iterator = new RegexIterator(
|
||||
new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)),
|
||||
'/^.+\.(' . $extensions . ')$/i',
|
||||
|
@ -773,6 +813,10 @@ class UpgradeShell extends Shell {
|
|||
->addSubcommand('components', array(
|
||||
'help' => __d('cake_console', 'Update components to extend Component class.'),
|
||||
'parser' => $subcommandParser
|
||||
))
|
||||
->addSubcommand('exceptions', array(
|
||||
'help' => __d('cake_console', 'Replace use of cakeError with exceptions.'),
|
||||
'parser' => $subcommandParser
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue