diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index 5245a3171..5629c3ae7 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -58,18 +58,12 @@ class SchemaShell extends Shell { * @access public */ function startup() { - $name = null; + $name = $file = $path = $connection = null; if (!empty($this->params['name'])) { $name = $this->params['name']; $this->params['file'] = Inflector::underscore($name); } - - $path = null; - if (!empty($this->params['path'])) { - $path = $this->params['path']; - } - - $file = null; + $path = $this->_getPath(); if (empty($this->params['file'])) { $this->params['file'] = 'schema.php'; } @@ -78,7 +72,6 @@ class SchemaShell extends Shell { } $file = $this->params['file']; - $connection = null; if (!empty($this->params['connection'])) { $connection = $this->params['connection']; } @@ -86,6 +79,23 @@ class SchemaShell extends Shell { $this->Schema =& new CakeSchema(compact('name', 'path', 'file', 'connection')); } +/** + * Get the correct path for the params. Uses path, and plugin to find the correct path. + * path param takes precedence over any plugins specified. + * + * @return mixed string to correct path or null. + **/ + function _getPath() { + if (!empty($this->params['path'])) { + return $this->params['path']; + } + if (!empty($this->params['plugin'])) { + $pluginPath = $this->_pluginPath($this->params['plugin']); + return $pluginPath . 'config' . DS . 'schema' . DS; + } + return null; + } + /** * Override main * diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index a60b7d3a6..33641c4b8 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -90,7 +90,11 @@ class CakeSchema extends Object { } if (empty($options['path'])) { - $this->path = CONFIGS . 'schema'; + if (is_dir(CONFIGS . 'schema')) { + $this->path = CONFIGS . 'schema'; + } else { + $this->path = CONFIGS . 'sql'; + } } $options = array_merge(get_object_vars($this), $options); diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index c82ea2f4b..7524a4584 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -160,7 +160,7 @@ class SchemaShellTest extends CakeTestCase { $this->assertEqual($this->Shell->Schema->file, 'test_schema.php'); $this->assertEqual($this->Shell->Schema->connection, 'default'); $this->assertEqual($this->Shell->Schema->path, APP . 'config' . DS . 'schema'); - + unset($this->Shell->Schema); $this->Shell->params = array( 'file' => 'other_file.php', @@ -311,7 +311,7 @@ class SchemaShellTest extends CakeTestCase { $this->Shell->startup(); $this->Shell->setReturnValue('in', 'y'); $this->Shell->run(); - + $db =& ConnectionManager::getDataSource('test_suite'); $sources = $db->listSources(); $this->assertTrue(in_array('i18n', $sources)); @@ -364,5 +364,33 @@ class SchemaShellTest extends CakeTestCase { $this->_fixtures['core.article']->create($this->db); } +/** + * test that the plugin param creates the correct path in the schema object. + * + * @return void + **/ + function testPluginParam() { + App::build(array( + 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) + )); + $this->Shell->params = array( + 'plugin' => 'TestPlugin', + 'connection' => 'test_suite' + ); + $this->Shell->startup(); + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'config' . DS . 'schema' . DS; + $this->assertEqual($this->Shell->Schema->path, $expected); + + unset($this->Shell->Schema); + $this->Shell->params = array( + 'plugin' => 'TestPlugin', + 'connection' => 'test_suite', + 'path' => '/some/path' + ); + $this->Shell->startup(); + $expected = '/some/path'; + $this->assertEqual($this->Shell->Schema->path, $expected); + } + } ?> \ No newline at end of file