mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
updating shell, fixes #4540 where shell name and model are the same
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6738 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f8f1380bcd
commit
f6a78538ff
2 changed files with 40 additions and 25 deletions
|
@ -188,10 +188,10 @@ class ShellDispatcher {
|
|||
$this->shiftArgs();
|
||||
|
||||
$this->shellPaths = array(
|
||||
APP . 'vendors' . DS . 'shells' . DS,
|
||||
VENDORS . 'shells' . DS,
|
||||
CONSOLE_LIBS
|
||||
);
|
||||
APP . 'vendors' . DS . 'shells' . DS,
|
||||
VENDORS . 'shells' . DS,
|
||||
CONSOLE_LIBS
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Initializes the environment and loads the Cake core.
|
||||
|
@ -213,7 +213,8 @@ class ShellDispatcher {
|
|||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'inflector.php',
|
||||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'configure.php',
|
||||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'cache.php',
|
||||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'string.php'
|
||||
CORE_PATH . 'cake' . DS . 'libs' . DS . 'string.php',
|
||||
CORE_PATH . 'cake' . DS . 'console' . DS . 'error.php'
|
||||
);
|
||||
|
||||
foreach ($includes as $inc) {
|
||||
|
@ -303,7 +304,7 @@ class ShellDispatcher {
|
|||
$shell->loadTasks();
|
||||
|
||||
foreach ($shell->taskNames as $task) {
|
||||
if (get_parent_class($shell->{$task}) == 'Shell') {
|
||||
if (strtolower(get_parent_class($shell)) == 'shell') {
|
||||
$shell->{$task}->initialize();
|
||||
$shell->{$task}->loadTasks();
|
||||
}
|
||||
|
@ -337,12 +338,14 @@ class ShellDispatcher {
|
|||
$missingCommand = true;
|
||||
}
|
||||
|
||||
$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'
|
||||
);
|
||||
$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'
|
||||
);
|
||||
|
||||
if (in_array(strtolower($command), $protectedCommands)) {
|
||||
$missingCommand = true;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
require_once CAKE . 'console' . DS . 'error.php';
|
||||
/**
|
||||
* Base class for command-line utilities for automating programmer chores.
|
||||
*
|
||||
|
@ -124,7 +123,7 @@ class Shell extends Object {
|
|||
*
|
||||
*/
|
||||
function __construct(&$dispatch) {
|
||||
$vars = array('params', 'args', 'shell', 'shellName'=> 'name', 'shellClass'=> 'className', 'shellCommand'=> 'command');
|
||||
$vars = array('params', 'args', 'shell', 'shellCommand'=> 'command');
|
||||
foreach ($vars as $key => $var) {
|
||||
if (is_string($key)) {
|
||||
$this->{$var} =& $dispatch->{$key};
|
||||
|
@ -133,15 +132,25 @@ class Shell extends Object {
|
|||
}
|
||||
}
|
||||
|
||||
$shellKey = Inflector::underscore($this->name);
|
||||
$this->className = get_class($this);
|
||||
|
||||
if ($this->name == null) {
|
||||
$this->name = str_replace(array('shell', 'Shell', 'task', 'Task'), '', $this->className);
|
||||
}
|
||||
|
||||
$shellKey = Inflector::underscore($this->className);
|
||||
ClassRegistry::addObject($shellKey, $this);
|
||||
ClassRegistry::map($shellKey, $shellKey);
|
||||
if (!PHP5 && isset($this->args[0]) && strpos(low(get_class($this)), low(Inflector::camelize($this->args[0]))) !== false) {
|
||||
$dispatch->shiftArgs();
|
||||
}
|
||||
if (!PHP5 && isset($this->args[0]) && low($this->command) == low(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) {
|
||||
$dispatch->shiftArgs();
|
||||
|
||||
if (!PHP5 && isset($this->args[0])) {
|
||||
if(strpos($this->className, low(Inflector::camelize($this->args[0]))) !== false) {
|
||||
$dispatch->shiftArgs();
|
||||
}
|
||||
if (low($this->command) == low(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) {
|
||||
$dispatch->shiftArgs();
|
||||
}
|
||||
}
|
||||
|
||||
$this->Dispatch =& $dispatch;
|
||||
}
|
||||
/**
|
||||
|
@ -204,9 +213,9 @@ class Shell extends Object {
|
|||
return;
|
||||
}
|
||||
|
||||
uses ('model'.DS.'connection_manager',
|
||||
'model'.DS.'datasources'.DS.'dbo_source', 'model'.DS.'model'
|
||||
);
|
||||
App::import(array(
|
||||
'model'.DS.'connection_manager', 'model'.DS.'datasources'.DS.'dbo_source', 'model'.DS.'model'
|
||||
));
|
||||
|
||||
if ($this->uses === true && App::import('Model', 'AppModel')) {
|
||||
$this->AppModel =& new AppModel(false, false, false);
|
||||
|
@ -247,11 +256,13 @@ class Shell extends Object {
|
|||
}
|
||||
|
||||
foreach ($tasks as $taskName) {
|
||||
$taskKey = Inflector::underscore($taskName);
|
||||
$task = Inflector::underscore($taskName);
|
||||
$taskClass = Inflector::camelize($taskName.'Task');
|
||||
$taskKey = Inflector::underscore($taskClass);
|
||||
|
||||
if (!class_exists($taskClass)) {
|
||||
foreach ($this->Dispatch->shellPaths as $path) {
|
||||
$taskPath = $path . 'tasks' . DS . Inflector::underscore($taskName).'.php';
|
||||
$taskPath = $path . 'tasks' . DS . $task.'.php';
|
||||
if (file_exists($taskPath)) {
|
||||
require_once $taskPath;
|
||||
break;
|
||||
|
@ -268,6 +279,7 @@ class Shell extends Object {
|
|||
ClassRegistry::map($taskName, $taskKey);
|
||||
}
|
||||
} else {
|
||||
|
||||
$this->taskNames[] = $taskName;
|
||||
if (!PHP5) {
|
||||
$this->{$taskName} =& new $taskClass($this->Dispatch);
|
||||
|
|
Loading…
Reference in a new issue