Permalink
Browse files

Added an 'exceptions' method to the UpgradeShell.

This just replaces some of the basic cakeError() calls with
equivalent exceptions.
  • Loading branch information...
jamiemill committed Nov 6, 2011
1 parent 1d52dc0 commit 4368b62dfb8c4347ae412433a5dffc0d1e0336ae
Showing with 41 additions and 0 deletions.
  1. +41 −0 lib/Cake/Console/Command/UpgradeShell.php
@@ -516,6 +516,43 @@ public function components() {
$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\(["\']error404["\']\));/',
+ 'throw new InternalErrorException();'
+ ),
+ );
+ $this->_filesRegexpUpdate($patterns);
+ }
/**
* Move application views files to where they now should be
*
@@ -776,6 +813,10 @@ public function getOptionParser() {
->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
));
}
}

0 comments on commit 4368b62

Please sign in to comment.