mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixing console scripts.
Correcting errors when using bake shell to create views. Corrected errors when interactively creating controllers and views Corrected issue in ProjectTask::cakeAdmin() with admin route not writing the admin define in core.php Moved ControllerTask::getAdmin() to Shell::getAdmin() Removed define setting CAKE_ADMIN to null which would cause issues with admin methods and views Corrected missing ?> git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5322 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
9d56c4616e
commit
172f9817cb
8 changed files with 92 additions and 103 deletions
|
@ -473,5 +473,4 @@ class AclShell extends Shell {
|
|||
return $vars;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -231,5 +231,4 @@ class ApiShell extends Shell {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -34,9 +34,6 @@
|
|||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
*/
|
||||
if (!defined('CAKE_ADMIN')) {
|
||||
define('CAKE_ADMIN', null);
|
||||
}
|
||||
class BakeShell extends Shell {
|
||||
|
||||
var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View');
|
||||
|
@ -79,7 +76,7 @@ class BakeShell extends Shell {
|
|||
* Displays help contents
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
*/
|
||||
function help() {
|
||||
$this->out('CakePHP Bake:');
|
||||
$this->hr();
|
||||
|
@ -100,7 +97,7 @@ class BakeShell extends Shell {
|
|||
$this->out("\n\tbake view\n\t\tbakes views. run 'bake view help' for more info");
|
||||
$this->out("\n\tbake controller\n\t\tbakes a controller. run 'bake controller help' for more info");
|
||||
$this->out("");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -96,7 +96,7 @@ class ConsoleShell extends Shell {
|
|||
$data = strip_tags($data);
|
||||
$data = str_replace($this->badCommandChars, "", $data);
|
||||
}
|
||||
|
||||
|
||||
$modelA = $tmp[1];
|
||||
$association = $tmp[2];
|
||||
$modelB = $tmp[3];
|
||||
|
@ -113,11 +113,11 @@ class ConsoleShell extends Shell {
|
|||
$data = strip_tags($data);
|
||||
$data = str_replace($this->badCommandChars, "", $data);
|
||||
}
|
||||
|
||||
|
||||
$modelA = $tmp[1];
|
||||
$association = $tmp[2];
|
||||
$modelB = $tmp[3];
|
||||
|
||||
|
||||
// Verify that there is actually an association to unbind
|
||||
$currentAssociations = $this->{$modelA}->getAssociated();
|
||||
$validCurrentAssociation = false;
|
||||
|
@ -142,8 +142,8 @@ class ConsoleShell extends Shell {
|
|||
|
||||
// Do we have a valid model?
|
||||
list($modelToCheck, $tmp) = explode('->', $command);
|
||||
|
||||
if ($this->isValidModel($modelToCheck)) {
|
||||
|
||||
if ($this->isValidModel($modelToCheck)) {
|
||||
$findCommand = "\$data = \$this->$command;";
|
||||
@eval($findCommand);
|
||||
|
||||
|
@ -194,7 +194,7 @@ class ConsoleShell extends Shell {
|
|||
$command = strip_tags($command);
|
||||
$command = str_replace($this->badCommandChars, "", $command);
|
||||
list($modelToSave, $tmp) = explode("->", $command);
|
||||
|
||||
|
||||
if ($this->isValidModel($modelToSave)) {
|
||||
// Extract the array of data we are trying to build
|
||||
list($foo, $data) = explode("->save", $command);
|
||||
|
@ -208,7 +208,7 @@ class ConsoleShell extends Shell {
|
|||
break;
|
||||
case (preg_match("/^(\w+) columns/", $command, $tmp) == true):
|
||||
$modelToCheck = strip_tags(str_replace($this->badCommandChars, "", $tmp[1]));
|
||||
|
||||
|
||||
if ($this->isValidModel($modelToCheck)) {
|
||||
// Get the column info for this model
|
||||
$fieldsCommand = "\$data = \$this->{$modelToCheck}->getColumnTypes();";
|
||||
|
@ -239,6 +239,4 @@ class ConsoleShell extends Shell {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
?>
|
|
@ -127,7 +127,7 @@ class Shell extends Object {
|
|||
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();
|
||||
}
|
||||
|
@ -447,7 +447,32 @@ class Shell extends Object {
|
|||
$shortPath = str_replace('..'.DS, '', $shortPath);
|
||||
return str_replace(DS.DS, DS, $shortPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for CAKE_ADMIN and Forces user to input it if not enabled
|
||||
*
|
||||
* @return the controller name
|
||||
*/
|
||||
function getAdmin() {
|
||||
$admin = null;
|
||||
if (defined('CAKE_ADMIN')) {
|
||||
$admin = CAKE_ADMIN.'_';
|
||||
} else {
|
||||
$this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
|
||||
$this->out('What would you like the admin route to be?');
|
||||
$this->out('Example: www.example.com/admin/controller');
|
||||
while ($admin == '') {
|
||||
$admin = $this->in("What would you like the admin route to be?", null, 'admin');
|
||||
}
|
||||
if ($this->Project->cakeAdmin($admin) !== true) {
|
||||
$this->out('Unable to write to /app/config/core.php.');
|
||||
$this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
|
||||
exit();
|
||||
} else {
|
||||
$admin = $admin . '_';
|
||||
}
|
||||
}
|
||||
return $admin;
|
||||
}
|
||||
/**
|
||||
* creates the proper pluralize controller for the url
|
||||
*
|
||||
|
|
|
@ -84,6 +84,7 @@ class ControllerTask extends Shell {
|
|||
* @return void
|
||||
*/
|
||||
function __interactive() {
|
||||
$this->interactive = false;
|
||||
$this->hr();
|
||||
$this->out('Controller Bake:');
|
||||
$this->hr();
|
||||
|
@ -148,6 +149,7 @@ class ControllerTask extends Shell {
|
|||
$wannaDoAdmin = $this->in("Would you like to create the methods for admin routing?", array('y','n'), 'y');
|
||||
}
|
||||
}
|
||||
$admin = false;
|
||||
|
||||
if ((low($wannaDoAdmin) == 'y' || low($wannaDoAdmin) == 'yes')) {
|
||||
$admin = $this->getAdmin();
|
||||
|
@ -222,7 +224,6 @@ class ControllerTask extends Shell {
|
|||
if ($baked && $this->_checkUnitTest()) {
|
||||
$this->__bakeTest($controllerName);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -529,32 +530,6 @@ class ControllerTask extends Shell {
|
|||
|
||||
return $controllerName;
|
||||
}
|
||||
/**
|
||||
* Checks for CAKE_ADMIN and Forces user to input it if not enabled
|
||||
*
|
||||
* @return the controller name
|
||||
*/
|
||||
function getAdmin() {
|
||||
$admin = null;
|
||||
if (defined('CAKE_ADMIN')) {
|
||||
$admin = CAKE_ADMIN.'_';
|
||||
} else {
|
||||
$this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
|
||||
$this->out('What would you like the admin route to be?');
|
||||
$this->out('Example: www.example.com/admin/controller');
|
||||
while ($admin == '') {
|
||||
$admin = $this->in("What would you like the admin route to be?", null, 'admin');
|
||||
}
|
||||
if ($this->Project->cakeAdmin($admin) !== true) {
|
||||
$this->out('Unable to write to /app/config/core.php.');
|
||||
$this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
|
||||
exit();
|
||||
} else {
|
||||
$admin = $admin . '_';
|
||||
}
|
||||
}
|
||||
return $admin;
|
||||
}
|
||||
/**
|
||||
* Displays help contents
|
||||
*
|
||||
|
@ -571,5 +546,6 @@ class ControllerTask extends Shell {
|
|||
$this->out("\n\tcontroller <name> null admin\n\t\tbakes a controller with scaffold actions for CAKE_ADMIN");
|
||||
$this->out("");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -241,13 +241,14 @@ class ProjectTask extends Shell {
|
|||
* Enables CAKE_ADMIN in /app/config/core.php
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
*/
|
||||
function cakeAdmin($name) {
|
||||
$File =& new File($path . 'webroot' . DS . 'index.php');
|
||||
$File =& new File(CONFIGS . 'core.php');
|
||||
$contents = $File->read();
|
||||
if (preg_match('%([/\\t\\x20]*define\\(\'CAKE_ADMIN\',[\\t\\x20\'a-z]*\\);)%', $contents, $match)) {
|
||||
$result = str_replace($match[0], 'define(\'CAKE_ADMIN\', \''.$name.'\');', $contents);
|
||||
if ($File->write($result)) {
|
||||
define('CAKE_ADMIN', $name);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -79,46 +79,51 @@ class ViewTask extends Shell {
|
|||
$this->__interactive();
|
||||
}
|
||||
|
||||
$controller = $action = $alias = null;
|
||||
if (isset($this->args[0])) {
|
||||
$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[1])) {
|
||||
$this->template = $this->args[1];
|
||||
}
|
||||
|
||||
if (isset($this->args[2])) {
|
||||
$action = $this->args[2];
|
||||
}
|
||||
if (isset($this->args[2])) {
|
||||
$action = $this->args[2];
|
||||
}
|
||||
|
||||
if (!$action) {
|
||||
$action = $this->template;
|
||||
}
|
||||
if (!$action) {
|
||||
$action = $this->template;
|
||||
}
|
||||
|
||||
if (in_array($action, $this->scaffoldActions)) {
|
||||
$this->bake($action, true);
|
||||
} elseif ($action) {
|
||||
$this->bake($action, true);
|
||||
} else {
|
||||
$vars = $this->__loadController();
|
||||
if ($vars) {
|
||||
$protected = array( 'object', low($this->controllerName. 'Controller'), 'controller', 'appcontroller',
|
||||
'tostring', 'requestaction', 'log', 'cakeerror', 'constructclasses', 'redirect', 'set', 'setaction',
|
||||
'validate', 'validateerrors', 'render', 'referer', 'flash', 'flashout', 'generatefieldnames',
|
||||
'postconditions', 'cleanupfields', 'beforefilter', 'beforerender', 'afterfilter', 'disablecache', 'paginate');
|
||||
if (in_array($action, $this->scaffoldActions)) {
|
||||
$this->bake($action, true);
|
||||
} elseif ($action) {
|
||||
$this->bake($action, true);
|
||||
} else {
|
||||
$vars = $this->__loadController();
|
||||
if ($vars) {
|
||||
$protected = array( 'object', low($this->controllerName. 'Controller'), 'controller', 'appcontroller',
|
||||
'tostring', 'requestaction', 'log', 'cakeerror', 'constructclasses', 'redirect', 'set', 'setaction',
|
||||
'validate', 'validateerrors', 'render', 'referer', 'flash', 'flashout', 'generatefieldnames',
|
||||
'postconditions', 'cleanupfields', 'beforefilter', 'beforerender', 'afterfilter', 'disablecache', 'paginate');
|
||||
|
||||
$classVars = get_class_vars($this->controllerName . 'Controller');
|
||||
if (array_key_exists('scaffold', $classVars)) {
|
||||
$methods = $this->scaffoldActions;
|
||||
} else {
|
||||
$methods = get_class_methods($this->controllerName . 'Controller');
|
||||
}
|
||||
foreach ($methods as $method) {
|
||||
if ($method{0} != '_' && !in_array(low($method), am($protected, array('delete', CAKE_ADMIN.'_delete')))) {
|
||||
$content = $this->getContent($method, $vars);
|
||||
$this->bake($method, $content);
|
||||
$classVars = get_class_vars($this->controllerName . 'Controller');
|
||||
if (array_key_exists('scaffold', $classVars)) {
|
||||
$methods = $this->scaffoldActions;
|
||||
} else {
|
||||
$methods = get_class_methods($this->controllerName . 'Controller');
|
||||
}
|
||||
$adminDelete = null;
|
||||
|
||||
if (defined('CAKE_ADMIN')) {
|
||||
$adminDelete = CAKE_ADMIN.'_delete';
|
||||
}
|
||||
foreach ($methods as $method) {
|
||||
if ($method{0} != '_' && !in_array(low($method), am($protected, array('delete', $adminDelete)))) {
|
||||
$content = $this->getContent($method, $vars);
|
||||
$this->bake($method, $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,6 +141,7 @@ class ViewTask extends Shell {
|
|||
$this->hr();
|
||||
$wannaDoAdmin = 'n';
|
||||
$wannaDoScaffold = 'y';
|
||||
$this->interactive = false;
|
||||
|
||||
$this->controllerName = $this->Controller->getName();
|
||||
|
||||
|
@ -144,33 +150,19 @@ class ViewTask extends Shell {
|
|||
$interactive = $this->in("Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite {$this->controllerName} views if it exist.", array('y','n'), 'y');
|
||||
|
||||
if (low($interactive) == 'y' || low($interactive) == 'yes') {
|
||||
$this->interactive = true;
|
||||
$wannaDoScaffold = $this->in("Would you like to create some scaffolded views (index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller and model classes (including associated models).", array('y','n'), 'n');
|
||||
}
|
||||
|
||||
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
|
||||
$wannaDoAdmin = $this->in("Would you like to create the views for admin routing?", array('y','n'), 'y');
|
||||
}
|
||||
$admin = false;
|
||||
|
||||
$admin = '';
|
||||
if ((low($wannaDoAdmin) == 'y' || low($wannaDoAdmin) == 'yes')) {
|
||||
if (defined('CAKE_ADMIN')) {
|
||||
$admin = CAKE_ADMIN . '_';
|
||||
} else {
|
||||
$this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
|
||||
$this->out('What would you like the admin route to be?');
|
||||
$this->out('Example: www.example.com/admin/controller');
|
||||
while ($admin == '') {
|
||||
$admin = $this->in("What would you like the admin route to be?", null, 'admin');
|
||||
}
|
||||
if ($this->Project->cakeAdmin($admin) !== true) {
|
||||
$this->err('Unable to write to /app/config/core.php.');
|
||||
$this->err('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
|
||||
exit();
|
||||
} else {
|
||||
$admin = $admin . '_';
|
||||
}
|
||||
}
|
||||
$admin = $this->getAdmin();
|
||||
}
|
||||
|
||||
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
|
||||
$file = CONTROLLERS . $this->controllerPath . '_controller.php';
|
||||
|
||||
|
@ -180,6 +172,7 @@ class ViewTask extends Shell {
|
|||
}
|
||||
}
|
||||
$vars = $this->__loadController();
|
||||
|
||||
if ($vars) {
|
||||
foreach ($this->scaffoldActions as $action) {
|
||||
$content = $this->getContent($action, $vars);
|
||||
|
@ -230,7 +223,7 @@ class ViewTask extends Shell {
|
|||
$this->err('could not find the controller');
|
||||
}
|
||||
|
||||
if (!loadController($this->controllerName)) {
|
||||
if (!class_exists($this->controllerName . 'Controller') && !loadController($this->controllerName)) {
|
||||
$file = CONTROLLERS . $this->controllerPath . '_controller.php';
|
||||
$shortPath = $this->shortPath($file);
|
||||
$this->err("The file '{$shortPath}' could not be found.\nIn order to bake a view, you'll need to first create the controller.");
|
||||
|
@ -297,7 +290,7 @@ class ViewTask extends Shell {
|
|||
}
|
||||
$action = $template;
|
||||
|
||||
if (strpos($template, CAKE_ADMIN) !== false) {
|
||||
if (defined('CAKE_ADMIN') && strpos($template, CAKE_ADMIN) !== false) {
|
||||
$template = str_replace(CAKE_ADMIN.'_', '', $template);
|
||||
}
|
||||
|
||||
|
@ -345,4 +338,5 @@ class ViewTask extends Shell {
|
|||
$this->out("");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue