Skip to content
Browse files

Enabling plugin.name schema file creation and addition.

Making CakeSchema::load() use plugin parameter, tests added.
Plugin schema file added to test_app.
  • Loading branch information...
1 parent c2a53d3 commit 05f6099def804cdd0b60827bdab2d01d18d02fa1 @markstory markstory committed
View
13 cake/console/libs/schema.php
@@ -63,10 +63,12 @@ function startup() {
$name = $this->params['name'];
$this->params['file'] = Inflector::underscore($name);
}
- $path = $this->_getPath();
if (empty($this->params['file'])) {
$this->params['file'] = 'schema.php';
}
+ if (!empty($this->params['path'])) {
+ $path = $this->params['path'];
+ }
if (strpos($this->params['file'], '.php') === false) {
$this->params['file'] .= '.php';
}
@@ -263,20 +265,23 @@ function update() {
* @return void
**/
function _loadSchema() {
- $name = null;
+ $name = $plugin = null;
if (isset($this->args[0])) {
$name = $this->args[0];
}
if (isset($this->params['name'])) {
$name = $this->params['name'];
}
+ if (strpos($name, '.') !== false) {
+ list($plugin, $name) = explode('.', $name);
+ }
if (isset($this->params['dry'])) {
$this->__dry = true;
$this->out(__('Performing a dry run.', true));
}
- $options = array('name' => $name);
+ $options = array('name' => $name, 'plugin' => $plugin);
if (isset($this->params['s'])) {
$fileName = rtrim($this->Schema->file, '.php');
$options['file'] = $fileName . '_' . $this->params['s'] . '.php';
@@ -285,7 +290,7 @@ function _loadSchema() {
$Schema =& $this->Schema->load($options);
if (!$Schema) {
- $this->err(sprintf(__('%s could not be loaded', true), $this->Schema->file));
+ $this->err(sprintf(__('%s could not be loaded', true), $this->Schema->path . DS . $this->Schema->file));
$this->_stop();
}
$table = null;
View
3 cake/libs/model/cake_schema.php
@@ -133,9 +133,10 @@ function _build($data) {
}
}
}
-
if (file_exists($this->path . DS . $file) && is_file($this->path . DS . $file)) {
$this->file = $file;
+ } elseif (!empty($this->plugin)) {
+ $this->path = App::pluginPath($this->plugin) . 'config' . DS . 'schema';
}
}
View
32 cake/tests/cases/console/libs/schema.test.php
@@ -366,19 +366,35 @@ function testPluginParam() {
'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;
+ $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'config' . DS . 'schema';
$this->assertEqual($this->Shell->Schema->path, $expected);
+
+ App::build();
+ }
- unset($this->Shell->Schema);
+/**
+ * test that using Plugin.name with write.
+ *
+ * @return void
+ **/
+ function testPluginDotSyntax() {
+ 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',
- 'path' => '/some/path'
+ 'connection' => 'test_suite'
);
+ $this->Shell->args = array('TestPlugin.TestPluginApp');
$this->Shell->startup();
- $expected = '/some/path';
- $this->assertEqual($this->Shell->Schema->path, $expected);
- }
+ $this->Shell->setReturnValue('in', 'y');
+ $this->Shell->create();
+ $db =& ConnectionManager::getDataSource('test_suite');
+ $sources = $db->listSources();
+ $this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources));
+
+ $db->execute('DROP TABLE ' . $db->config['prefix'] . 'acos');
+ App::build();
+ }
}
?>
View
18 cake/tests/cases/libs/model/cake_schema.test.php
@@ -574,12 +574,28 @@ function testSchemaComparison() {
* @return void
*/
function testSchemaLoading() {
- $Other = $this->Schema->load(array('name' => 'MyOtherApp', 'path' => TMP . 'tests'));
+ $Other =& $this->Schema->load(array('name' => 'MyOtherApp', 'path' => TMP . 'tests'));
$this->assertEqual($Other->name, 'MyOtherApp');
$this->assertEqual($Other->tables, $this->Schema->tables);
}
/**
+ * test loading schema files inside of plugins.
+ *
+ * @return void
+ **/
+ function testSchemaLoadingFromPlugin() {
+ App::build(array(
+ 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
+ ));
+ $Other =& $this->Schema->load(array('name' => 'TestPluginApp', 'plugin' => 'TestPlugin'));
+ $this->assertEqual($Other->name, 'TestPluginApp');
+ $this->assertEqual(array_keys($Other->tables), array('acos'));
+
+ App::build();
+ }
+
+/**
* testSchemaCreateTable method
*
* @access public
View
39 cake/tests/test_app/plugins/test_plugin/config/schema/schema.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * TestAppSchema file
+ *
+ * Use for testing the loading of schema files from plugins.
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @filesource
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @package cake
+ * @subpackage cake.app.config.sql
+ * @since CakePHP(tm) v 1.3
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+class TestPluginAppSchema extends CakeSchema {
+
+ var $name = 'TestPluginApp';
+
+ var $acos = array(
+ 'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary'),
+ 'parent_id' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
+ 'model' => array('type'=>'string', 'null' => true),
+ 'foreign_key' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
+ 'alias' => array('type'=>'string', 'null' => true),
+ 'lft' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
+ 'rght' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
+ 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
+ );
+
+}
+?>

0 comments on commit 05f6099

Please sign in to comment.
Something went wrong with that request. Please try again.