updating console params, schema, db acl schema, and deprecated api shell initidb in favor or cake schema run create -name DbAcl, closes #3566

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6073 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-11-24 23:12:57 +00:00
parent 548eeefdd0
commit caefdbb6d7
6 changed files with 110 additions and 102 deletions

View file

@ -1,6 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/*DbAcl schema generated on: 2007-11-23 10:11:16 : 1195843096*/
/*DbAcl schema generated on: 2007-11-24 15:11:13 : 1195945453*/
class DbAclSchema extends CakeSchema {
@ -17,9 +17,9 @@ class DbAclSchema extends CakeSchema {
var $acos = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary', 'extra' => 'auto_increment'),
'parent_id' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'model' => array('type'=>'string', 'null' => true, 'default' => ''),
'model' => array('type'=>'string', 'null' => true),
'foreign_key' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'alias' => array('type'=>'string', 'null' => true, 'default' => ''),
'alias' => array('type'=>'string', 'null' => true),
'lft' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'rght' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
@ -28,9 +28,9 @@ class DbAclSchema extends CakeSchema {
var $aros = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary', 'extra' => 'auto_increment'),
'parent_id' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'model' => array('type'=>'string', 'null' => true, 'default' => ''),
'model' => array('type'=>'string', 'null' => true),
'foreign_key' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'alias' => array('type'=>'string', 'null' => true, 'default' => ''),
'alias' => array('type'=>'string', 'null' => true),
'lft' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'rght' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
@ -38,8 +38,8 @@ class DbAclSchema extends CakeSchema {
var $aros_acos = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary', 'extra' => 'auto_increment'),
'aro_id' => array('type'=>'integer', 'null' => false, 'default' => '', 'length' => 10, 'key' => 'index'),
'aco_id' => array('type'=>'integer', 'null' => false, 'default' => '', 'length' => 10),
'aro_id' => array('type'=>'integer', 'null' => false, 'length' => 10, 'key' => 'index'),
'aco_id' => array('type'=>'integer', 'null' => false, 'length' => 10),
'_create' => array('type'=>'string', 'null' => false, 'default' => '0', 'length' => 2),
'_read' => array('type'=>'string', 'null' => false, 'default' => '0', 'length' => 2),
'_update' => array('type'=>'string', 'null' => false, 'default' => '0', 'length' => 2),

View file

@ -403,19 +403,7 @@ class ShellDispatcher {
* @access public
*/
function parseParams($params) {
$out = array();
for ($i = 0; $i < count($params); $i++) {
if (strpos($params[$i], '-') === 0) {
$key = substr($params[$i], 1);
$value = true;
if(isset($params[++$i])) {
$value = str_replace('"', '', $params[$i]);
}
$this->params[$key] = $value;
} else {
$this->args[] = $params[$i];
}
}
$this->__parseParams($params);
$app = 'app';
$root = dirname(dirname(dirname(__FILE__)));
@ -442,6 +430,36 @@ class ShellDispatcher {
$this->params = array_merge($this->params, array('app'=> $app, 'root'=> $root, 'working'=> $working));
}
/**
* Helper for recursively paraing params
*
* @return array params
* @access private
*/
function __parseParams($params) {
$count = count($params);
for ($i = 0; $i < $count; $i++) {
if(isset($params[$i])) {
if ($params[$i]{0} === '-') {
$key = substr($params[$i], 1);
$this->params[$key] = true;
unset($params[$i]);
if(isset($params[++$i])) {
if ($params[$i]{0} !== '-') {
$this->params[$key] = str_replace('"', '', $params[$i]);
unset($params[$i]);
} else {
$i--;
$this->__parseParams($params);
}
}
} else {
$this->args[] = $params[$i];
unset($params[$i]);
}
}
}
}
/**
* Removes first argument and shifts other arguments up
*
@ -476,7 +494,7 @@ class ShellDispatcher {
$this->stdout("\nAvailable Shells:");
foreach ($this->shellPaths as $path) {
if (is_dir($path)) {
$shells = listClasses($path);
$shells = Configure::listObjects('file', $path);
$path = r(CORE_PATH, '', $path);
$this->stdout("\n " . $path . ":");
if (empty($shells)) {

View file

@ -319,54 +319,7 @@ class AclShell extends Shell {
* @access public
*/
function initdb() {
$db =& ConnectionManager::getDataSource($this->dataSource);
$this->out(__("Initializing Database...", true), true);
$this->out(__("Creating access control objects table (acos)...", true), true);
$sql = " CREATE TABLE ".$db->fullTableName('acos')." (
".$db->name('id')." ".$db->column($db->columns['primary_key']).",
".$db->name('parent_id')." ".$db->column($db->columns['integer'])." default NULL,
".$db->name('model')." ".$db->column($db->columns['string'])." default '',
".$db->name('foreign_key')." ".$db->column($db->columns['integer'])." default NULL,
".$db->name('alias')." ".$db->column($db->columns['string'])." default '',
".$db->name('lft')." ".$db->column($db->columns['integer'])." default NULL,
".$db->name('rght')." ".$db->column($db->columns['integer'])." default NULL,
PRIMARY KEY (".$db->name('id').")
)";
if ($db->query($sql) === false) {
die("Error: " . $db->lastError() . "\n\n");
}
$this->out(__("Creating access request objects table (aros)...", true), true);
$sql2 = "CREATE TABLE ".$db->fullTableName('aros')." (
".$db->name('id')." ".$db->column($db->columns['primary_key']).",
".$db->name('parent_id')." ".$db->column($db->columns['integer'])." default NULL,
".$db->name('model')." ".$db->column($db->columns['string'])." default '',
".$db->name('foreign_key')." ".$db->column($db->columns['integer'])." default NULL,
".$db->name('alias')." ".$db->column($db->columns['string'])." default '',
".$db->name('lft')." ".$db->column($db->columns['integer'])." default NULL,
".$db->name('rght')." ".$db->column($db->columns['integer'])." default NULL,
PRIMARY KEY (".$db->name('id').")
)";
if ($db->query($sql2) === false) {
die("Error: " . $db->lastError() . "\n\n");
}
$this->out(__("Creating relationships table (aros_acos)...", true), true);
$sql3 = "CREATE TABLE ".$db->fullTableName('aros_acos')." (
".$db->name('id')." ".$db->column($db->columns['primary_key']).",
".$db->name('aro_id')." ".$db->column($db->columns['integer'])." default NULL,
".$db->name('aco_id')." ".$db->column($db->columns['integer'])." default NULL,
".$db->name('_create')." ".$db->column($db->columns['integer'])." default '0' NOT NULL,
".$db->name('_read')." ".$db->column($db->columns['integer'])." default '0' NOT NULL,
".$db->name('_update')." ".$db->column($db->columns['integer'])." default '0' NOT NULL,
".$db->name('_delete')." ".$db->column($db->columns['integer'])." default '0' NOT NULL,
PRIMARY KEY (".$db->name('id').")
)";
if ($db->query($sql3) === false) {
die("Error: " . $db->lastError() . "\n\n");
}
$this->out("\n" . __("Done.", true), true);
$this->err('This command is deprecated. Please use, cake schema run create -name DbAcl');
}
/**
* Show help screen.

View file

@ -57,8 +57,20 @@ class SchemaShell extends Shell {
* @access public
*/
function startup() {
$settings = am(array('path'=> CONFIGS .'sql'), $this->params);
$this->Schema =& new CakeSchema($settings);
$name = null;
if (!empty($this->params['name'])) {
$name = $this->params['name'];
}
$path = null;
if (!empty($this->params['path'])) {
$path = $this->params['path'];
}
$file = null;
if (!empty($this->params['file'])) {
$file = $this->params['file'];
}
$this->Schema =& new CakeSchema(compact('name', 'path', 'file'));
}
/**
* Override main
@ -148,6 +160,10 @@ class SchemaShell extends Shell {
function dump() {
$write = false;
$Schema = $this->Schema->load();
if(!$Schema) {
$this->err(__('Schema could not be loaded', true));
exit();
}
if (!empty($this->args[0])) {
if($this->args[0] == 'true') {
$write = Inflector::underscore($this->Schema->name);

View file

@ -1,6 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/*DbAcl schema generated on: 2007-11-23 10:11:16 : 1195843096*/
/*DbAcl schema generated on: 2007-11-24 15:11:13 : 1195945453*/
class DbAclSchema extends CakeSchema {
@ -17,9 +17,9 @@ class DbAclSchema extends CakeSchema {
var $acos = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary', 'extra' => 'auto_increment'),
'parent_id' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'model' => array('type'=>'string', 'null' => true, 'default' => ''),
'model' => array('type'=>'string', 'null' => true),
'foreign_key' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'alias' => array('type'=>'string', 'null' => true, 'default' => ''),
'alias' => array('type'=>'string', 'null' => true),
'lft' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'rght' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
@ -28,9 +28,9 @@ class DbAclSchema extends CakeSchema {
var $aros = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary', 'extra' => 'auto_increment'),
'parent_id' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'model' => array('type'=>'string', 'null' => true, 'default' => ''),
'model' => array('type'=>'string', 'null' => true),
'foreign_key' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'alias' => array('type'=>'string', 'null' => true, 'default' => ''),
'alias' => array('type'=>'string', 'null' => true),
'lft' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'rght' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
@ -38,8 +38,8 @@ class DbAclSchema extends CakeSchema {
var $aros_acos = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary', 'extra' => 'auto_increment'),
'aro_id' => array('type'=>'integer', 'null' => false, 'default' => '', 'length' => 10, 'key' => 'index'),
'aco_id' => array('type'=>'integer', 'null' => false, 'default' => '', 'length' => 10),
'aro_id' => array('type'=>'integer', 'null' => false, 'length' => 10, 'key' => 'index'),
'aco_id' => array('type'=>'integer', 'null' => false, 'length' => 10),
'_create' => array('type'=>'string', 'null' => false, 'default' => '0', 'length' => 2),
'_read' => array('type'=>'string', 'null' => false, 'default' => '0', 'length' => 2),
'_update' => array('type'=>'string', 'null' => false, 'default' => '0', 'length' => 2),

View file

@ -47,7 +47,7 @@ class CakeSchema extends Object {
* @var string
* @access public
*/
var $path = TMP;
var $path = null;
/**
* File to write
*
@ -75,15 +75,21 @@ class CakeSchema extends Object {
* @param array $data optional load object properties
*/
function __construct($data = array()) {
$this->path = CONFIGS . 'sql';
$data = am(get_object_vars($this), $data);
parent::__construct();
$this->_build($data);
if (empty($this->name)) {
if (empty($data['name'])) {
$this->name = preg_replace('/schema$/i', '', get_class($this));
}
parent::__construct();
if ($this->name === 'Cake') {
$this->name = Inflector::camelize(Configure::read('App.dir'));
}
if (empty($data['path'])) {
$this->path = CONFIGS . 'sql';
}
$data = am(get_object_vars($this), $data);
$this->_build($data);
}
/**
* Builds schema object properties
@ -92,14 +98,24 @@ class CakeSchema extends Object {
* @access protected
*/
function _build($data) {
$file = null;
foreach ($data as $key => $val) {
if (!in_array($key, array('name', 'path', 'file', 'connection', 'tables', '_log'))) {
$this->tables[$key] = $val;
unset($this->{$key});
} elseif ($key != 'tables' && !empty($val)) {
$this->{$key} = $val;
if (!empty($val)) {
if (!in_array($key, array('name', 'path', 'file', 'connection', 'tables', '_log'))) {
$this->tables[$key] = $val;
unset($this->{$key});
} elseif ($key !== 'tables') {
if ($key === 'name' && $val !== $this->name) {
$file = Inflector::underscore($val) . '.php';
}
$this->{$key} = $val;
}
}
}
if(file_exists($this->path . DS . $file) && is_file($this->path . DS . $file)) {
$this->file = $file;
}
}
/**
* Before callback to be implemented in subclasses
@ -130,22 +146,27 @@ class CakeSchema extends Object {
if (is_string($options)) {
$options = array('path'=> $options);
}
if (!isset($options['name'])) {
$options['name'] = Inflector::camelize(Configure::read('App.dir'));
}
$options = am(
get_object_vars($this), $options
);
extract($options);
if (file_exists($path . DS . $file)) {
require_once($path . DS . $file);
$class = $name .'Schema';
if (class_exists($class)) {
$Schema =& new $class();
$this->_build($options);
return $Schema;
$class = $name .'Schema';
if (!class_exists($class)) {
if (file_exists($path . DS . $file) && is_file($path . DS . $file)) {
require_once($path . DS . $file);
} elseif (file_exists($path . DS . 'schema.php') && is_file($path . DS . 'schema.php')) {
require_once($path . DS . 'schema.php');
}
}
if (class_exists($class)) {
$Schema =& new $class();
$this->_build($options);
return $Schema;
}
return false;
}
/**
@ -159,7 +180,7 @@ class CakeSchema extends Object {
extract(am(
array(
'connection' => $this->connection,
'name' => Inflector::camelize(Configure::read('App.dir')),
'name' => $this->name,
'models' => true,
),
$options
@ -440,7 +461,7 @@ class CakeSchema extends Object {
unset($value['limit']);
}
if (isset($value['default']) && $value['default'] != 0) {
if (isset($value['default']) && ($value['default'] === '' || $value['default'] === false)) {
unset($value['default']);
}
if (empty($value['length'])) {