Browse Source

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.

mark_story 14 years ago
parent
commit
84f805419d

+ 3 - 3
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');
 		}

+ 5 - 25
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);
 	}
 
 /**