From 84f805419de669d015da77ee7a296f909d7ef013 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 2 Oct 2011 22:49:48 -0400 Subject: [PATCH] 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. --- .../Console/Command/Task/DbConfigTask.php | 6 ++-- .../Console/Command/Task/DbConfigTaskTest.php | 30 ++++--------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/lib/Cake/Console/Command/Task/DbConfigTask.php b/lib/Cake/Console/Command/Task/DbConfigTask.php index 02041ea3d..43fae5f35 100644 --- a/lib/Cake/Console/Command/Task/DbConfigTask.php +++ b/lib/Cake/Console/Command/Task/DbConfigTask.php @@ -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'); } diff --git a/lib/Cake/Test/Case/Console/Command/Task/DbConfigTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/DbConfigTaskTest.php index 701284938..7c5ded6be 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/DbConfigTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/DbConfigTaskTest.php @@ -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); } /**