From b6b192fda6de671922458d663fb0840595f354da Mon Sep 17 00:00:00 2001 From: gwoo Date: Sun, 25 Nov 2007 16:01:49 +0000 Subject: [PATCH] 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 --- app/config/sql/db_acl.php | 36 ++++++++++- app/config/sql/i18n.php | 58 ++++++++++++++++++ app/config/sql/sessions.php | 55 +++++++++++++++++ cake/console/libs/acl.php | 4 +- cake/console/libs/schema.php | 61 ++++++++++--------- .../libs/templates/skel/config/sql/db_acl.php | 36 ++++++++++- .../libs/templates/skel/config/sql/i18n.php | 58 ++++++++++++++++++ .../templates/skel/config/sql/sessions.php | 55 +++++++++++++++++ cake/libs/model/schema.php | 21 +++---- 9 files changed, 336 insertions(+), 48 deletions(-) create mode 100644 app/config/sql/i18n.php create mode 100644 app/config/sql/sessions.php create mode 100644 cake/console/libs/templates/skel/config/sql/i18n.php create mode 100644 cake/console/libs/templates/skel/config/sql/sessions.php diff --git a/app/config/sql/db_acl.php b/app/config/sql/db_acl.php index 4e76cf527..13aaabf2a 100644 --- a/app/config/sql/db_acl.php +++ b/app/config/sql/db_acl.php @@ -1,8 +1,38 @@ - + * 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'; diff --git a/app/config/sql/i18n.php b/app/config/sql/i18n.php new file mode 100644 index 000000000..082a1e9a0 --- /dev/null +++ b/app/config/sql/i18n.php @@ -0,0 +1,58 @@ + + * 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)) + ); + +} +?> \ No newline at end of file diff --git a/app/config/sql/sessions.php b/app/config/sql/sessions.php new file mode 100644 index 000000000..59fee54f7 --- /dev/null +++ b/app/config/sql/sessions.php @@ -0,0 +1,55 @@ + + * 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)) + ); + +} +?> \ No newline at end of file diff --git a/cake/console/libs/acl.php b/cake/console/libs/acl.php index 05c88b7fd..b13b12779 100644 --- a/cake/console/libs/acl.php +++ b/cake/console/libs/acl.php @@ -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 []\n" . "\t\t" . __("Displays this help message, or a message on a specific command.", true) . "\n" diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index 19dc93bd7..ccf0ff2cd 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -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)) { diff --git a/cake/console/libs/templates/skel/config/sql/db_acl.php b/cake/console/libs/templates/skel/config/sql/db_acl.php index 4e76cf527..13aaabf2a 100644 --- a/cake/console/libs/templates/skel/config/sql/db_acl.php +++ b/cake/console/libs/templates/skel/config/sql/db_acl.php @@ -1,8 +1,38 @@ - + * 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'; diff --git a/cake/console/libs/templates/skel/config/sql/i18n.php b/cake/console/libs/templates/skel/config/sql/i18n.php new file mode 100644 index 000000000..082a1e9a0 --- /dev/null +++ b/cake/console/libs/templates/skel/config/sql/i18n.php @@ -0,0 +1,58 @@ + + * 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)) + ); + +} +?> \ No newline at end of file diff --git a/cake/console/libs/templates/skel/config/sql/sessions.php b/cake/console/libs/templates/skel/config/sql/sessions.php new file mode 100644 index 000000000..59fee54f7 --- /dev/null +++ b/cake/console/libs/templates/skel/config/sql/sessions.php @@ -0,0 +1,55 @@ + + * 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)) + ); + +} +?> \ No newline at end of file diff --git a/cake/libs/model/schema.php b/cake/libs/model/schema.php index 9ef946057..707fc5070 100644 --- a/cake/libs/model/schema.php +++ b/cake/libs/model/schema.php @@ -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; }