mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +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;
|
return $vars;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -231,5 +231,4 @@ class ApiShell extends Shell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -34,9 +34,6 @@
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.console.libs
|
* @subpackage cake.cake.console.libs
|
||||||
*/
|
*/
|
||||||
if (!defined('CAKE_ADMIN')) {
|
|
||||||
define('CAKE_ADMIN', null);
|
|
||||||
}
|
|
||||||
class BakeShell extends Shell {
|
class BakeShell extends Shell {
|
||||||
|
|
||||||
var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View');
|
var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View');
|
||||||
|
|
|
@ -239,6 +239,4 @@ class ConsoleShell extends Shell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -447,7 +447,32 @@ class Shell extends Object {
|
||||||
$shortPath = str_replace('..'.DS, '', $shortPath);
|
$shortPath = str_replace('..'.DS, '', $shortPath);
|
||||||
return str_replace(DS.DS, 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
|
* creates the proper pluralize controller for the url
|
||||||
*
|
*
|
||||||
|
|
|
@ -84,6 +84,7 @@ class ControllerTask extends Shell {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function __interactive() {
|
function __interactive() {
|
||||||
|
$this->interactive = false;
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$this->out('Controller Bake:');
|
$this->out('Controller Bake:');
|
||||||
$this->hr();
|
$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');
|
$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')) {
|
if ((low($wannaDoAdmin) == 'y' || low($wannaDoAdmin) == 'yes')) {
|
||||||
$admin = $this->getAdmin();
|
$admin = $this->getAdmin();
|
||||||
|
@ -222,7 +224,6 @@ class ControllerTask extends Shell {
|
||||||
if ($baked && $this->_checkUnitTest()) {
|
if ($baked && $this->_checkUnitTest()) {
|
||||||
$this->__bakeTest($controllerName);
|
$this->__bakeTest($controllerName);
|
||||||
}
|
}
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,32 +530,6 @@ class ControllerTask extends Shell {
|
||||||
|
|
||||||
return $controllerName;
|
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
|
* Displays help contents
|
||||||
*
|
*
|
||||||
|
@ -573,3 +548,4 @@ class ControllerTask extends Shell {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
?>
|
|
@ -243,11 +243,12 @@ class ProjectTask extends Shell {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function cakeAdmin($name) {
|
function cakeAdmin($name) {
|
||||||
$File =& new File($path . 'webroot' . DS . 'index.php');
|
$File =& new File(CONFIGS . 'core.php');
|
||||||
$contents = $File->read();
|
$contents = $File->read();
|
||||||
if (preg_match('%([/\\t\\x20]*define\\(\'CAKE_ADMIN\',[\\t\\x20\'a-z]*\\);)%', $contents, $match)) {
|
if (preg_match('%([/\\t\\x20]*define\\(\'CAKE_ADMIN\',[\\t\\x20\'a-z]*\\);)%', $contents, $match)) {
|
||||||
$result = str_replace($match[0], 'define(\'CAKE_ADMIN\', \''.$name.'\');', $contents);
|
$result = str_replace($match[0], 'define(\'CAKE_ADMIN\', \''.$name.'\');', $contents);
|
||||||
if ($File->write($result)) {
|
if ($File->write($result)) {
|
||||||
|
define('CAKE_ADMIN', $name);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -79,11 +79,10 @@ class ViewTask extends Shell {
|
||||||
$this->__interactive();
|
$this->__interactive();
|
||||||
}
|
}
|
||||||
|
|
||||||
$controller = $action = $alias = null;
|
|
||||||
if (isset($this->args[0])) {
|
if (isset($this->args[0])) {
|
||||||
|
$controller = $action = $alias = null;
|
||||||
$this->controllerName = Inflector::camelize($this->args[0]);
|
$this->controllerName = Inflector::camelize($this->args[0]);
|
||||||
$this->controllerPath = Inflector::underscore($this->controllerName);
|
$this->controllerPath = Inflector::underscore($this->controllerName);
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->args[1])) {
|
if (isset($this->args[1])) {
|
||||||
$this->template = $this->args[1];
|
$this->template = $this->args[1];
|
||||||
|
@ -115,8 +114,13 @@ class ViewTask extends Shell {
|
||||||
} else {
|
} else {
|
||||||
$methods = get_class_methods($this->controllerName . 'Controller');
|
$methods = get_class_methods($this->controllerName . 'Controller');
|
||||||
}
|
}
|
||||||
|
$adminDelete = null;
|
||||||
|
|
||||||
|
if (defined('CAKE_ADMIN')) {
|
||||||
|
$adminDelete = CAKE_ADMIN.'_delete';
|
||||||
|
}
|
||||||
foreach ($methods as $method) {
|
foreach ($methods as $method) {
|
||||||
if ($method{0} != '_' && !in_array(low($method), am($protected, array('delete', CAKE_ADMIN.'_delete')))) {
|
if ($method{0} != '_' && !in_array(low($method), am($protected, array('delete', $adminDelete)))) {
|
||||||
$content = $this->getContent($method, $vars);
|
$content = $this->getContent($method, $vars);
|
||||||
$this->bake($method, $content);
|
$this->bake($method, $content);
|
||||||
}
|
}
|
||||||
|
@ -124,6 +128,7 @@ class ViewTask extends Shell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Handles interactive baking
|
* Handles interactive baking
|
||||||
*
|
*
|
||||||
|
@ -136,6 +141,7 @@ class ViewTask extends Shell {
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$wannaDoAdmin = 'n';
|
$wannaDoAdmin = 'n';
|
||||||
$wannaDoScaffold = 'y';
|
$wannaDoScaffold = 'y';
|
||||||
|
$this->interactive = false;
|
||||||
|
|
||||||
$this->controllerName = $this->Controller->getName();
|
$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');
|
$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') {
|
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');
|
$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') {
|
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
|
||||||
$wannaDoAdmin = $this->in("Would you like to create the views for admin routing?", array('y','n'), 'y');
|
$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 ((low($wannaDoAdmin) == 'y' || low($wannaDoAdmin) == 'yes')) {
|
||||||
if (defined('CAKE_ADMIN')) {
|
$admin = $this->getAdmin();
|
||||||
$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 . '_';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
|
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
|
||||||
$file = CONTROLLERS . $this->controllerPath . '_controller.php';
|
$file = CONTROLLERS . $this->controllerPath . '_controller.php';
|
||||||
|
|
||||||
|
@ -180,6 +172,7 @@ class ViewTask extends Shell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$vars = $this->__loadController();
|
$vars = $this->__loadController();
|
||||||
|
|
||||||
if ($vars) {
|
if ($vars) {
|
||||||
foreach ($this->scaffoldActions as $action) {
|
foreach ($this->scaffoldActions as $action) {
|
||||||
$content = $this->getContent($action, $vars);
|
$content = $this->getContent($action, $vars);
|
||||||
|
@ -230,7 +223,7 @@ class ViewTask extends Shell {
|
||||||
$this->err('could not find the controller');
|
$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';
|
$file = CONTROLLERS . $this->controllerPath . '_controller.php';
|
||||||
$shortPath = $this->shortPath($file);
|
$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.");
|
$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;
|
$action = $template;
|
||||||
|
|
||||||
if (strpos($template, CAKE_ADMIN) !== false) {
|
if (defined('CAKE_ADMIN') && strpos($template, CAKE_ADMIN) !== false) {
|
||||||
$template = str_replace(CAKE_ADMIN.'_', '', $template);
|
$template = str_replace(CAKE_ADMIN.'_', '', $template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,3 +339,4 @@ class ViewTask extends Shell {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
?>
|
Loading…
Add table
Reference in a new issue