mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Fixing issue where DbConfigTask would try to rebuild
database configuration. This could happen when using commands like `Console/cake bake controller`. Using ConnectionManager ensures that the database config file will be loaded if its available.
This commit is contained in:
parent
aae2b0c257
commit
84f805419d
2 changed files with 8 additions and 28 deletions
|
@ -353,14 +353,14 @@ class DbConfigTask extends Shell {
|
|||
*/
|
||||
public function getConfig() {
|
||||
App::uses('ConnectionManager', 'Model');
|
||||
$configs = ConnectionManager::enumConnectionObjects();
|
||||
|
||||
$useDbConfig = 'default';
|
||||
$configs = get_class_vars($this->databaseClassName);
|
||||
if (!is_array($configs)) {
|
||||
if (!is_array($configs) || empty($configs)) {
|
||||
return $this->execute();
|
||||
}
|
||||
|
||||
$connections = array_keys($configs);
|
||||
|
||||
if (count($connections) > 1) {
|
||||
$useDbConfig = $this->in(__d('cake_console', 'Use Database Config') .':', $connections, 'default');
|
||||
}
|
||||
|
|
|
@ -23,28 +23,6 @@ App::uses('ConsoleInput', 'Console');
|
|||
App::uses('Shell', 'Console');
|
||||
App::uses('DbConfigTask', 'Console/Command/Task');
|
||||
|
||||
class TEST_DATABASE_CONFIG {
|
||||
public $default = array(
|
||||
'driver' => 'mysql',
|
||||
'persistent' => false,
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
'database' => 'database_name',
|
||||
'prefix' => '',
|
||||
);
|
||||
|
||||
public $otherOne = array(
|
||||
'driver' => 'mysql',
|
||||
'persistent' => false,
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
'database' => 'other_one',
|
||||
'prefix' => '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* DbConfigTest class
|
||||
*
|
||||
|
@ -68,7 +46,6 @@ class DbConfigTaskTest extends CakeTestCase {
|
|||
);
|
||||
|
||||
$this->Task->path = APP . 'Config' . DS;
|
||||
$this->Task->databaseClassName = 'TEST_DATABASE_CONFIG';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,9 +64,12 @@ class DbConfigTaskTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testGetConfig() {
|
||||
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('otherOne'));
|
||||
$this->Task->expects($this->at(0))
|
||||
->method('in')
|
||||
->will($this->returnValue('test'));
|
||||
|
||||
$result = $this->Task->getConfig();
|
||||
$this->assertEquals('otherOne', $result);
|
||||
$this->assertEquals('test', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue