adding i18n and sessions schema files. command modified slightly to : cake schema run create DbAcl, cake schema run create i18n, and cake schema run create Sessions

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6077 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-11-25 16:01:49 +00:00
parent ff8faa5318
commit b6b192fda6
9 changed files with 336 additions and 48 deletions

View file

@ -1,8 +1,38 @@
<?php
<?php
/* SVN FILE: $Id$ */
/*DbAcl schema generated on: 2007-11-24 15:11:13 : 1195945453*/
/**
* This is Acl Schema file
*
* Use it to configure database for ACL
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.app.config.sql
* @since CakePHP(tm) v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/*
*
* Using the Schema command line utility
* cake schema run create DbAcl
*
*/
class DbAclSchema extends CakeSchema {
var $name = 'DbAcl';

58
app/config/sql/i18n.php Normal file
View file

@ -0,0 +1,58 @@
<?php
/* SVN FILE: $Id$ */
/*i18n schema generated on: 2007-11-25 07:11:25 : 1196004805*/
/**
* This is i18n Schema file
*
* Use it to configure database for i18n
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.app.config.sql
* @since CakePHP(tm) v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/*
*
* Using the Schema command line utility
* cake schema run create i18n
*
*/
class i18nSchema extends CakeSchema {
var $name = 'i18n';
function before($event = array()) {
return true;
}
function after($event = array()) {
}
var $i18n = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary', 'extra' => 'auto_increment'),
'locale' => array('type'=>'string', 'null' => false, 'length' => 6, 'key' => 'index'),
'model' => array('type'=>'string', 'null' => false, 'key' => 'index'),
'foreign_key' => array('type'=>'integer', 'null' => false, 'length' => 10, 'key' => 'index'),
'field' => array('type'=>'string', 'null' => false, 'key' => 'index'),
'content' => array('type'=>'text', 'null' => true, 'default' => NULL),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'locale' => array('column' => 'locale', 'unique' => 0), 'model' => array('column' => 'model', 'unique' => 0), 'row_id' => array('column' => 'foreign_key', 'unique' => 0), 'field' => array('column' => 'field', 'unique' => 0))
);
}
?>

View file

