Browse files

Merge branch '1.3' into 1.3-jshelper

  • Loading branch information...
2 parents 6d1c38c + d15a961 commit 83a705f7393a67b1c7fd9ad52f968e749fd1cedc @markstory markstory committed Aug 3, 2009
Showing with 2,574 additions and 925 deletions.
  1. +1 −0 .gitignore
  2. +3 −3 app/config/bootstrap.php
  3. +5 −0 app/config/core.php
  4. +8 −1 app/webroot/test.php
  5. +1 −0 cake/basics.php
  6. +5 −0 cake/bootstrap.php
  7. +135 −118 cake/console/cake.php
  8. +131 −94 cake/console/libs/acl.php
  9. +1 −1 cake/console/libs/api.php
  10. +7 −1 cake/console/libs/bake.php
  11. +2 −2 cake/console/libs/schema.php
  12. +49 −40 cake/console/libs/shell.php
  13. +28 −21 cake/console/libs/tasks/controller.php
  14. +3 −3 cake/console/libs/tasks/fixture.php
  15. +3 −4 cake/console/libs/tasks/model.php
  16. +6 −6 cake/console/libs/tasks/plugin.php
  17. +8 −8 cake/console/libs/tasks/project.php
  18. +26 −5 cake/console/libs/tasks/template.php
  19. +1 −1 cake/console/libs/tasks/test.php
  20. +46 −61 cake/console/libs/tasks/view.php
  21. +11 −5 cake/console/libs/testsuite.php
  22. 0 cake/console/{libs → }/templates/default/actions/controller_actions.ctp
  23. +1 −0 cake/console/{libs → }/templates/default/classes/controller.ctp
  24. 0 cake/console/{libs → }/templates/default/classes/fixture.ctp
  25. 0 cake/console/{libs → }/templates/default/classes/model.ctp
  26. 0 cake/console/{libs → }/templates/default/classes/test.ctp
  27. +3 −3 cake/console/{libs → }/templates/default/views/form.ctp
  28. +4 −2 cake/console/{libs → }/templates/default/views/home.ctp
  29. +2 −2 cake/console/{libs → }/templates/default/views/index.ctp
  30. +9 −9 cake/console/{libs → }/templates/default/views/view.ctp
  31. 0 cake/console/{libs → }/templates/skel/.htaccess
  32. 0 cake/console/{libs → }/templates/skel/app_controller.php
  33. +1 −1 cake/console/{libs → }/templates/skel/app_helper.php
  34. 0 cake/console/{libs → }/templates/skel/app_model.php
  35. 0 cake/console/{libs → }/templates/skel/config/acl.ini.php
  36. 0 cake/console/{libs → }/templates/skel/config/bootstrap.php
  37. +5 −0 cake/console/{libs → }/templates/skel/config/core.php
  38. 0 cake/console/{libs → }/templates/skel/config/database.php.default
  39. 0 cake/console/{libs → }/templates/skel/config/inflections.php
  40. 0 cake/console/{libs → }/templates/skel/config/routes.php
  41. 0 cake/console/{libs → }/templates/skel/config/sql/db_acl.php
  42. 0 cake/console/{libs → }/templates/skel/config/sql/db_acl.sql
  43. 0 cake/console/{libs → }/templates/skel/config/sql/i18n.php
  44. 0 cake/console/{libs → }/templates/skel/config/sql/i18n.sql
  45. 0 cake/console/{libs → }/templates/skel/config/sql/sessions.php
  46. 0 cake/console/{libs → }/templates/skel/config/sql/sessions.sql
  47. 0 cake/console/{libs/templates/skel/views/scaffolds → templates/skel/controllers/components}/empty
  48. 0 cake/console/{libs → }/templates/skel/controllers/pages_controller.php
  49. 0 cake/console/{libs → }/templates/skel/index.php
  50. 0 cake/console/{libs/templates/skel/views/pages → templates/skel/locale/eng/LC_MESSAGES}/empty
  51. 0 cake/console/{libs/templates/skel/views/helpers → templates/skel/models/behaviors}/empty
  52. 0 cake/console/{libs/templates/skel/views/errors → templates/skel/models/datasources}/empty
  53. 0 cake/console/{libs/templates/skel/views/elements → templates/skel/plugins}/empty
  54. 0 ...nsole/{libs/templates/skel/vendors/shells/templates → templates/skel/tests/cases/behaviors}/empty
  55. 0 .../console/{libs/templates/skel/vendors/shells/tasks → templates/skel/tests/cases/components}/empty
  56. 0 cake/console/{libs/templates/skel/tmp/tests → templates/skel/tests/cases/controllers}/empty
  57. 0 cake/console/{libs/templates/skel/tmp/sessions → templates/skel/tests/cases/datasources}/empty
  58. 0 cake/console/{libs/templates/skel/tmp/logs → templates/skel/tests/cases/helpers}/empty
  59. 0 cake/console/{libs/templates/skel/tmp/cache/views → templates/skel/tests/cases/models}/empty
  60. 0 cake/console/{libs/templates/skel/tmp/cache/persistent → templates/skel/tests/cases/shells}/empty
  61. 0 cake/console/{libs/templates/skel/tmp/cache/models → templates/skel/tests/fixtures}/empty
  62. 0 cake/console/{libs → }/templates/skel/tests/groups/empty
  63. 0 cake/console/{libs/templates/skel/tests/fixtures → templates/skel/tmp/cache/models}/empty
  64. 0 cake/console/{libs/templates/skel/tests/cases/models → templates/skel/tmp/cache/persistent}/empty
  65. 0 cake/console/{libs/templates/skel/tests/cases/helpers → templates/skel/tmp/cache/views}/empty
  66. 0 cake/console/{libs/templates/skel/tests/cases/controllers → templates/skel/tmp/logs}/empty
  67. 0 cake/console/{libs/templates/skel/tests/cases/components → templates/skel/tmp/sessions}/empty
  68. 0 cake/console/{libs/templates/skel/tests/cases/behaviors → templates/skel/tmp/tests}/empty
  69. 0 cake/console/{libs/templates/skel/plugins → templates/skel/vendors/css}/empty
  70. 0 cake/console/{libs/templates/skel/models/datasources → templates/skel/vendors/img}/empty
  71. 0 cake/console/{libs/templates/skel/models/behaviors → templates/skel/vendors/js}/empty
  72. 0 .../console/{libs/templates/skel/locale/eng/LC_MESSAGES → templates/skel/vendors/shells/tasks}/empty
  73. 0 cake/console/{libs → }/templates/skel/views/elements/email/html/default.ctp
  74. 0 cake/console/{libs → }/templates/skel/views/elements/email/text/default.ctp
  75. 0 cake/console/{libs/templates/skel/controllers/components → templates/skel/views/elements}/empty
  76. 0 cake/console/templates/skel/views/errors/empty
  77. 0 cake/console/templates/skel/views/helpers/empty
  78. 0 cake/console/{libs → }/templates/skel/views/layouts/ajax.ctp
  79. 0 cake/console/{libs → }/templates/skel/views/layouts/default.ctp
  80. 0 cake/console/{libs → }/templates/skel/views/layouts/email/html/default.ctp
  81. 0 cake/console/{libs → }/templates/skel/views/layouts/email/text/default.ctp
  82. +0 −1 cake/console/{libs → }/templates/skel/views/layouts/flash.ctp
  83. 0 cake/console/{libs → }/templates/skel/views/layouts/js/default.ctp
  84. 0 cake/console/{libs → }/templates/skel/views/layouts/rss/default.ctp
  85. 0 cake/console/{libs → }/templates/skel/views/layouts/xml/default.ctp
  86. 0 cake/console/templates/skel/views/pages/empty
  87. 0 cake/console/templates/skel/views/scaffolds/empty
  88. 0 cake/console/{libs → }/templates/skel/webroot/.htaccess
  89. +1 −1 cake/console/{libs → }/templates/skel/webroot/css.php
  90. 0 cake/console/{libs → }/templates/skel/webroot/css/cake.generic.css
  91. 0 cake/console/{libs → }/templates/skel/webroot/favicon.ico
  92. 0 cake/console/{libs → }/templates/skel/webroot/img/cake.icon.gif
  93. 0 cake/console/{libs → }/templates/skel/webroot/img/cake.power.gif
  94. 0 cake/console/{libs → }/templates/skel/webroot/index.php
  95. 0 cake/console/{libs → }/templates/skel/webroot/js/vendors.php
  96. +8 −1 cake/console/{libs → }/templates/skel/webroot/test.php
  97. +1 −1 cake/dispatcher.php
  98. +1 −1 cake/libs/cake_session.php
  99. +10 −10 cake/libs/configure.php
  100. +1 −1 cake/libs/controller/components/acl.php
  101. +7 −7 cake/libs/controller/components/cookie.php
  102. +1 −1 cake/libs/controller/components/request_handler.php
  103. +1 −2 cake/libs/debugger.php
  104. +1 −1 cake/libs/file.php
  105. +16 −1 cake/libs/folder.php
  106. +11 −4 cake/libs/http_socket.php
  107. +3 −2 cake/libs/inflector.php
  108. +3 −3 cake/libs/l10n.php
  109. +4 −1 cake/libs/magic_db.php
  110. +1 −1 cake/libs/model/behaviors/acl.php
  111. +1 −1 cake/libs/model/behaviors/containable.php
  112. +4 −4 cake/libs/model/cake_schema.php
  113. +7 −7 cake/libs/model/datasources/datasource.php
  114. +32 −19 cake/libs/model/datasources/dbo/dbo_mssql.php
  115. +17 −19 cake/libs/model/datasources/dbo/dbo_mysqli.php
  116. +19 −15 cake/libs/model/datasources/dbo/dbo_oracle.php
  117. +4 −2 cake/libs/model/datasources/dbo_source.php
  118. +4 −3 cake/libs/model/model.php
  119. +1 −1 cake/libs/multibyte.php
  120. +4 −3 cake/libs/object.php
  121. +9 −10 cake/libs/router.php
  122. +18 −18 cake/libs/security.php
  123. +1 −1 cake/libs/set.php
  124. +1 −1 cake/libs/validation.php
  125. +3 −3 cake/libs/view/errors/missing_action.ctp
  126. +3 −3 cake/libs/view/errors/missing_component_class.ctp
  127. +2 −2 cake/libs/view/errors/missing_component_file.ctp
  128. +3 −3 cake/libs/view/errors/missing_controller.ctp
  129. +2 −2 cake/libs/view/errors/missing_helper_class.ctp
  130. +4 −5 cake/libs/view/errors/missing_helper_file.ctp
  131. +3 −3 cake/libs/view/errors/missing_layout.ctp
  132. +2 −2 cake/libs/view/errors/missing_model.ctp
  133. +2 −2 cake/libs/view/errors/missing_scaffolddb.ctp
  134. +2 −2 cake/libs/view/errors/missing_table.ctp
  135. +2 −2 cake/libs/view/errors/missing_view.ctp
  136. +2 −2 cake/libs/view/errors/private_action.ctp
  137. +1 −1 cake/libs/view/errors/scaffold_error.ctp
  138. +1 −3 cake/libs/view/helpers/ajax.php
  139. +9 −0 cake/libs/view/helpers/javascript.php
  140. +14 −20 cake/libs/view/helpers/paginator.php
  141. +0 −1 cake/libs/view/helpers/xml.php
  142. +3 −1 cake/libs/view/pages/home.ctp
  143. +2 −2 cake/libs/view/scaffolds/edit.ctp
  144. +2 −2 cake/libs/view/scaffolds/index.ctp
  145. +8 −8 cake/libs/view/scaffolds/view.ctp
  146. +1 −1 cake/libs/view/theme.php
  147. +11 −9 cake/libs/xml.php
  148. +3 −2 cake/tests/cases/basics.test.php
  149. +461 −24 cake/tests/cases/console/cake.test.php
  150. +92 −3 cake/tests/cases/console/libs/acl.test.php
  151. +105 −14 cake/tests/cases/console/libs/shell.test.php
  152. +56 −9 cake/tests/cases/console/libs/tasks/controller.test.php
  153. +8 −4 cake/tests/cases/console/libs/tasks/db_config.test.php
  154. +16 −3 cake/tests/cases/console/libs/tasks/fixture.test.php
  155. +1 −1 cake/tests/cases/console/libs/tasks/model.test.php
  156. +11 −5 cake/tests/cases/console/libs/tasks/plugin.test.php
  157. +2 −2 cake/tests/cases/console/libs/tasks/project.test.php
  158. +14 −9 cake/tests/cases/console/libs/tasks/template.test.php
  159. +40 −12 cake/tests/cases/console/libs/tasks/test.test.php
  160. +2 −4 cake/tests/cases/console/libs/tasks/view.test.php
  161. +3 −3 cake/tests/cases/libs/cake_test_fixture.test.php
  162. +1 −1 cake/tests/cases/libs/code_coverage_manager.test.php
  163. +1 −0 cake/tests/cases/libs/controller/components/cookie.test.php
  164. +1 −1 cake/tests/cases/libs/controller/components/email.test.php
  165. +2 −2 cake/tests/cases/libs/folder.test.php
  166. +2 −2 cake/tests/cases/libs/http_socket.test.php
  167. +13 −0 cake/tests/cases/libs/inflector.test.php
  168. +1 −1 cake/tests/cases/libs/l10n.test.php
  169. +3 −14 cake/tests/cases/libs/magic_db.test.php
  170. +61 −58 cake/tests/cases/libs/model/behaviors/containable.test.php
  171. +12 −9 cake/tests/cases/libs/model/behaviors/translate.test.php
  172. +1 −1 cake/tests/cases/libs/model/cake_schema.test.php
  173. +205 −10 cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php
  174. +5 −2 cake/tests/cases/libs/model/datasources/dbo_source.test.php
  175. +11 −1 cake/tests/cases/libs/model/model_delete.test.php
  176. +25 −0 cake/tests/cases/libs/model/model_integration.test.php
  177. +36 −8 cake/tests/cases/libs/model/model_read.test.php
  178. +4 −0 cake/tests/cases/libs/model/model_validation.test.php
  179. +59 −11 cake/tests/cases/libs/model/model_write.test.php
  180. +69 −0 cake/tests/cases/libs/router.test.php
  181. +2 −2 cake/tests/cases/libs/sanitize.test.php
  182. +0 −1 cake/tests/cases/libs/set.test.php
  183. +1 −45 cake/tests/cases/libs/view/helpers/ajax.test.php
  184. +20 −0 cake/tests/cases/libs/view/helpers/cache.test.php
  185. +1 −2 cake/tests/cases/libs/view/helpers/javascript.test.php
  186. +0 −1 cake/tests/cases/libs/view/helpers/js.test.php
  187. +392 −34 cake/tests/cases/libs/view/helpers/paginator.test.php
  188. +20 −1 cake/tests/cases/libs/view/helpers/xml.test.php
  189. +19 −0 cake/tests/cases/libs/xml.test.php
  190. +1 −1 cake/tests/fixtures/uuid_tree_fixture.php
  191. +1 −1 cake/tests/groups/database.group.php
  192. +1 −1 cake/tests/groups/no_database.group.php
  193. +0 −1 cake/tests/lib/cake_reporter.php
  194. +2 −0 cake/tests/lib/cake_test_fixture.php
  195. +1 −1 cake/tests/lib/test_manager.php
  196. +1 −2 cake/tests/test_app/views/layouts/cache_layout.ctp
  197. +1 −1 cake/tests/test_app/views/layouts/email/text/default.ctp
  198. +3 −1 cake/tests/test_app/views/pages/home.ctp
  199. +3 −1 cake/tests/test_app/views/posts/test_nocache_tags.ctp
  200. 0 plugins/empty
