From 9b39236117cf117b9e46f95b76f127b26ed0bb15 Mon Sep 17 00:00:00 2001 From: gwoo Date: Sat, 12 May 2007 23:40:37 +0000 Subject: [PATCH] updating paths for shell, bake git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5063 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/console/cake.php | 20 +++++++++++++------- cake/console/libs/bake.php | 24 ++++++++++++++++++++++-- cake/console/libs/shell.php | 8 ++++---- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/cake/console/cake.php b/cake/console/cake.php index 810dddba6..cf56508fc 100644 --- a/cake/console/cake.php +++ b/cake/console/cake.php @@ -148,7 +148,7 @@ class ShellDispatcher { $this->stdin = fopen('php://stdin', 'r'); $this->stdout = fopen('php://stdout', 'w'); $this->stderr = fopen('php://stderr', 'w'); - + if (!isset($this->args[0]) || !isset($this->params['working'])) { $this->stdout("\nCakePHP Console: "); $this->stdout('This file has been loaded incorrectly and cannot continue.'); @@ -157,7 +157,7 @@ class ShellDispatcher { $this->stdout('(http://manual.cakephp.org/)'); exit(); } - + if (basename(__FILE__) != basename($this->args[0])) { $this->stdout("\nCakePHP Console: "); $this->stdout('Warning: the dispatcher may have been loaded incorrectly, which could lead to unexpected results...'); @@ -232,7 +232,7 @@ class ShellDispatcher { */ function dispatch() { $this->stdout("\nWelcome to CakePHP v" . Configure::version() . " Console"); - + if (!isset($this->args[0]) || (isset($this->args[0]) && $this->args[0] != 'help')) { $this->stdout("Type 'cake help' for help\n"); } @@ -396,10 +396,16 @@ class ShellDispatcher { $app = $this->params['app']; } } - if(in_array($app, array('cake', 'console', 'app'))){ + + if(empty($this->params['app']) && in_array($app, array('cake', 'console', 'app'))){ $app = 'app'; $this->params['working'] = dirname(dirname(__FILE__)); } + + if($this->params['working'] !== dirname(dirname(__FILE__))) { + $this->params['root'] = $this->params['working']; + } + $this->params = array_merge(array('app'=> $app, 'root'=> dirname($this->params['working'])), $this->params); } /** @@ -426,7 +432,7 @@ class ShellDispatcher { $this->stdout(" -root: " . ROOT); $this->stdout(" -app: ". APP); $this->stdout(" -core: " . CORE_PATH); - + $this->stdout("\nAvailable Scripts:"); foreach($this->shellPaths as $path) { if(is_dir($path)) { @@ -440,9 +446,9 @@ class ShellDispatcher { if ($shell != 'shell.php') { $this->stdout("\t - " . r('.php', '', $shell)); } - } + } } - } + } } $this->stdout("\nTo run a command, type 'cake script_name [args]'"); $this->stdout("To get help on a specific command, type 'cake script_name help'"); diff --git a/cake/console/libs/bake.php b/cake/console/libs/bake.php index 18264b47f..43d60393d 100644 --- a/cake/console/libs/bake.php +++ b/cake/console/libs/bake.php @@ -71,7 +71,7 @@ class BakeShell extends Shell { $this->hr(); if(!is_dir(CONFIGS)) { - $this->project($this->params['working']); + $this->project($this->params['app']); } if(!config('database')) { @@ -1858,6 +1858,11 @@ class BakeShell extends Shell { } else { $this->out('Unable to generate random hash for CAKE_SESSION_STRING, please change this yourself in ' . CONFIGS . 'core.php'); } + if($this->__setCake() === true ){ + $this->out('CAKE_CORE_INCLUDE_PATH set to ' . CAKE_CORE_INCLUDE_PATH); + } else { + $this->out('Unable to to set CAKE_CORE_INCLUDE_PATH, please change this yourself in ' . WWW_ROOT . 'index.php'); + } if(chmodr($projectPath.DS.'tmp', 0777) === false) { $this->out('Could not set permissions on '. $projectPath.DS.'tmp'.DS.'*'); $this->out('You must manually check that these directories can be wrote to by the server'); @@ -1956,7 +1961,8 @@ class BakeShell extends Shell { return false; } } - function __generateHash(){ + + function __generateHash(){ $file = file_get_contents(CONFIGS.'core.php'); if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_SESSION_STRING\\\',[\\t\\x20\'A-z0-9]*\\);)/', $file, $match)) { uses('Security'); @@ -1972,6 +1978,20 @@ class BakeShell extends Shell { return false; } } + + function __setCake(){ + $file = file_get_contents(APP.'webroot'.DS.'index.php'); + if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $file, $match)) { + $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '".CAKE_CORE_INCLUDE_PATH."');", $file); + if(file_put_contents(APP.'webroot'.DS.'index.php', $result)){ + return true; + } else { + return false; + } + } else { + return false; + } + } /** * Outputs an ASCII art banner to standard output. * diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index 200a51e0c..333c0f49a 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -71,10 +71,10 @@ class Shell extends Object { */ function __construct(&$dispatch) { $this->Dispatch = & $dispatch; - $this->params = & $this->Dispatch->params; - $this->args = & $this->Dispatch->args; - $this->name = & $this->Dispatch->shellName; - $this->command = & $this->Dispatch->shellCommand; + $vars = array('params', 'args', 'shellName', 'shellCommand'); + foreach($vars as $var) { + $this->{$var} = & $this->Dispatch->{$var}; + } } /** * Initializes the Shell