Closes #3318, When model calls invalidate, it would be usefull to use the __(messageID, true)

Fixes #2603, Scaffold edit() should redirect to index() when no record is found.
Closes #2990 cake_sessions Needs A Database Name Setting, Configure::write('Session.database', 'default')
Closes #3120, database - $config['encoding']; added new settings to database.php.default
Corrected errors when setting database configurations from console, would not allow changing setting on old configuration.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5815 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-10-20 10:14:30 +00:00
parent ae9243e43d
commit e750c9d38f
8 changed files with 126 additions and 56 deletions

View file

@ -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.
*/

View file

@ -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' => ''
);
}
?>

View file

@ -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 = "<?php\n";
$out .= "class DATABASE_CONFIG {\n\n";
foreach ($configs as $config) {
$config = am($this->__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);
}
}
?>
?>

View file

@ -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.
*/

View file

@ -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' => ''
);
}
?>

View file

@ -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];

View file

@ -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.

View file

@ -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;
}
}
?>
?>