View
1 .gitignore
@@ -1,3 +1,4 @@
app/config
app/tmp
+plugins
vendors
View
6 app/config/bootstrap.php
@@ -44,8 +44,8 @@
/**
* As of 1.3, additional rules for the inflector are added below
*
- * Inflector::rule('singular', array('rules' => array(), irregular' => array(), 'uninflected' => array()));
- * Inflector::rule('plural', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
+ * Inflector::rules('singular', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
+ * Inflector::rules('plural', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
*
*/
-?>
+?>
View
5 app/config/core.php
@@ -185,6 +185,11 @@
Configure::write('Acl.classname', 'DbAcl');
Configure::write('Acl.database', 'default');
/**
+ * If you are on PHP 5.3 uncomment this line and correct your server timezone
+ * to fix the date & time related errors.
+ */
+ //date_default_timezone_set('UTC');
+/**
*
* Cache Engine Configuration
* Default settings provided below
View
9 app/webroot/test.php
@@ -24,7 +24,14 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
-error_reporting(E_ALL);
+/**
+ * PHP 5.3 raises many notices in bootstrap.
+ */
+if (!defined('E_DEPRECATED')) {
+ define('E_DEPRECATED', 8192);
+}
+error_reporting(E_ALL & ~E_DEPRECATED);
+
set_time_limit(0);
ini_set('memory_limit','128M');
ini_set('display_errors', 1);
View
1 cake/basics.php
@@ -89,6 +89,7 @@ function config() {
* </code>
*
* @param string $name Filename without the .php part
+ * @deprecated
*/
function uses() {
$args = func_get_args();
View
5 cake/bootstrap.php
@@ -22,6 +22,11 @@
if (!defined('PHP5')) {
define('PHP5', (PHP_VERSION >= 5));
}
+if (!defined('E_DEPRECATED')) {
+ define('E_DEPRECATED', 8192);
+}
+error_reporting(E_ALL & ~E_DEPRECATED);
+
require CORE_PATH . 'cake' . DS . 'basics.php';
$TIME_START = getMicrotime();
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
View
253 cake/console/cake.php
@@ -1,7 +1,5 @@
#!/usr/bin/php -q
<?php
-/* SVN FILE: $Id$ */
-
/**
* Command-line code generation utility to automate programmer chores.
*
@@ -26,7 +24,9 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
-
+if (!defined('E_DEPRECATED')) {
+ define('E_DEPRECATED', 8192);
+}
/**
* Shell dispatcher
*
@@ -135,15 +135,21 @@ function ShellDispatcher($args = array()) {
/**
* Constructor
*
- * @param array $args the argv.
+ * The execution of the script is stopped after dispatching the request with
+ * a status code of either 0 or 1 according to the result of the dispatch.
+ *
+ * @param array $args the argv
+ * @return void
+ * @access public
*/
function __construct($args = array()) {
set_time_limit(0);
+
$this->__initConstants();
$this->parseParams($args);
$this->_initEnvironment();
$this->__buildPaths();
- $this->_stop($this->dispatch());
+ $this->_stop($this->dispatch() === false ? 1 : 0);
}
/**
@@ -220,7 +226,6 @@ function __buildPaths() {
if (!class_exists('Folder')) {
require LIBS . 'folder.php';
}
-
foreach ($pluginPaths as $pluginPath) {
$Folder =& new Folder($pluginPath);
list($plugins,) = $Folder->read(false, true);
@@ -278,7 +283,7 @@ function __bootstrap() {
Configure::getInstance(file_exists(CONFIGS . 'bootstrap.php'));
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
- include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
+ include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
App::build();
}
@@ -305,118 +310,134 @@ function clear() {
/**
* Dispatches a CLI request
*
+ * @return boolean
* @access public
*/
function dispatch() {
- if (isset($this->args[0])) {
+ $arg = $this->shiftArgs();
+
+ if (!$arg) {
+ $this->help();
+ return false;
+ }
+ if ($arg == 'help') {
+ $this->help();
+ return true;
+ }
+
+ if (strpos($arg, '.') !== false) {
+ list($plugin, $shell) = explode('.', $arg);
+ } else {
$plugin = null;
- $shell = $this->args[0];
- if (strpos($shell, '.') !== false) {
- list($plugin, $shell) = explode('.', $this->args[0]);
- }
+ $shell = $arg;
+ }
+ $this->shell = $shell;
+ $this->shellName = Inflector::camelize($shell);
+ $this->shellClass = $this->shellName . 'Shell';
- $this->shell = $shell;
- $this->shiftArgs();
- $this->shellName = Inflector::camelize($this->shell);
- $this->shellClass = $this->shellName . 'Shell';
+ $arg = null;
- if ($this->shell === 'help') {
- $this->help();
- } else {
- $loaded = false;
- foreach ($this->shellPaths as $path) {
- $this->shellPath = $path . $this->shell . '.php';
-
- $isPlugin = ($plugin && strpos($path, DS . $plugin . DS . 'vendors' . DS . 'shells' . DS) !== false);
- if (($isPlugin && file_exists($this->shellPath)) || (!$plugin && file_exists($this->shellPath))) {
- $loaded = true;
- break;
- }
- }
+ if (isset($this->args[0])) {
+ $arg = $this->args[0];
+ $this->shellCommand = Inflector::variable($arg);
+ }
- if ($loaded) {
- if (!class_exists('Shell')) {
- require CONSOLE_LIBS . 'shell.php';
- }
- require $this->shellPath;
- if (class_exists($this->shellClass)) {
- $command = null;
- if (isset($this->args[0])) {
- $command = $this->args[0];
- }
- $this->shellCommand = Inflector::variable($command);
- $shell = new $this->shellClass($this);
-
- if (strtolower(get_parent_class($shell)) == 'shell') {
- $shell->initialize();
- $shell->loadTasks();
-
- foreach ($shell->taskNames as $task) {
- if (strtolower(get_parent_class($shell)) == 'shell') {
- $shell->{$task}->initialize();
- $shell->{$task}->loadTasks();
- }
- }
-
- $task = Inflector::camelize($command);
- if (in_array($task, $shell->taskNames)) {
- $this->shiftArgs();
- $shell->{$task}->startup();
- if (isset($this->args[0]) && $this->args[0] == 'help') {
- if (method_exists($shell->{$task}, 'help')) {
- $shell->{$task}->help();
- $this->_stop();
- } else {
- $this->help();
- }
- }
- return $shell->{$task}->execute();
- }
- }
+ $Shell = $this->_getShell($plugin);
- $classMethods = get_class_methods($shell);
+ if (!$Shell) {
+ $title = sprintf(__('Error: Class %s could not be loaded.', true), $this->shellClass);
+ $this->stderr($title . "\n");
+ return false;
+ }
- $privateMethod = $missingCommand = false;
- if ((in_array($command, $classMethods) || in_array(strtolower($command), $classMethods)) && strpos($command, '_', 0) === 0) {
- $privateMethod = true;
- }
+ $methods = array();
- if (!in_array($command, $classMethods) && !in_array(strtolower($command), $classMethods)) {
- $missingCommand = true;
- }
+ if (is_a($Shell, 'Shell')) {
+ $Shell->initialize();
+ $Shell->loadTasks();
- $protectedCommands = array(
- 'initialize','in','out','err','hr',
- 'createfile', 'isdir','copydir','object','tostring',
- 'requestaction','log','cakeerror', 'shelldispatcher',
- '__initconstants','__initenvironment','__construct',
- 'dispatch','__bootstrap','getinput','stdout','stderr','parseparams','shiftargs'
- );
+ foreach ($Shell->taskNames as $task) {
+ if (is_a($Shell->{$task}, 'Shell')) {
+ $Shell->{$task}->initialize();
+ $Shell->{$task}->loadTasks();
+ }
+ }
- if (in_array(strtolower($command), $protectedCommands)) {
- $missingCommand = true;
- }
+ $task = Inflector::camelize($arg);
- if ($missingCommand && method_exists($shell, 'main')) {
- $shell->startup();
- return $shell->main();
- } elseif (!$privateMethod && method_exists($shell, $command)) {
- $this->shiftArgs();
- $shell->startup();
- return $shell->{$command}();
- } else {
- $this->stderr("Unknown {$this->shellName} command '$command'.\nFor usage, try 'cake {$this->shell} help'.\n\n");
- }
+ if (in_array($task, $Shell->taskNames)) {
+ $this->shiftArgs();
+ $Shell->{$task}->startup();
+
+ if (isset($this->args[0]) && $this->args[0] == 'help') {
+ if (method_exists($Shell->{$task}, 'help')) {
+ $Shell->{$task}->help();
} else {
- $this->stderr('Class '.$this->shellClass.' could not be loaded');
+ $this->help();
}
- } else {
- $this->help();
+ return true;
}
+ return $Shell->{$task}->execute();
+ }
+ $methods = array_diff(get_class_methods('Shell'), array('help'));
+ }
+ $methods = array_diff(get_class_methods($Shell), $methods);
+ $added = in_array(strtolower($arg), array_map('strtolower', $methods));
+ $private = $arg[0] == '_' && method_exists($Shell, $arg);
+
+ if (!$private) {
+ if ($added) {
+ $this->shiftArgs();
+ $Shell->startup();
+ return $Shell->{$arg}();
+ }
+ if (method_exists($Shell, 'main')) {
+ $Shell->startup();
+ return $Shell->main();
}
- } else {
- $this->help();
}
+
+ $title = sprintf(__('Error: Unknown %1$s command %2$s.', true), $this->shellName, $arg);
+ $message = sprintf(__('For usage try `cake %s help`', true), $this->shell);
+ $this->stderr($title . "\n" . $message . "\n");
+ return false;
+ }
+/**
+ * Get shell to use, either plugin shell or application shell
+ *
+ * All paths in the shellPaths property are searched.
+ * shell, shellPath and shellClass properties are taken into account.
+ *
+ * @param string $plugin Optionally the name of a plugin
+ * @return mixed False if no shell could be found or an object on success
+ * @access protected
+ */
+ function _getShell($plugin = null) {
+ foreach ($this->shellPaths as $path) {
+ $this->shellPath = $path . $this->shell . '.php';
+ $pluginShellPath = DS . $plugin . DS . 'vendors' . DS . 'shells' . DS;
+
+ if ((strpos($path, $pluginShellPath) !== false || !$plugin) && file_exists($this->shellPath)) {
+ $loaded = true;
+ break;
+ }
+ }
+ if (!isset($loaded)) {
+ return false;
+ }
+
+ if (!class_exists('Shell')) {
+ require CONSOLE_LIBS . 'shell.php';
+ }
+
+ if (!class_exists($this->shellClass)) {
+ require $this->shellPath;
+ }
+ if (!class_exists($this->shellClass)) {
+ return false;
+ }
+ $Shell = new $this->shellClass($this);
+ return $Shell;
}
/**
@@ -475,7 +496,7 @@ function stdout($string, $newline = true) {
* @access public
*/
function stderr($string) {
- fwrite($this->stderr, 'Error: '. $string);
+ fwrite($this->stderr, $string);
}
/**
@@ -486,13 +507,15 @@ function stderr($string) {
*/
function parseParams($params) {
$this->__parseParams($params);
-
$defaults = array('app' => 'app', 'root' => dirname(dirname(dirname(__FILE__))), 'working' => null, 'webroot' => 'webroot');
-
$params = array_merge($defaults, array_intersect_key($this->params, $defaults));
-
- $isWin = array_filter(array_map('strpos', $params, array('\\')));
-
+ $isWin = false;
+ foreach ($defaults as $default => $value) {
+ if (strpos($params[$default], '\\') !== false) {
+ $isWin = true;
+ break;
+ }
+ }
$params = str_replace('\\', '/', $params);
if (!empty($params['working']) && (!isset($this->args[0]) || isset($this->args[0]) && $this->args[0]{0} !== '.')) {
@@ -504,7 +527,7 @@ function parseParams($params) {
}
}
- if ($params['app'][0] == '/' || preg_match('/([a-zA-Z])(:)/i', $params['app'], $matches)) {
+ if ($params['app'][0] == '/' || preg_match('/([a-z])(:)/i', $params['app'], $matches)) {
$params['root'] = dirname($params['app']);
} elseif (strpos($params['app'], '/')) {
$params['root'] .= '/' . dirname($params['app']);
@@ -521,7 +544,7 @@ function parseParams($params) {
}
/**
- * Helper for recursively paraing params
+ * Helper for recursively parsing params
*
* @return array params
* @access private
@@ -555,16 +578,11 @@ function __parseParams($params) {
/**
* Removes first argument and shifts other arguments up
*
- * @return boolean False if there are no arguments
+ * @return mixed Null if there are no arguments otherwise the shifted argument
* @access public
*/
function shiftArgs() {
- if (empty($this->args)) {
- return false;
- }
- unset($this->args[0]);
- $this->args = array_values($this->args);
- return true;
+ return array_shift($this->args);
}
/**
@@ -589,7 +607,6 @@ function help() {
$this->stdout("\nAvailable Shells:");
$_shells = array();
-
foreach ($this->shellPaths as $path) {
if (is_dir($path)) {
$shells = App::objects('file', $path);
@@ -603,6 +620,7 @@ function help() {
} else {
sort($shells);
foreach ($shells as $shell) {
+
if ($shell !== 'shell.php') {
$this->stdout("\t " . str_replace('.php', '', $shell));
}
@@ -612,7 +630,6 @@ function help() {
}
$this->stdout("\nTo run a command, type 'cake shell_name [args]'");
$this->stdout("To get help on a specific command, type 'cake shell_name help'");
- $this->_stop();
}
/**
View
225 cake/console/libs/acl.php
@@ -137,52 +137,29 @@ function main() {
* @access public
*/
function create() {
-
$this->_checkArgs(3, 'create');
$this->checkNodeType();
extract($this->__dataVars());
$class = ucfirst($this->args[0]);
- $object = new $class();
-
- if (preg_match('/^([\w]+)\.(.*)$/', $this->args[1], $matches) && count($matches) == 3) {
- $parent = array(
- 'model' => $matches[1],
- 'foreign_key' => $matches[2],
- );
- } else {
- $parent = $this->args[1];
- }
+ $parent = $this->parseIdentifier($this->args[1]);
if (!empty($parent) && $parent != '/' && $parent != 'root') {
- @$parent = $object->node($parent);
- if (empty($parent)) {
- $this->err(sprintf(__('Could not find parent node using reference "%s"', true), $this->args[1]));
- return;
- } else {
- $parent = Set::extract($parent, "0.{$class}.id");
- }
+ $parent = $this->_getNodeId($class, $parent);
} else {
$parent = null;
}
- if (preg_match('/^([\w]+)\.(.*)$/', $this->args[2], $matches) && count($matches) == 3) {
- $data = array(
- 'model' => $matches[1],
- 'foreign_key' => $matches[2],
- );
- } else {
- if (!($this->args[2] == '/')) {
- $data = array('alias' => $this->args[2]);
- } else {
- $this->error(__('/ can not be used as an alias!', true), __('\t/ is the root, please supply a sub alias', true));
- }
+ $data = $this->parseIdentifier($this->args[2]);
+ if (is_string($data) && $data != '/') {
+ $data = array('alias' => $data);
+ } elseif (is_string($data)) {
+ $this->error(__('/ can not be used as an alias!', true), __("\t/ is the root, please supply a sub alias", true));
}
$data['parent_id'] = $parent;
- $object->create();
-
- if ($object->save($data)) {
+ $this->Acl->{$class}->create();
+ if ($this->Acl->{$class}->save($data)) {
$this->out(sprintf(__("New %s '%s' created.\n", true), $class, $this->args[2]), true);
} else {
$this->err(sprintf(__("There was a problem creating a new %s '%s'.", true), $class, $this->args[2]));
@@ -198,7 +175,11 @@ function delete() {
$this->_checkArgs(2, 'delete');
$this->checkNodeType();
extract($this->__dataVars());
- if (!$this->Acl->{$class}->delete($this->args[1])) {
+
+ $identifier = $this->parseIdentifier($this->args[1]);
+ $nodeId = $this->_getNodeId($class, $identifier);
+
+ if (!$this->Acl->{$class}->delete($nodeId)) {
$this->error(__("Node Not Deleted", true), sprintf(__("There was an error deleting the %s. Check that the node exists", true), $class) . ".\n");
}
$this->out(sprintf(__("%s deleted", true), $class) . ".\n", true);
@@ -213,10 +194,13 @@ function setParent() {
$this->_checkArgs(3, 'setParent');
$this->checkNodeType();
extract($this->__dataVars());
+ $target = $this->parseIdentifier($this->args[1]);
+ $parent = $this->parseIdentifier($this->args[2]);
+
$data = array(
$class => array(
- 'id' => $this->args[1],
- 'parent_id' => $this->args[2]
+ 'id' => $this->_getNodeId($class, $target),
+ 'parent_id' => $this->_getNodeId($class, $parent)
)
);
$this->Acl->{$class}->create();
@@ -378,73 +362,90 @@ function initdb() {
* @access public
*/
function help() {
- $head = __("Usage: cake acl <command> <arg1> <arg2>...", true) . "\n";
+ $head = "-----------------------------------------------\n";
+ $head .= __("Usage: cake acl <command> <arg1> <arg2>...", true) . "\n";
$head .= "-----------------------------------------------\n";
- $head .= __("Commands:", true) . "\n\n";
+ $head .= __("Commands:", true) . "\n";
$commands = array(
- 'create' => "\tcreate aro|aco <parent> <node>\n" .
- "\t\t" . __("Creates a new ACL object <node> under the parent specified by <parent>, an id/alias.", true) . "\n" .
- "\t\t" . __("The <parent> and <node> references can be in one of the following formats:", true) . "\n" .
- "\t\t\t- " . __("<model>.<id> - The node will be bound to a specific record of the given model", true) . "\n" .
- "\t\t\t- " . __("<alias> - The node will be given a string alias (or path, in the case of <parent>),", true) . "\n" .
- "\t\t\t " . __("i.e. 'John'. When used with <parent>, this takes the form of an alias path,", true) . "\n" .
- "\t\t\t " . __("i.e. <group>/<subgroup>/<parent>.", true) . "\n" .
- "\t\t" . __("To add a node at the root level, enter 'root' or '/' as the <parent> parameter.", true) . "\n",
-
- 'delete' => "\tdelete aro|aco <node>\n" .
- "\t\t" . __("Deletes the ACL object with the given <node> reference (see 'create' for info on node references).", true) . "\n",
-
- 'setparent' => "\tsetParent aro|aco <node> <parent>\n" .
- "\t\t" . __("Moves the ACL object specified by <node> beneath the parent ACL object specified by <parent>.", true) . "\n" .
- "\t\t" . __("To identify the node and parent, use the row id.", true) . "\n",
-
- 'getpath' => "\tgetPath aro|aco <node>\n" .
- "\t\t" . __("Returns the path to the ACL object specified by <node>. This command", true) . "\n" .
- "\t\t" . __("is useful in determining the inhertiance of permissions for a certain", true) . "\n" .
- "\t\t" . __("object in the tree.", true) . "\n" .
- "\t\t" . __("For more detailed parameter usage info, see help for the 'create' command.", true) . "\n",
-
- 'check' => "\tcheck <aro_id> <aco_id> [<aco_action>] " . __("or", true) . " all\n" .
- "\t\t" . __("Use this command to check ACL permissions.", true) . "\n" .
- "\t\t" . __("For more detailed parameter usage info, see help for the 'create' command.", true) . "\n",
-
- 'grant' => "\tgrant <aro_id> <aco_id> [<aco_action>] " . __("or", true) . " all\n" .
- "\t\t" . __("Use this command to grant ACL permissions. Once executed, the ARO", true) . "\n" .
- "\t\t" . __("specified (and its children, if any) will have ALLOW access to the", true) . "\n" .
- "\t\t" . __("specified ACO action (and the ACO's children, if any).", true) . "\n" .
- "\t\t" . __("For more detailed parameter usage info, see help for the 'create' command.", true) . "\n",
-
- 'deny' => "\tdeny <aro_id> <aco_id> [<aco_action>]" . __("or", true) . " all\n" .
- "\t\t" . __("Use this command to deny ACL permissions. Once executed, the ARO", true) . "\n" .
- "\t\t" . __("specified (and its children, if any) will have DENY access to the", true) . "\n" .
- "\t\t" . __("specified ACO action (and the ACO's children, if any).", true) . "\n" .
- "\t\t" . __("For more detailed parameter usage info, see help for the 'create' command.", true) . "\n",
-
- 'inherit' => "\tinherit <aro_id> <aco_id> [<aco_action>]" . __("or", true) . " all\n" .
- "\t\t" . __("Use this command to force a child ARO object to inherit its", true) . "\n" .
- "\t\t" . __("permissions settings from its parent.", true) . "\n" .
- "\t\t" . __("For more detailed parameter usage info, see help for the 'create' command.", true) . "\n",
-
- 'view' => "\tview aro|aco [<node>]\n" .
- "\t\t" . __("The view command will return the ARO or ACO tree. The optional", true) . "\n" .
- "\t\t" . __("id/alias parameter allows you to return only a portion of the requested tree.", true) . "\n" .
- "\t\t" . __("For more detailed parameter usage info, see help for the 'create' command.", true) . "\n",
-
- 'initdb' => "\tinitdb\n".
- "\t\t" . __("Uses this command : cake schema run create DbAcl", true) . "\n",
-
- 'help' => "\thelp [<command>]\n" .
- "\t\t" . __("Displays this help message, or a message on a specific command.", true) . "\n"
+ 'create' => "create aro|aco <parent> <node>\n" .
+ "\t" . __("Creates a new ACL object <node> under the parent", true) . "\n" .
+ "\t" . __("specified by <parent>, an id/alias.", true) . "\n" .
+ "\t" . __("The <parent> and <node> references can be", true) . "\n" .
+ "\t" . __("in one of the following formats:", true) . "\n\n" .
+ "\t\t- " . __("<model>.<id> - The node will be bound to a", true) . "\n" .
+ "\t\t" . __("specific record of the given model.", true) . "\n\n" .
+ "\t\t- " . __("<alias> - The node will be given a string alias,", true) . "\n" .
+ "\t\t" . __(" (or path, in the case of <parent>)", true) . "\n" .
+ "\t\t " . __("i.e. 'John'. When used with <parent>,", true) . "\n" .
+ "\t\t" . __("this takes the form of an alias path,", true) . "\n" .
+ "\t\t " . __("i.e. <group>/<subgroup>/<parent>.", true) . "\n\n" .
+ "\t" . __("To add a node at the root level,", true) . "\n" .
+ "\t" . __("enter 'root' or '/' as the <parent> parameter.", true) . "\n",
+
+ 'delete' => "delete aro|aco <node>\n" .
+ "\t" . __("Deletes the ACL object with the given <node> reference", true) . "\n" .
+ "\t" . __("For more detailed parameter usage info,", true) . "\n" .
+ "\t" . __("see help for the 'create' command.", true),
+
+ 'setparent' => "setParent aro|aco <node> <parent>\n" .
+ "\t" . __("Moves the ACL object specified by <node> beneath", true) . "\n" .
+ "\t" . __("the parent ACL object specified by <parent>.", true) . "\n" .
+ "\t" . __("For more detailed parameter usage info,", true) . "\n" .
+ "\t" . __("see help for the 'create' command.", true),
+
+ 'getpath' => "getPath aro|aco <node>\n" .
+ "\t" . __("Returns the path to the ACL object specified by <node>. This command", true) . "\n" .
+ "\t" . __("is useful in determining the inhertiance of permissions for a certain", true) . "\n" .
+ "\t" . __("object in the tree.", true) . "\n" .
+ "\t" . __("For more detailed parameter usage info,", true) . "\n" .
+ "\t" . __("see help for the 'create' command.", true),
+
+ 'check' => "check <aro_id> <aco_id> [<aco_action>] " . __("or", true) . " all\n" .
+ "\t" . __("Use this command to check ACL permissions.", true) . "\n" .
+ "\t" . __("For more detailed parameter usage info,", true) . "\n" .
+ "\t" . __("see help for the 'create' command.", true),
+
+ 'grant' => "grant <aro_id> <aco_id> [<aco_action>] " . __("or", true) . " all\n" .
+ "\t" . __("Use this command to grant ACL permissions. Once executed, the ARO", true) . "\n" .
+ "\t" . __("specified (and its children, if any) will have ALLOW access to the", true) . "\n" .
+ "\t" . __("specified ACO action (and the ACO's children, if any).", true) . "\n" .
+ "\t" . __("For more detailed parameter usage info,", true) . "\n" .
+ "\t" . __("see help for the 'create' command.", true),
+
+ 'deny' => "deny <aro_id> <aco_id> [<aco_action>]" . __("or", true) . " all\n" .
+ "\t" . __("Use this command to deny ACL permissions. Once executed, the ARO", true) . "\n" .
+ "\t" . __("specified (and its children, if any) will have DENY access to the", true) . "\n" .
+ "\t" . __("specified ACO action (and the ACO's children, if any).", true) . "\n" .
+ "\t" . __("For more detailed parameter usage info,", true) . "\n" .
+ "\t" . __("see help for the 'create' command.", true),
+
+ 'inherit' => "inherit <aro_id> <aco_id> [<aco_action>]" . __("or", true) . " all\n" .
+ "\t" . __("Use this command to force a child ARO object to inherit its", true) . "\n" .
+ "\t" . __("permissions settings from its parent.", true) . "\n" .
+ "\t" . __("For more detailed parameter usage info,", true) . "\n" .
+ "\t" . __("see help for the 'create' command.", true),
+
+ 'view' => "view aro|aco [<node>]\n" .
+ "\t" . __("The view command will return the ARO or ACO tree.", true) . "\n" .
+ "\t" . __("The optional id/alias parameter allows you to return\n\tonly a portion of the requested tree.", true) . "\n" .
+ "\t" . __("For more detailed parameter usage info,", true) . "\n" .
+ "\t" . __("see help for the 'create' command.", true),
+
+ 'initdb' => "initdb\n".
+ "\t" . __("Uses this command : cake schema run create DbAcl", true),
+
+ 'help' => "help [<command>]\n" .
+ "\t" . __("Displays this help message, or a message on a specific command.", true)
);
$this->out($head);
if (!isset($this->args[0])) {
foreach ($commands as $cmd) {
$this->out("{$cmd}\n\n");
}
- } elseif (isset($commands[low($this->args[0])])) {
- $this->out($commands[low($this->args[0])] . "\n\n");
+ } elseif (isset($commands[strtolower($this->args[0])])) {
+ $this->out($commands[strtolower($this->args[0])] . "\n\n");
} else {
$this->out(sprintf(__("Command '%s' not found", true), $this->args[0]));
}
@@ -477,7 +478,7 @@ function nodeExists() {
return false;
}
extract($this->__dataVars($this->args[0]));
- $key = (ife(is_numeric($this->args[1]), $secondary_id, 'alias'));
+ $key = is_numeric($this->args[1]) ? $secondary_id : 'alias';
$conditions = array($class . '.' . $key => $this->args[1]);
$possibility = $this->Acl->{$class}->find('all', compact('conditions'));
if (empty($possibility)) {
@@ -487,6 +488,42 @@ function nodeExists() {
}
/**
+ * Parse an identifier into Model.foriegnKey or an alias.
+ * Takes an identifier determines its type and returns the result as used by other methods.
+ *
+ * @param string $identifier Identifier to parse
+ * @return mixed a string for aliases, and an array for model.foreignKey
+ **/
+ function parseIdentifier($identifier) {
+ if (preg_match('/^([\w]+)\.(.*)$/', $identifier, $matches)) {
+ return array(
+ 'model' => $matches[1],
+ 'foreign_key' => $matches[2],
+ );
+ }
+ return $identifier;
+ }
+
+/**
+ * Get the node for a given identifier. $identifier can either be a string alias
+ * or an array of properties to use in AcoNode::node()
+ *
+ * @param string $class Class type you want (Aro/Aco)
+ * @param mixed $identifier A mixed identifier for finding the node.
+ * @return int Integer of NodeId. Will trigger an error if nothing is found.
+ **/
+ function _getNodeId($class, $identifier) {
+ $node = $this->Acl->{$class}->node($identifier);
+ if (empty($node)) {
+ if (is_array($identifier)) {
+ $identifier = var_export($identifier, true);
+ }
+ $this->error(sprintf(__('Could not find node using reference "%s"', true), $identifier));
+ }
+ return Set::extract($node, "0.{$class}.id");
+ }
+
+/**
* get params for standard Acl methods
*
* @return array aro, aco, action
@@ -533,7 +570,7 @@ function __dataVars($type = null) {
}
$vars = array();
$class = ucwords($type);
- $vars['secondary_id'] = ife(strtolower($class) == 'aro', 'foreign_key', 'object_id');
+ $vars['secondary_id'] = (strtolower($class) == 'aro') ? 'foreign_key' : 'object_id';
$vars['data_name'] = $type;
$vars['table_name'] = $type . 's';
$vars['class'] = $class;
View
2 cake/console/libs/api.php
@@ -47,7 +47,7 @@ class ApiShell extends Shell {
*
* @access public
*/
- function initialize () {
+ function initialize() {
$this->paths = array_merge($this->paths, array(
'behavior' => LIBS . 'model' . DS . 'behaviors' . DS,
'cache' => LIBS . 'cache' . DS,
View
8 cake/console/libs/bake.php
@@ -56,6 +56,12 @@ function loadTasks() {
if (isset($this->params['connection'])) {
$this->{$task}->connection = $this->params['connection'];
}
+ foreach($this->args as $i => $arg) {
+ if (strpos($arg, '.')) {
+ list($this->params['plugin'], $this->args[$i]) = explode('.', $arg);
+ break;
+ }
+ }
if (isset($this->params['plugin'])) {
$this->{$task}->plugin = $this->params['plugin'];
}
@@ -157,7 +163,7 @@ function all() {
$object = new $model();
$modelExists = true;
} else {
- App::import('Model');
+ App::import('Model', 'Model', false);
$object = new Model(array('name' => $name, 'ds' => $this->connection));
}
View
4 cake/console/libs/schema.php
@@ -27,7 +27,7 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('File');
-App::import('Model', 'CakeSchema');
+App::import('Model', 'CakeSchema', false);
/**
* Schema is a command-line database management utility for automating programmer chores.
@@ -208,7 +208,7 @@ function dump() {
}
}
$db =& ConnectionManager::getDataSource($this->Schema->connection);
- $contents = "#". $Schema->name ." sql generated on: " . date('Y-m-d H:i:s') . " : ". time()."\n\n";
+ $contents = "#" . $Schema->name . " sql generated on: " . date('Y-m-d H:i:s') . " : " . time() . "\n\n";
$contents .= $db->dropSchema($Schema) . "\n\n". $db->createSchema($Schema);
if ($write) {
if (strpos($write, '.sql') === false) {
View
89 cake/console/libs/shell.php
@@ -320,7 +320,7 @@ function loadTasks() {
}
if (!isset($this->{$taskName})) {
- $this->err("Task '".$taskName."' could not be loaded");
+ $this->err("Task '" . $taskName . "' could not be loaded");
$this->_stop();
}
}
@@ -363,69 +363,78 @@ function in($prompt, $options = null, $default = null) {
}
/**
- * Outputs to the stdout filehandle.
+ * Outputs a single or multiple messages to stdout.
*
- * @param string $string String to output.
- * @param boolean $newline If true, the outputs gets an added newline.
+ * @param mixed $message A string or a an array of strings to output
+ * @param mixed $after Appended to message, if true a newline is used
* @access public
*/
- function out($string, $newline = true) {
- if (is_array($string)) {
- $str = '';
- foreach ($string as $message) {
- $str .= $message ."\n";
- }
- $string = $str;
+ function out($message, $after = true) {
+ if (is_array($message)) {
+ $message = implode($this->nl(), $message);
}
- return $this->Dispatch->stdout($string, $newline);
+ $this->Dispatch->stdout($message . $this->nl($after), false);
}
/**
- * Outputs to the stderr filehandle.
+ * Outputs a single or multiple error messages to stderr.
*
- * @param string $string Error text to output.
+ * @param mixed $message A string or a an array of strings to output
+ * @param mixed $after Appended to message, if true a newline is used
* @access public
*/
- function err($string) {
- if (is_array($string)) {
- $str = '';
- foreach ($string as $message) {
- $str .= $message ."\n";
- }
- $string = $str;
+ function err($message, $after = true) {
+ if (is_array($message)) {
+ $message = implode($this->nl(), $message);
}
- return $this->Dispatch->stderr($string."\n");
+ $this->Dispatch->stderr($message . $this->nl($after));
}
/**
- * Outputs a series of minus characters to the standard output, acts as a visual separator.
+ * Returns a single or multiple linefeeds sequences.
*
- * @param boolean $newline If true, the outputs gets an added newline.
+ * @param mixed $format If true returns a linefeed sequence, if false null,
+ * if a string is given that is returned,
+ * if an integer is given it is used as a multiplier to return multiple linefeed sequences
* @access public
+ * @return string
*/
- function hr($newline = false) {
- if ($newline) {
- $this->out("\n");
+ function nl($format = true) {
+ if (is_string($format)) {
+ return $format . "\n";
}
- $this->out('---------------------------------------------------------------');
- if ($newline) {
- $this->out("\n");
+ if (is_int($format)) {
+ return str_repeat("\n", $format);
}
+ return $format ? "\n" : null;
}
/**
- * Displays a formatted error message and exits the application
+ * Outputs a series of minus characters to the standard output, acts as a visual separator.
*
- * @param string $title Title of the error message
- * @param string $msg Error message
+ * @param mixed $surround If true, the outputs gets surrounded by newlines.
* @access public
*/
- function error($title, $msg) {
- $out = "$title\n";
- $out .= "$msg\n";
- $out .= "\n";
- $this->err($out);
- $this->_stop();
+ function hr($surround = false) {
+ $this->out(null, $surround);
+ $this->out('---------------------------------------------------------------');
+ $this->out(null, $surround);
+ }
+/**
+ * Displays a formatted error message
+ * and exits the application with status code 1
+ *
+ * @param string $title Title of the error
+ * @param string $message An optional error message
+ * @access public
+ */
+ function error($title, $message = null) {
+ $this->err(sprintf(__('Error: %s', true), $title));
+
+ if (!empty($message)) {
+ $this->err($message);
+ }
+ $this->_stop(1);
}
/**
@@ -466,7 +475,7 @@ function createFile ($path, $contents) {
}
}
if (!class_exists('File')) {
- uses('file');
+ require LIBS . 'file.php';
}
if ($File = new File($path, true)) {
View
49 cake/console/libs/tasks/controller.php
@@ -78,24 +78,29 @@ function execute() {
if (strtolower($this->args[0]) == 'all') {
return $this->all();
}
+
$controller = Inflector::camelize($this->args[0]);
- $actions = null;
- if (isset($this->args[1]) && $this->args[1] == 'scaffold') {
- $this->out(__('Baking scaffold for ', true) . $controller);
+ $actions = 'scaffold';
+
+ if (!empty($this->args[1]) && ($this->args[1] == 'public' || $this->args[1] == 'scaffold')) {
+ $this->out(__('Baking basic crud methods for ', true) . $controller);
$actions = $this->bakeActions($controller);
- } else {
- $actions = 'scaffold';
+ } elseif (!empty($this->args[1]) && $this->args[1] == 'admin') {
+ $admin = $this->Project->getAdmin();
+ if ($admin) {
+ $this->out('Adding ' . Configure::read('Routing.admin') .' methods');
+ $actions= $this->bakeActions($controller, $admin);
+ }
}
- if ((isset($this->args[1]) && $this->args[1] == 'admin') || (isset($this->args[2]) && $this->args[2] == 'admin')) {
- if ($admin = $this->Project->getAdmin()) {
+
+ if (!empty($this->args[2]) && $this->args[2] == 'admin') {
+ $admin = $this->Project->getAdmin();
+ if ($admin) {
$this->out('Adding ' . Configure::read('Routing.admin') .' methods');
- if ($actions == 'scaffold') {
- $actions = $this->bakeActions($controller, $admin);
- } else {
- $actions .= $this->bakeActions($controller, $admin);
- }
+ $actions .= "\n" . $this->bakeActions($controller, $admin);
}
}
+
if ($this->bake($controller, $actions)) {
if ($this->_checkUnitTest()) {
$this->bakeTest($controller);
@@ -280,7 +285,7 @@ function bakeActions($controllerName, $admin = null, $wannaUseSession = true) {
if ($this->plugin) {
$modelImport = $this->plugin . '.' . $modelImport;
}
- if (!App::import('Model', $currentModelName)) {
+ if (!App::import('Model', $modelImport)) {
$this->err(__('You must have a model for this class to build basic methods. Please try again.', true));
$this->_stop();
}
@@ -456,17 +461,19 @@ function help() {
$this->out("controller <name>");
$this->out("\tbakes controller with var \$scaffold");
$this->out('');
- $this->out("controller <name> scaffold");
- $this->out("\tbakes controller with scaffold actions.");
+ $this->out("controller <name> public");
+ $this->out("\tbakes controller with basic crud actions");
$this->out("\t(index, view, add, edit, delete)");
$this->out('');
- $this->out("controller <name> scaffold admin");
- $this->out("\tbakes a controller with scaffold actions for both public");
- $this->out("\tand Configure::read('Routing.admin')");
- $this->out('');
$this->out("controller <name> admin");
- $this->out("\tbakes a controller with scaffold actions only for");
- $this->out("\tConfigure::read('Routing.admin')");
+ $this->out("\tbakes a controller with basic crud actions for");
+ $this->out("\tConfigure::read('Routing.admin') methods.");
+ $this->out('');
+ $this->out("controller <name> public admin");
+ $this->out("\tbakes a controller with basic crud actions for");
+ $this->out("\tConfigure::read('Routing.admin') and non admin methods.");
+ $this->out("\t(index, view, add, edit, delete,");
+ $this->out("\tadmin_index, admin_view, admin_edit, admin_add, admin_delete)");
$this->out('');
$this->out("controller all");
$this->out("\tbakes all controllers with CRUD methods.");
View
6 cake/console/libs/tasks/fixture.php
@@ -74,7 +74,7 @@ function __construct(&$dispatch) {
parent::__construct($dispatch);
$this->path = $this->params['working'] . DS . 'tests' . DS . 'fixtures' . DS;
if (!class_exists('CakeSchema')) {
- App::import('Model', 'CakeSchema');
+ App::import('Model', 'CakeSchema', false);
}
}
@@ -384,13 +384,13 @@ function _getRecordsFromTable($modelName, $useTable = null) {
while (!$condition) {
$condition = $this->in($prompt, null, 'WHERE 1=1 LIMIT 10');
}
- App::import('Core', 'Model');
+ App::import('Model', 'Model', false);
$modelObject =& new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
$records = $modelObject->find('all', array(
'conditions' => $condition,
'recursive' => -1
));
- $db =& $modelObject->getDataSource();
+ $db =& ConnectionManager::getDataSource($modelObject->useDbConfig);
$schema = $modelObject->schema();
$out = array();
foreach ($records as $record) {
View
7 cake/console/libs/tasks/model.php
@@ -20,7 +20,6 @@
* @since CakePHP(tm) v 1.2
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
-App::import('Model', 'ConnectionManager');
/**
* Task class for creating and updating model files.
@@ -82,7 +81,7 @@ class ModelTask extends Shell {
* @return void
**/
function startup() {
- App::import('Core', 'Model');
+ App::import('Model', 'Model', false);
parent::startup();
}
@@ -405,7 +404,7 @@ function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
} elseif ($metaData['type'] == 'integer') {
$guess = $methods['numeric'];
} elseif ($metaData['type'] == 'boolean') {
- $guess = $methods['numeric'];
+ $guess = $methods['boolean'];
} elseif ($metaData['type'] == 'datetime' || $metaData['type'] == 'date') {
$guess = $methods['date'];
} elseif ($metaData['type'] == 'time') {
@@ -912,4 +911,4 @@ function bakeFixture($className, $useTable = null) {
$this->Fixture->bake($className, $useTable);
}
}
-?>
+?>
View
12 cake/console/libs/tasks/plugin.php
@@ -60,8 +60,8 @@ function initialize() {
function execute() {
if (empty($this->params['skel'])) {
$this->params['skel'] = '';
- if (is_dir(CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS . 'templates' . DS . 'skel') === true) {
- $this->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS . 'templates' . DS . 'skel';
+ if (is_dir(CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel') === true) {
+ $this->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel';
}
}
$plugin = null;
@@ -111,7 +111,7 @@ function __interactive($plugin = null) {
}
if (!$this->bake($plugin)) {
- $this->err(sprintf(__("An error occured trying to bake: %s in %s", true), $plugin, $this->path . $pluginPath));
+ $this->err(sprintf(__("An error occured trying to bake: %s in %s", true), $plugin, $this->path . Inflector::underscore($pluginPath)));
}
}
@@ -129,7 +129,6 @@ function bake($plugin) {
if (count($pathOptions) > 1) {
$this->findPath($pathOptions);
}
-
$this->hr();
$this->out(sprintf(__("Plugin Name: %s", true), $plugin));
$this->out(sprintf(__("Plugin Directory: %s", true), $this->path . $pluginPath));
@@ -142,8 +141,9 @@ function bake($plugin) {
$Folder =& new Folder($this->path . $pluginPath);
$directories = array(
- 'config' . DS . 'sql',
+ 'config' . DS . 'schema',
'models' . DS . 'behaviors',
+ 'models' . DS . 'datasources',
'controllers' . DS . 'components',
'views' . DS . 'helpers',
'tests' . DS . 'cases' . DS . 'components',
@@ -156,7 +156,7 @@ function bake($plugin) {
'vendors' . DS . 'img',
'vendors' . DS . 'js',
'vendors' . DS . 'css',
- 'vendors' . DS . 'shells'
+ 'vendors' . DS . 'shells' . DS . 'tasks'
);
foreach ($directories as $directory) {
View
16 cake/console/libs/tasks/project.php
@@ -57,8 +57,8 @@ function execute($project = null) {
if (empty($this->params['skel'])) {
$this->params['skel'] = '';
- if (is_dir(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel') === true) {
- $this->params['skel'] = CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel';
+ if (is_dir(CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel') === true) {
+ $this->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel';
}
}
@@ -125,7 +125,6 @@ function bake($path, $skel = null, $skip = array('empty')) {
if (!$skel) {
$skel = $this->params['skel'];
}
-
while (!$skel) {
$skel = $this->in(sprintf(__("What is the path to the directory layout you wish to copy?\nExample: %s"), APP, null, ROOT . DS . 'myapp' . DS));
if ($skel == '') {
@@ -155,7 +154,7 @@ function bake($path, $skel = null, $skip = array('empty')) {
$this->out(sprintf(__("Created: %s in %s", true), $app, $path));
$this->hr();
} else {
- $this->err(" '".$app."' could not be created properly");
+ $this->err(" '" . $app . "' could not be created properly");
return false;
}
@@ -184,7 +183,8 @@ function bake($path, $skel = null, $skip = array('empty')) {
function createHome($dir) {
$app = basename($dir);
$path = $dir . 'views' . DS . 'pages' . DS;
- include(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'default'.DS.'views'.DS.'home.ctp');
+ $source = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS .'default' . DS . 'views' . DS . 'home.ctp';
+ include($source);
return $this->createFile($path.'home.ctp', $output);
}
@@ -200,7 +200,7 @@ function securitySalt($path) {
$contents = $File->read();
if (preg_match('/([\\t\\x20]*Configure::write\\(\\\'Security.salt\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
if (!class_exists('Security')) {
- uses('Security');
+ require LIBS . 'security.php';
}
$string = Security::generateAuthKey();
$result = str_replace($match[0], "\t" . 'Configure::write(\'Security.salt\', \''.$string.'\');', $contents);
@@ -224,7 +224,7 @@ function corePath($path) {
$File =& new File($path . 'webroot' . DS . 'index.php');
$contents = $File->read();
if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
- $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '".CAKE_CORE_INCLUDE_PATH."');", $contents);
+ $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '" . CAKE_CORE_INCLUDE_PATH . "');", $contents);
if (!$File->write($result)) {
return false;
}
@@ -235,7 +235,7 @@ function corePath($path) {
$File =& new File($path . 'webroot' . DS . 'test.php');
$contents = $File->read();
if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
- $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '".CAKE_CORE_INCLUDE_PATH."');", $contents);
+ $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '" . CAKE_CORE_INCLUDE_PATH . "');", $contents);
if (!$File->write($result)) {
return false;
}
View
31 cake/console/libs/tasks/template.php
@@ -52,18 +52,40 @@ function initialize() {
* @return array Array of bake themes that are installed.
**/
function _findThemes() {
- $paths = $this->Dispatch->shellPaths;
+ $paths = App::path('shells');
+ $core = array_pop($paths);
+ $core = str_replace('libs' . DS, '', $core);
+ $paths[] = $core;
+ $Folder =& new Folder($core . 'templates' . DS . 'default');
+ $contents = $Folder->read();
+ $themeFolders = $contents[0];
+
+ $plugins = App::objects('plugin');
+ foreach ($plugins as $plugin) {
+ $paths[] = $this->_pluginPath($plugin) . 'vendors' . DS . 'shells' . DS;
+ }
+
+ // TEMPORARY TODO remove when all paths are DS terminated
+ foreach ($paths as $i => $path) {
+ $paths[$i] = rtrim($path, DS) . DS;
+ }
+
$themes = array();
foreach ($paths as $path) {
$Folder =& new Folder($path . 'templates', false);
$contents = $Folder->read();
$subDirs = $contents[0];
foreach ($subDirs as $dir) {
- if (empty($dir) || $dir == 'skel') {
+ if (empty($dir) || preg_match('@^skel$|_skel$@', $dir)) {
continue;
}
- $templateDir = $path . 'templates' . DS . $dir . DS;
- $themes[$dir] = $templateDir;
+ $Folder =& new Folder($path . 'templates' . DS . $dir);
+ $contents = $Folder->read();
+ $subDirs = $contents[0];
+ if (array_intersect($contents[0], $themeFolders)) {
+ $templateDir = $path . 'templates' . DS . $dir . DS;
+ $themes[$dir] = $templateDir;
+ }
}
}
return $themes;
@@ -184,7 +206,6 @@ function _findTemplate($path, $directory, $filename) {
}
}
$this->err(sprintf(__('Could not find template for %s', true), $filename));
- $this->_stop();
return false;
}
}
View
2 cake/console/libs/tasks/test.php
@@ -268,7 +268,7 @@ function getTestableMethods($className) {
$thisMethods = array_diff($classMethods, $parentMethods);
$out = array();
foreach ($thisMethods as $method) {
- if (substr($method, 0, 1) != '_') {
+ if (substr($method, 0, 1) != '_' && $method != strtolower($className)) {
$out[] = $method;
}
}
View
107 cake/console/libs/tasks/view.php
@@ -20,7 +20,7 @@
* @since CakePHP(tm) v 1.2
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
-App::import('Core', 'Controller');
+App::import('Controller', 'Controller', false);
/**
* Task class for creating and updating view files.
@@ -103,63 +103,40 @@ function execute() {
if (empty($this->args)) {
$this->__interactive();
}
+ if (empty($this->args[0])) {
+ return;
+ }
+ if (!isset($this->connection)) {
+ $this->connection = 'default';
+ }
+ $controller = $action = $alias = null;
+ $this->controllerName = Inflector::camelize($this->args[0]);
+ $this->controllerPath = Inflector::underscore($this->controllerName);
- if (isset($this->args[0])) {
- if (!isset($this->connection)) {
- $this->connection = 'default';
- }
- $controller = $action = $alias = null;
- $this->controllerName = Inflector::camelize($this->args[0]);
- $this->controllerPath = Inflector::underscore($this->controllerName);
-
- if (isset($this->args[1])) {
- $this->template = $this->args[1];
- }
-
- if (isset($this->args[2])) {
- $action = $this->args[2];
- }
+ if (strtolower($this->args[0]) == 'all') {
+ return $this->all();
+ }
- if (!$action) {
- $action = $this->template;
- }
+ if (isset($this->args[1])) {
+ $this->template = $this->args[1];
+ }
+ if (isset($this->args[2])) {
+ $action = $this->args[2];
+ }
+ if (!$action) {
+ $action = $this->template;
+ }
+ if ($action) {
+ return $this->bake($action, true);
+ }
- if (strtolower($this->args[0]) == 'all') {
- return $this->all();
- }
+ $vars = $this->__loadController();
+ $methods = $this->_methodsToBake();
- if (in_array($action, $this->scaffoldActions)) {
- $this->bake($action, true);
- } elseif ($action) {
- $this->bake($action, true);
- } else {
- $vars = $this->__loadController();
- $methods = $this->_methodsToBake();
- $methods = array_diff(