mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
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:
parent
ae9243e43d
commit
e750c9d38f
8 changed files with 126 additions and 56 deletions
|
@ -105,7 +105,13 @@
|
||||||
*
|
*
|
||||||
* The table name set here should *not* include any table prefix defined elsewhere.
|
* 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.
|
* The name of CakePHP's session cookie.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -70,26 +70,29 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DATABASE_CONFIG {
|
class DATABASE_CONFIG {
|
||||||
|
|
||||||
var $default = array(
|
var $default = array(
|
||||||
'driver' => 'mysql',
|
'driver' => 'mysql',
|
||||||
'persistent' => false,
|
'persistent' => false,
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
|
'port' => '',
|
||||||
'login' => 'user',
|
'login' => 'user',
|
||||||
'password' => 'password',
|
'password' => 'password',
|
||||||
'database' => 'project_name',
|
'database' => 'database_name',
|
||||||
'prefix' => ''
|
'schema' => '',
|
||||||
|
'prefix' => '',
|
||||||
|
'encoding' => ''
|
||||||
);
|
);
|
||||||
|
|
||||||
var $test = array(
|
var $test = array(
|
||||||
'driver' => 'mysql',
|
'driver' => 'mysql',
|
||||||
'persistent' => false,
|
'persistent' => false,
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
|
'port' => '',
|
||||||
'login' => 'user',
|
'login' => 'user',
|
||||||
'password' => 'password',
|
'password' => 'password',
|
||||||
'database' => 'project_name-test',
|
'database' => 'test_database_name',
|
||||||
'prefix' => ''
|
'schema' => '',
|
||||||
|
'prefix' => '',
|
||||||
|
'encoding' => ''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -36,11 +36,11 @@ if (!class_exists('File')) {
|
||||||
* @subpackage cake.cake.console.libs.tasks
|
* @subpackage cake.cake.console.libs.tasks
|
||||||
*/
|
*/
|
||||||
class DbConfigTask extends Shell {
|
class DbConfigTask extends Shell {
|
||||||
|
|
||||||
var $__defaultConfig = array('name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
|
var $__defaultConfig = array('name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
|
||||||
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
|
'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
|
* Execution method always used for tasks
|
||||||
|
@ -92,6 +92,15 @@ class DbConfigTask extends Shell {
|
||||||
while ($host == '') {
|
while ($host == '') {
|
||||||
$host = $this->in('Database Host:', null, 'localhost');
|
$host = $this->in('Database Host:', null, 'localhost');
|
||||||
}
|
}
|
||||||
|
$port = '';
|
||||||
|
|
||||||
|
while ($port == '') {
|
||||||
|
$port = $this->in('Port?', null, 'n');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (low($port) == 'n') {
|
||||||
|
$port = null;
|
||||||
|
}
|
||||||
$login = '';
|
$login = '';
|
||||||
|
|
||||||
while ($login == '') {
|
while ($login == '') {
|
||||||
|
@ -125,7 +134,26 @@ class DbConfigTask extends Shell {
|
||||||
if (low($prefix) == 'n') {
|
if (low($prefix) == 'n') {
|
||||||
$prefix = null;
|
$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) {
|
while ($this->__verify($config) == false) {
|
||||||
$this->__interactive();
|
$this->__interactive();
|
||||||
|
@ -137,7 +165,7 @@ class DbConfigTask extends Shell {
|
||||||
$done = true;
|
$done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->bake($dbConfigs);
|
$this->bake($dbConfigs);
|
||||||
config('database');
|
config('database');
|
||||||
return true;
|
return true;
|
||||||
|
@ -156,15 +184,17 @@ class DbConfigTask extends Shell {
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$this->out('The following database configuration will be created:');
|
$this->out('The following database configuration will be created:');
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$this->out("Name: $name");
|
$this->out("Name: $name");
|
||||||
$this->out("Driver: $driver");
|
$this->out("Driver: $driver");
|
||||||
$this->out("Persistent: $persistent");
|
$this->out("Persistent: $persistent");
|
||||||
$this->out("Host: $host");
|
$this->out("Host: $host");
|
||||||
$this->out("User: $login");
|
$this->out("Port: $port");
|
||||||
$this->out("Pass: " . str_repeat('*', strlen($password)));
|
$this->out("User: $login");
|
||||||
$this->out("Database: $database");
|
$this->out("Pass: " . str_repeat('*', strlen($password)));
|
||||||
$this->out("Table prefix: $prefix");
|
$this->out("Database: $database");
|
||||||
$this->out("Schema: $schema");
|
$this->out("Table prefix: $prefix");
|
||||||
|
$this->out("Schema: $schema");
|
||||||
|
$this->out("Encoding: $encoding");
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$looksGood = $this->in('Look okay?', array('y', 'n'), 'y');
|
$looksGood = $this->in('Look okay?', array('y', 'n'), 'y');
|
||||||
|
|
||||||
|
@ -192,54 +222,70 @@ class DbConfigTask extends Shell {
|
||||||
$db = new DATABASE_CONFIG;
|
$db = new DATABASE_CONFIG;
|
||||||
$temp = get_class_vars(get_class($db));
|
$temp = get_class_vars(get_class($db));
|
||||||
|
|
||||||
foreach ($temp as $configName => $info) {
|
foreach ($temp as $configName => $info) {
|
||||||
if (!isset($info['schema'])) {
|
if (!isset($info['schema'])) {
|
||||||
$info['schema'] = null;
|
$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,
|
$oldConfigs[] = array('name' => $configName,
|
||||||
'driver' => $info['driver'],
|
'driver' => $info['driver'],
|
||||||
'persistent' => $info['persistent'],
|
'persistent' => $info['persistent'],
|
||||||
'host' => $info['host'],
|
'host' => $info['host'],
|
||||||
|
'port' => $info['port'],
|
||||||
'login' => $info['login'],
|
'login' => $info['login'],
|
||||||
'password' => $info['password'],
|
'password' => $info['password'],
|
||||||
'database' => $info['database'],
|
'database' => $info['database'],
|
||||||
'prefix' => $info['prefix'],
|
'prefix' => $info['prefix'],
|
||||||
'schema' => $info['schema']);
|
'schema' => $info['schema'],
|
||||||
|
'encoding' => $info['encoding']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($oldConfigs as $oldConfig) {
|
foreach ($oldConfigs as $key => $oldConfig) {
|
||||||
foreach ($configs as $key => $config) {
|
foreach ($configs as $key1 => $config) {
|
||||||
if ($oldConfig['name'] == $config['name']) {
|
if ($oldConfig['name'] == $config['name']) {
|
||||||
unset($configs[$key]);
|
unset($oldConfigs[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$configs = am($oldConfigs, $configs);
|
$configs = am($oldConfigs, $configs);
|
||||||
$out = "<?php\n";
|
$out = "<?php\n";
|
||||||
$out .= "class DATABASE_CONFIG {\n\n";
|
$out .= "class DATABASE_CONFIG {\n\n";
|
||||||
|
|
||||||
foreach ($configs as $config) {
|
foreach ($configs as $config) {
|
||||||
$config = am($this->__defaultConfig, $config);
|
$config = am($this->__defaultConfig, $config);
|
||||||
extract($config);
|
extract($config);
|
||||||
$out .= "\tvar \${$name} = array(\n";
|
$out .= "\tvar \${$name} = array(\n";
|
||||||
$out .= "\t\t'driver' => '{$driver}',\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'host' => '{$host}',\n";
|
||||||
|
$out .= "\t\t'port' => '{$port}',\n";
|
||||||
$out .= "\t\t'login' => '{$login}',\n";
|
$out .= "\t\t'login' => '{$login}',\n";
|
||||||
$out .= "\t\t'password' => '{$password}',\n";
|
$out .= "\t\t'password' => '{$password}',\n";
|
||||||
$out .= "\t\t'database' => '{$database}', \n";
|
$out .= "\t\t'database' => '{$database}',\n";
|
||||||
$out .= "\t\t'schema' => '{$schema}', \n";
|
$out .= "\t\t'schema' => '{$schema}',\n";
|
||||||
$out .= "\t\t'prefix' => '{$prefix}' \n";
|
$out .= "\t\t'prefix' => '{$prefix}',\n";
|
||||||
|
$out .= "\t\t'encoding' => '{$encoding}'\n";
|
||||||
$out .= "\t);\n";
|
$out .= "\t);\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$out .= "}\n";
|
$out .= "}\n";
|
||||||
$out .= "?>";
|
$out .= "?>";
|
||||||
$filename = CONFIGS.'database.php';
|
$filename = CONFIGS.'database.php';
|
||||||
return $this->createFile($filename, $out);
|
return $this->createFile($filename, $out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -105,7 +105,13 @@
|
||||||
*
|
*
|
||||||
* The table name set here should *not* include any table prefix defined elsewhere.
|
* 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.
|
* The name of CakePHP's session cookie.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -70,26 +70,29 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DATABASE_CONFIG {
|
class DATABASE_CONFIG {
|
||||||
|
|
||||||
var $default = array(
|
var $default = array(
|
||||||
'driver' => 'mysql',
|
'driver' => 'mysql',
|
||||||
'persistent' => false,
|
'persistent' => false,
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
|
'port' => '',
|
||||||
'login' => 'user',
|
'login' => 'user',
|
||||||
'password' => 'password',
|
'password' => 'password',
|
||||||
'database' => 'project_name',
|
'database' => 'database_name',
|
||||||
'prefix' => ''
|
'schema' => '',
|
||||||
|
'prefix' => '',
|
||||||
|
'encoding' => ''
|
||||||
);
|
);
|
||||||
|
|
||||||
var $test = array(
|
var $test = array(
|
||||||
'driver' => 'mysql',
|
'driver' => 'mysql',
|
||||||
'persistent' => false,
|
'persistent' => false,
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
|
'port' => '',
|
||||||
'login' => 'user',
|
'login' => 'user',
|
||||||
'password' => 'password',
|
'password' => 'password',
|
||||||
'database' => 'project_name-test',
|
'database' => 'test_database_name',
|
||||||
'prefix' => ''
|
'schema' => '',
|
||||||
|
'prefix' => '',
|
||||||
|
'encoding' => ''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -256,12 +256,12 @@ class Scaffold extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->controller->_beforeScaffold($action)) {
|
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) {
|
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);
|
$this->controller->redirect($this->redirect);
|
||||||
} else {
|
} 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') {
|
} elseif ($action == 'edit') {
|
||||||
$this->ScaffoldModel->id = $params['pass'][0];
|
$this->ScaffoldModel->id = $params['pass'][0];
|
||||||
|
|
|
@ -1832,7 +1832,7 @@ class Model extends Overloadable {
|
||||||
if (empty($value)) {
|
if (empty($value)) {
|
||||||
$value = true;
|
$value = true;
|
||||||
}
|
}
|
||||||
$this->validationErrors[$field] = $value;
|
$this->validationErrors[$field] = __($value, true);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns true if given field name is a foreign key in this Model.
|
* Returns true if given field name is a foreign key in this Model.
|
||||||
|
|
|
@ -412,7 +412,7 @@ class CakeSession extends Object {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(Configure::read('Session.cookie')) {
|
switch(Configure::read('Session.save')) {
|
||||||
case 'cake':
|
case 'cake':
|
||||||
if (!isset($_SESSION)) {
|
if (!isset($_SESSION)) {
|
||||||
if (function_exists('ini_set')) {
|
if (function_exists('ini_set')) {
|
||||||
|
@ -430,6 +430,12 @@ class CakeSession extends Object {
|
||||||
break;
|
break;
|
||||||
case 'database':
|
case 'database':
|
||||||
if (!isset($_SESSION)) {
|
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')) {
|
if (function_exists('ini_set')) {
|
||||||
ini_set('session.use_trans_sid', 0);
|
ini_set('session.use_trans_sid', 0);
|
||||||
ini_set('url_rewriter.tags', '');
|
ini_set('url_rewriter.tags', '');
|
||||||
|
@ -611,7 +617,7 @@ class CakeSession extends Object {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __read($key) {
|
function __read($key) {
|
||||||
$db =& ConnectionManager::getDataSource('default');
|
$db =& ConnectionManager::getDataSource(Configure::read('Session.database'));
|
||||||
$table = $db->fullTableName(Configure::read('Session.table'), false);
|
$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);
|
$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
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __write($key, $value) {
|
function __write($key, $value) {
|
||||||
$db =& ConnectionManager::getDataSource('default');
|
$db =& ConnectionManager::getDataSource(Configure::read('Session.database'));
|
||||||
$table = $db->fullTableName(Configure::read('Session.table'));
|
$table = $db->fullTableName(Configure::read('Session.table'));
|
||||||
|
|
||||||
switch(Configure::read('Security.level')) {
|
switch(Configure::read('Security.level')) {
|
||||||
|
@ -677,7 +683,7 @@ class CakeSession extends Object {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __destroy($key) {
|
function __destroy($key) {
|
||||||
$db =& ConnectionManager::getDataSource('default');
|
$db =& ConnectionManager::getDataSource(Configure::read('Session.database'));
|
||||||
$table = $db->fullTableName(Configure::read('Session.table'));
|
$table = $db->fullTableName(Configure::read('Session.table'));
|
||||||
$db->execute("DELETE FROM " . $db->name($table) . " WHERE " . $db->name($table.'.id') . " = " . $db->value($key, 'integer'));
|
$db->execute("DELETE FROM " . $db->name($table) . " WHERE " . $db->name($table.'.id') . " = " . $db->value($key, 'integer'));
|
||||||
return true;
|
return true;
|
||||||
|
@ -690,10 +696,10 @@ class CakeSession extends Object {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __gc($expires = null) {
|
function __gc($expires = null) {
|
||||||
$db =& ConnectionManager::getDataSource('default');
|
$db =& ConnectionManager::getDataSource(Configure::read('Session.database'));
|
||||||
$table = $db->fullTableName(Configure::read('Session.table'));
|
$table = $db->fullTableName(Configure::read('Session.table'));
|
||||||
$db->execute("DELETE FROM " . $db->name($table) . " WHERE " . $db->name($table.'.expires') . " < ". $db->value(time()));
|
$db->execute("DELETE FROM " . $db->name($table) . " WHERE " . $db->name($table.'.expires') . " < ". $db->value(time()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Add table
Reference in a new issue