diff --git a/app/config/core.php b/app/config/core.php index 3a7b7275b..ccfb41b4f 100644 --- a/app/config/core.php +++ b/app/config/core.php @@ -105,7 +105,13 @@ * * The table name set here should *not* include any table prefix defined elsewhere. */ - Configure::write('Session.table', 'cake_sessions'); + //Configure::write('Session.table', 'cake_sessions'); +/** + * The DATABASE_CONFIG::$var to use for database session handling. + * + * 'Session.save' must be set to 'database' in order to utilize this constant. + */ + //Configure::write('Session.database', 'default'); /** * The name of CakePHP's session cookie. */ diff --git a/app/config/database.php.default b/app/config/database.php.default index 3b1f205bf..67de32e06 100644 --- a/app/config/database.php.default +++ b/app/config/database.php.default @@ -70,26 +70,29 @@ * */ class DATABASE_CONFIG { - var $default = array( 'driver' => 'mysql', 'persistent' => false, 'host' => 'localhost', + 'port' => '', 'login' => 'user', 'password' => 'password', - 'database' => 'project_name', - 'prefix' => '' + 'database' => 'database_name', + 'schema' => '', + 'prefix' => '', + 'encoding' => '' ); - var $test = array( 'driver' => 'mysql', 'persistent' => false, 'host' => 'localhost', + 'port' => '', 'login' => 'user', 'password' => 'password', - 'database' => 'project_name-test', - 'prefix' => '' + 'database' => 'test_database_name', + 'schema' => '', + 'prefix' => '', + 'encoding' => '' ); } - ?> \ No newline at end of file diff --git a/cake/console/libs/tasks/db_config.php b/cake/console/libs/tasks/db_config.php index d63fc613a..f62dbd19d 100644 --- a/cake/console/libs/tasks/db_config.php +++ b/cake/console/libs/tasks/db_config.php @@ -36,11 +36,11 @@ if (!class_exists('File')) { * @subpackage cake.cake.console.libs.tasks */ class DbConfigTask extends Shell { - + var $__defaultConfig = array('name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost', 'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name', - 'schema'=> null, 'prefix'=> null); - + 'schema'=> null, 'prefix'=> null, 'encoding' => null, 'port' => null); + /** * Execution method always used for tasks @@ -92,6 +92,15 @@ class DbConfigTask extends Shell { while ($host == '') { $host = $this->in('Database Host:', null, 'localhost'); } + $port = ''; + + while ($port == '') { + $port = $this->in('Port?', null, 'n'); + } + + if (low($port) == 'n') { + $port = null; + } $login = ''; while ($login == '') { @@ -125,7 +134,26 @@ class DbConfigTask extends Shell { if (low($prefix) == 'n') { $prefix = null; } - $config = compact('name', 'driver', 'persistent', 'host', 'login', 'password', 'database', 'prefix'); + $encoding = ''; + + while ($encoding == '') { + $encoding = $this->in('Table encoding?', null, 'n'); + } + + if (low($encoding) == 'n') { + $encoding = null; + } + $schema = ''; + + while ($schema == '') { + $schema = $this->in('Table schema?', null, 'n'); + } + + if (low($schema) == 'n') { + $schema = null; + } + + $config = compact('name', 'driver', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema'); while ($this->__verify($config) == false) { $this->__interactive(); @@ -137,7 +165,7 @@ class DbConfigTask extends Shell { $done = true; } } - + $this->bake($dbConfigs); config('database'); return true; @@ -156,15 +184,17 @@ class DbConfigTask extends Shell { $this->hr(); $this->out('The following database configuration will be created:'); $this->hr(); - $this->out("Name: $name"); - $this->out("Driver: $driver"); - $this->out("Persistent: $persistent"); - $this->out("Host: $host"); - $this->out("User: $login"); - $this->out("Pass: " . str_repeat('*', strlen($password))); - $this->out("Database: $database"); - $this->out("Table prefix: $prefix"); - $this->out("Schema: $schema"); + $this->out("Name: $name"); + $this->out("Driver: $driver"); + $this->out("Persistent: $persistent"); + $this->out("Host: $host"); + $this->out("Port: $port"); + $this->out("User: $login"); + $this->out("Pass: " . str_repeat('*', strlen($password))); + $this->out("Database: $database"); + $this->out("Table prefix: $prefix"); + $this->out("Schema: $schema"); + $this->out("Encoding: $encoding"); $this->hr(); $looksGood = $this->in('Look okay?', array('y', 'n'), 'y'); @@ -192,54 +222,70 @@ class DbConfigTask extends Shell { $db = new DATABASE_CONFIG; $temp = get_class_vars(get_class($db)); - foreach ($temp as $configName => $info) { + foreach ($temp as $configName => $info) { if (!isset($info['schema'])) { $info['schema'] = null; } - + if (!isset($info['encoding'])) { + $info['encoding'] = null; + } + if (!isset($info['port'])) { + $info['port'] = null; + } + + if($info['persistent'] === false) { + $info['persistent'] = 'false'; + } else { + $info['persistent'] = 'false'; + } + $oldConfigs[] = array('name' => $configName, 'driver' => $info['driver'], 'persistent' => $info['persistent'], 'host' => $info['host'], + 'port' => $info['port'], 'login' => $info['login'], 'password' => $info['password'], 'database' => $info['database'], 'prefix' => $info['prefix'], - 'schema' => $info['schema']); + 'schema' => $info['schema'], + 'encoding' => $info['encoding']); } } - - foreach ($oldConfigs as $oldConfig) { - foreach ($configs as $key => $config) { + + foreach ($oldConfigs as $key => $oldConfig) { + foreach ($configs as $key1 => $config) { if ($oldConfig['name'] == $config['name']) { - unset($configs[$key]); + unset($oldConfigs[$key]); } } } - + $configs = am($oldConfigs, $configs); $out = "__defaultConfig, $config); - extract($config); + extract($config); $out .= "\tvar \${$name} = array(\n"; $out .= "\t\t'driver' => '{$driver}',\n"; - $out .= "\t\t'persistent' => '{$persistent}',\n"; + $out .= "\t\t'persistent' => {$persistent},\n"; $out .= "\t\t'host' => '{$host}',\n"; + $out .= "\t\t'port' => '{$port}',\n"; $out .= "\t\t'login' => '{$login}',\n"; $out .= "\t\t'password' => '{$password}',\n"; - $out .= "\t\t'database' => '{$database}', \n"; - $out .= "\t\t'schema' => '{$schema}', \n"; - $out .= "\t\t'prefix' => '{$prefix}' \n"; + $out .= "\t\t'database' => '{$database}',\n"; + $out .= "\t\t'schema' => '{$schema}',\n"; + $out .= "\t\t'prefix' => '{$prefix}',\n"; + $out .= "\t\t'encoding' => '{$encoding}'\n"; $out .= "\t);\n"; } - + $out .= "}\n"; $out .= "?>"; $filename = CONFIGS.'database.php'; return $this->createFile($filename, $out); } } -?> +?> \ No newline at end of file diff --git a/cake/console/libs/templates/skel/config/core.php b/cake/console/libs/templates/skel/config/core.php index 3a7b7275b..ccfb41b4f 100644 --- a/cake/console/libs/templates/skel/config/core.php +++ b/cake/console/libs/templates/skel/config/core.php @@ -105,7 +105,13 @@ * * The table name set here should *not* include any table prefix defined elsewhere. */ - Configure::write('Session.table', 'cake_sessions'); + //Configure::write('Session.table', 'cake_sessions'); +/** + * The DATABASE_CONFIG::$var to use for database session handling. + * + * 'Session.save' must be set to 'database' in order to utilize this constant. + */ + //Configure::write('Session.database', 'default'); /** * The name of CakePHP's session cookie. */ diff --git a/cake/console/libs/templates/skel/config/database.php.default b/cake/console/libs/templates/skel/config/database.php.default index 3b1f205bf..67de32e06 100644 --- a/cake/console/libs/templates/skel/config/database.php.default +++ b/cake/console/libs/templates/skel/config/database.php.default @@ -70,26 +70,29 @@ * */ class DATABASE_CONFIG { - var $default = array( 'driver' => 'mysql', 'persistent' => false, 'host' => 'localhost', + 'port' => '', 'login' => 'user', 'password' => 'password', - 'database' => 'project_name', - 'prefix' => '' + 'database' => 'database_name', + 'schema' => '', + 'prefix' => '', + 'encoding' => '' ); - var $test = array( 'driver' => 'mysql', 'persistent' => false, 'host' => 'localhost', + 'port' => '', 'login' => 'user', 'password' => 'password', - 'database' => 'project_name-test', - 'prefix' => '' + 'database' => 'test_database_name', + 'schema' => '', + 'prefix' => '', + 'encoding' => '' ); } - ?> \ No newline at end of file diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index b807d99d4..00acec087 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -256,12 +256,12 @@ class Scaffold extends Object { } if ($this->controller->_beforeScaffold($action)) { - if ($action == 'edit' && !isset($params['pass'][0])) { + if ($action == 'edit' && !isset($params['pass'][0]) || !$this->ScaffoldModel->exists()) { if (isset($this->controller->Session) && $this->controller->Session->valid != false) { - $this->controller->Session->setFlash(sprintf(__("No id set for %s::edit()", true), Inflector::humanize($this->modelKey))); + $this->controller->Session->setFlash(sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey))); $this->controller->redirect($this->redirect); } else { - return $this->controller->flash(sprintf(__("No id set for %s::edit()", true), Inflector::humanize($this->modelKey)), $this->redirect); + return $this->controller->flash(sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey)), $this->redirect); } } elseif ($action == 'edit') { $this->ScaffoldModel->id = $params['pass'][0]; diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 825296d59..ff037447d 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1832,7 +1832,7 @@ class Model extends Overloadable { if (empty($value)) { $value = true; } - $this->validationErrors[$field] = $value; + $this->validationErrors[$field] = __($value, true); } /** * Returns true if given field name is a foreign key in this Model. diff --git a/cake/libs/session.php b/cake/libs/session.php index dc429ed92..a54e9da4a 100644 --- a/cake/libs/session.php +++ b/cake/libs/session.php @@ -412,7 +412,7 @@ class CakeSession extends Object { break; } - switch(Configure::read('Session.cookie')) { + switch(Configure::read('Session.save')) { case 'cake': if (!isset($_SESSION)) { if (function_exists('ini_set')) { @@ -430,6 +430,12 @@ class CakeSession extends Object { break; case 'database': if (!isset($_SESSION)) { + if (Configure::read('Session.table') === null) { + trigger_error(__("You must set the all Configure::write('Session.*') in core.php to use database storage"), E_USER_WARNING); + exit(); + } elseif (Configure::read('Session.database') === null) { + Configure::write('Session.database', 'default'); + } if (function_exists('ini_set')) { ini_set('session.use_trans_sid', 0); ini_set('url_rewriter.tags', ''); @@ -611,7 +617,7 @@ class CakeSession extends Object { * @access private */ function __read($key) { - $db =& ConnectionManager::getDataSource('default'); + $db =& ConnectionManager::getDataSource(Configure::read('Session.database')); $table = $db->fullTableName(Configure::read('Session.table'), false); $row = $db->query("SELECT " . $db->name($table.'.data') . " FROM " . $db->name($table) . " WHERE " . $db->name($table.'.id') . " = " . $db->value($key), false); @@ -634,7 +640,7 @@ class CakeSession extends Object { * @access private */ function __write($key, $value) { - $db =& ConnectionManager::getDataSource('default'); + $db =& ConnectionManager::getDataSource(Configure::read('Session.database')); $table = $db->fullTableName(Configure::read('Session.table')); switch(Configure::read('Security.level')) { @@ -677,7 +683,7 @@ class CakeSession extends Object { * @access private */ function __destroy($key) { - $db =& ConnectionManager::getDataSource('default'); + $db =& ConnectionManager::getDataSource(Configure::read('Session.database')); $table = $db->fullTableName(Configure::read('Session.table')); $db->execute("DELETE FROM " . $db->name($table) . " WHERE " . $db->name($table.'.id') . " = " . $db->value($key, 'integer')); return true; @@ -690,10 +696,10 @@ class CakeSession extends Object { * @access private */ function __gc($expires = null) { - $db =& ConnectionManager::getDataSource('default'); + $db =& ConnectionManager::getDataSource(Configure::read('Session.database')); $table = $db->fullTableName(Configure::read('Session.table')); $db->execute("DELETE FROM " . $db->name($table) . " WHERE " . $db->name($table.'.expires') . " < ". $db->value(time())); return true; } } -?> +?> \ No newline at end of file