Skip to content
Permalink
Browse files

Continuing work on getting plugin support for CakeSchema and SchemaSh…

…ell. Applied patch from 'SkieDr', test cases added.
  • Loading branch information...
markstory committed Aug 28, 2009
1 parent 58e9c0e commit 71aa460a4820ccd2a831f7b017a8c026274cf69c
Showing with 50 additions and 5 deletions.
  1. +5 −2 cake/console/libs/schema.php
  2. +23 −3 cake/libs/model/cake_schema.php
  3. +22 −0 cake/tests/cases/libs/model/cake_schema.test.php
@@ -58,7 +58,7 @@ function initialize() {
* @access public
*/
function startup() {
$name = $file = $path = $connection = null;
$name = $file = $path = $connection = $plugin = null;
if (!empty($this->params['name'])) {
$name = $this->params['name'];
$this->params['file'] = Inflector::underscore($name);
@@ -75,8 +75,11 @@ function startup() {
if (!empty($this->params['connection'])) {
$connection = $this->params['connection'];
}
if (!empty($this->params['plugin'])) {
$plugin = $this->params['plugin'];
}
$this->Schema =& new CakeSchema(compact('name', 'path', 'file', 'connection'));
$this->Schema =& new CakeSchema(compact('name', 'path', 'file', 'connection', 'plugin'));
}
/**
@@ -65,6 +65,13 @@ class CakeSchema extends Object {
*/
var $connection = 'default';
/**
* plugin name.
*
* @var string
**/
var $plugin = null;
/**
* Set of tables
*
@@ -84,6 +91,9 @@ function __construct($options = array()) {
if (empty($options['name'])) {
$this->name = preg_replace('/schema$/i', '', get_class($this));
}
if (!empty($options['plugin'])) {
$this->plugin = $options['plugin'];
}
if (strtolower($this->name) === 'cake') {
$this->name = Inflector::camelize(Inflector::slug(Configure::read('App.dir')));
@@ -112,7 +122,7 @@ function _build($data) {
$file = null;
foreach ($data as $key => $val) {
if (!empty($val)) {
if (!in_array($key, array('name', 'path', 'file', 'connection', 'tables', '_log'))) {
if (!in_array($key, array('plugin', 'name', 'path', 'file', 'connection', 'tables', '_log'))) {
$this->tables[$key] = $val;
unset($this->{$key});
} elseif ($key !== 'tables') {
@@ -207,6 +217,9 @@ function read($options = array()) {
$db =& ConnectionManager::getDataSource($connection);
App::import('Model', 'AppModel');
if (isset($this->plugin)) {
App::import('Model', Inflector::camelize($this->plugin) . 'AppModel');
}
$tables = array();
$currentTables = $db->listSources();
@@ -217,11 +230,18 @@ function read($options = array()) {
}
if (!is_array($models) && $models !== false) {
$models = App::objects('model');
if (isset($this->plugin)) {
$models = App::objects('model', App::pluginPath($this->plugin) . 'models' . DS, false);
} else {
$models = App::objects('model');
}
}
if (is_array($models)) {
foreach ($models as $model) {
if (isset($this->plugin)) {
$model = $this->plugin . '.' . $model;
}
if (PHP5) {
$Object = ClassRegistry::init(array('class' => $model, 'ds' => $connection));
} else {
@@ -230,7 +250,7 @@ function read($options = array()) {
if (is_object($Object) && $Object->useTable !== false) {
$Object->setDataSource($connection);
$table = $db->fullTableName($Object, false);
$table = $db->fullTableName($Object->useTable, false);
if (in_array($table, $currentTables)) {
$key = array_search($table, $currentTables);
@@ -453,6 +453,28 @@ function testSchemaRead() {
$this->assertTrue(empty($read['tables']));
}
/**
* test reading schema from plugins.
*
* @return void
**/
function testSchemaReadWithPlugins() {
App::objects('model', null, false);
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$Schema =& new CakeSchema();
$Schema->plugin = 'TestPlugin';
$read = $Schema->read(array(
'connection' => 'test_suite',
'name' => 'TestApp',
'models' => true
));
$this->assertTrue(isset($read['tables']['posts']));
App::build();
}
/**
* testSchemaWrite method
*

0 comments on commit 71aa460

Please sign in to comment.
You can’t perform that action at this time.