@ -0,0 +1,55 @@
<?php
/* SVN FILE: $Id$ */
/*Sessions schema generated on: 2007-11-25 07:11:54 : 1196004714*/
/**
* This is Sessions Schema file
*
* Use it to configure database for Sessions
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.app.config.sql
* @since CakePHP(tm) v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/*
*
* Using the Schema command line utility
* cake schema run create Sessions
*
*/
class SessionsSchema extends CakeSchema {
var $name = 'Sessions';
function before($event = array()) {
return true;
}
function after($event = array()) {
}
var $cake_sessions = array(
'id' => array('type'=>'string', 'null' => false, 'key' => 'primary'),
'data' => array('type'=>'text', 'null' => true, 'default' => NULL),
'expires' => array('type'=>'integer', 'null' => true, 'default' => NULL),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
}
?>

View file

@ -340,7 +340,7 @@ class AclShell extends Shell {
* @access public
*/
function initdb() {
$this->err('This command is deprecated. Please use, cake schema run create -name DbAcl');
$this->err('This command is deprecated. Please use, cake schema run create DbAcl');
}
/**
* Show help screen.
@ -394,7 +394,7 @@ class AclShell extends Shell {
"\t\t" . __("id/alias parameter allows you to return only a portion of the requested tree.", true) . "\n",
'initdb' => "\tinitdb\n".
"\t\t" . __("Use this command : cake schema run create -name DbAcl", true) . "\n",
"\t\t" . __("Use this command : cake schema run create DbAcl", true) . "\n",
'help' => "\thelp [<command>]\n" .
"\t\t" . __("Displays this help message, or a message on a specific command.", true) . "\n"

View file

@ -114,13 +114,13 @@ class SchemaShell extends Shell {
$snapshot = true;
}
if(!$snapshot && file_exists($this->Schema->path . DS . 'schema.php')) {
if (!$snapshot && file_exists($this->Schema->path . DS . 'schema.php')) {
$snapshot = true;
$result = $this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's');
if($result === 'q') {
if ($result === 'q') {
exit();
}
if($result === 'o') {
if ($result === 'o') {
$snapshot = false;
}
}
@ -128,11 +128,11 @@ class SchemaShell extends Shell {
$content = $this->Schema->read($options);
$content['file'] = 'schema.php';
if($snapshot === true) {
if ($snapshot === true) {
$Folder =& new Folder($this->Schema->path);
$result = $Folder->read();
$count = 1;
if(!empty($result[1])) {
if (!empty($result[1])) {
foreach ($result[1] as $file) {
if (preg_match('/schema/', $file)) {
$count++;
@ -160,12 +160,12 @@ class SchemaShell extends Shell {
function dump() {
$write = false;
$Schema = $this->Schema->load();
if(!$Schema) {
if (!$Schema) {
$this->err(__('Schema could not be loaded', true));
exit();
}
if (!empty($this->args[0])) {
if($this->args[0] == 'true') {
if ($this->args[0] == 'true') {
$write = Inflector::underscore($this->Schema->name);
} else {
$write = $this->args[0];
@ -174,12 +174,12 @@ class SchemaShell extends Shell {
$db =& ConnectionManager::getDataSource($this->Schema->connection);
$contents = "#". $Schema->name ." sql generated on: " . date('Y-m-d H:m:s') . " : ". time()."\n\n";
$contents .= $db->dropSchema($Schema) . "\n\n". $db->createSchema($Schema);
if($write) {
if(strpos($write, '.sql') === false) {
if ($write) {
if (strpos($write, '.sql') === false) {
$write .= '.sql';
}
$File = new File($this->Schema->path . DS . $write, true);
if($File->write($contents)) {
if ($File->write($contents)) {
$this->out(sprintf(__('SQL dump file created in %s', true), $File->pwd()));
exit();
} else {
@ -205,24 +205,29 @@ class SchemaShell extends Shell {
$this->Dispatch->shiftArgs();
if(isset($this->params['dry'])) {
$name = null;
if (isset($this->args[0])) {
$name = $this->args[0];
}
if (isset($this->params['dry'])) {
$this->__dry = true;
$this->out(__('Performing a dry run.', true));
}
$options = array('file' => $this->Schema->file);
if(isset($this->params['s'])) {
$options = array('name' => $name, 'file' => $this->Schema->file);
if (isset($this->params['s'])) {
$options = array('file' => 'schema_'.$this->params['s'].'.php');
}
$Schema = $this->Schema->load($options);
if(!$Schema) {
$this->err(sprintf(__('%s could not be loaded', true), $options['file']));
if (!$Schema) {
$this->err(sprintf(__('%s could not be loaded', true), $this->Schema->file));
exit();
}
$table = null;
if(isset($this->args[1])) {
if (isset($this->args[1])) {
$table = $this->args[1];
}
@ -249,7 +254,7 @@ class SchemaShell extends Shell {
$options = array();
$table = null;
$event = array_keys($Schema->tables);
if($table) {
if ($table) {
$event = array($table);
}
$errors = array();
@ -260,16 +265,16 @@ class SchemaShell extends Shell {
$drop = $db->dropSchema($Schema, $table);
$this->out($drop);
if('y' == $this->in('Are you sure you want to drop tables and create your database?', array('y', 'n'), 'n')) {
if ('y' == $this->in('Are you sure you want to drop tables and create your database?', array('y', 'n'), 'n')) {
$create = $db->createSchema($Schema, $table);
$this->out('Updating Database...');
$contents = array_map('trim', explode(";", $drop. $create));
foreach($contents as $sql) {
if($this->__dry === true) {
if ($this->__dry === true) {
$this->out($sql);
} else {
if(!empty($sql)) {
if(!$this->Schema->before(array('created'=> $event))) {
if (!empty($sql)) {
if (!$this->Schema->before(array('created'=> $event))) {
return false;
}
if (!$db->_execute($sql)) {
@ -279,7 +284,7 @@ class SchemaShell extends Shell {
}
}
}
if(!empty($errors)) {
if (!empty($errors)) {
$this->err($errors);
} elseif ($this->__dry !== true) {
$this->out(__('Database updated', true));
@ -300,7 +305,7 @@ class SchemaShell extends Shell {
$Old = $this->Schema->read();
$compare = $this->Schema->compare($Old, $Schema);
if(isset($compare[$table])) {
if (isset($compare[$table])) {
$compare = array($table => $compare[$table]);
}
@ -309,16 +314,16 @@ class SchemaShell extends Shell {
$db->fullDebug = true;
$contents = $db->alterSchema($compare, $table);
if(empty($contents)) {
if (empty($contents)) {
$this->out(__('Schema is up to date.', true));
exit();
} elseif($this->__dry === true || 'y' == $this->in('Would you like to see the changes?', array('y', 'n'), 'y')) {
} elseif ($this->__dry === true || 'y' == $this->in('Would you like to see the changes?', array('y', 'n'), 'y')) {
$this->out($contents);
}
if($this->__dry !== true) {
if('y' == $this->in('Are you sure you want to update your database?', array('y', 'n'), 'n')) {
if ($this->__dry !== true) {
if ('y' == $this->in('Are you sure you want to update your database?', array('y', 'n'), 'n')) {
$this->out('Updating Database...');
if(!$this->Schema->before($compare)) {
if (!$this->Schema->before($compare)) {
return false;
}
if ($db->_execute($contents)) {

View file

@ -1,8 +1,38 @@
<?php
<?php
/* SVN FILE: $Id$ */
/*DbAcl schema generated on: 2007-11-24 15:11:13 : 1195945453*/
/**
* This is Acl Schema file
*
* Use it to configure database for ACL
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.app.config.sql
* @since CakePHP(tm) v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/*
*
* Using the Schema command line utility
* cake schema run create DbAcl
*
*/
class DbAclSchema extends CakeSchema {
var $name = 'DbAcl';

View file

@ -0,0 +1,58 @@
<?php
/* SVN FILE: $Id$ */
/*i18n schema generated on: 2007-11-25 07:11:25 : 1196004805*/
/**
* This is i18n Schema file
*
* Use it to configure database for i18n
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.app.config.sql
* @since CakePHP(tm) v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/*
*
* Using the Schema command line utility
* cake schema run create i18n
*
*/
class i18nSchema extends CakeSchema {
var $name = 'i18n';
function before($event = array()) {
return true;
}
function after($event = array()) {
}
var $i18n = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary', 'extra' => 'auto_increment'),
'locale' => array('type'=>'string', 'null' => false, 'length' => 6, 'key' => 'index'),
'model' => array('type'=>'string', 'null' => false, 'key' => 'index'),
'foreign_key' => array('type'=>'integer', 'null' => false, 'length' => 10, 'key' => 'index'),
'field' => array('type'=>'string', 'null' => false, 'key' => 'index'),
'content' => array('type'=>'text', 'null' => true, 'default' => NULL),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'locale' => array('column' => 'locale', 'unique' => 0), 'model' => array('column' => 'model', 'unique' => 0), 'row_id' => array('column' => 'foreign_key', 'unique' => 0), 'field' => array('column' => 'field', 'unique' => 0))
);
}
?>

View file

@ -0,0 +1,55 @@
<?php
/* SVN FILE: $Id$ */
/*Sessions schema generated on: 2007-11-25 07:11:54 : 1196004714*/
/**
* This is Sessions Schema file
*
* Use it to configure database for Sessions
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.app.config.sql
* @since CakePHP(tm) v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/*
*
* Using the Schema command line utility
* cake schema run create Sessions
*
*/
class SessionsSchema extends CakeSchema {
var $name = 'Sessions';
function before($event = array()) {
return true;
}
function after($event = array()) {
}
var $cake_sessions = array(
'id' => array('type'=>'string', 'null' => false, 'key' => 'primary'),
'data' => array('type'=>'text', 'null' => true, 'default' => NULL),
'expires' => array('type'=>'integer', 'null' => true, 'default' => NULL),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
}
?>

View file

@ -72,12 +72,12 @@ class CakeSchema extends Object {
/**
* Constructor
*
* @param array $data optional load object properties
* @param array $options optional load object properties
*/
function __construct($data = array()) {
function __construct($options = array()) {
parent::__construct();
if (empty($data['name'])) {
if (empty($options['name'])) {
$this->name = preg_replace('/schema$/i', '', get_class($this));
}
@ -85,11 +85,11 @@ class CakeSchema extends Object {
$this->name = Inflector::camelize(Configure::read('App.dir'));
}
if (empty($data['path'])) {
if (empty($options['path'])) {
$this->path = CONFIGS . 'sql';
}
$data = am(get_object_vars($this), $data);
$this->_build($data);
$options = am(get_object_vars($this), $options);
$this->_build($options);
}
/**
* Builds schema object properties
@ -146,11 +146,9 @@ class CakeSchema extends Object {
if (is_string($options)) {
$options = array('path'=> $options);
}
$options = am(
get_object_vars($this), $options
);
extract($options);
$this->_build($options);
extract(get_object_vars($this));
$class = $name .'Schema';
if (!class_exists($class)) {
@ -162,8 +160,7 @@ class CakeSchema extends Object {
}
if (class_exists($class)) {
$Schema =& new $class();
$this->_build($options);
$Schema =& new $class($options);
return $Schema;
}