Skip to content
Permalink
Browse files

Extracted another method.

  • Loading branch information...
markstory committed May 15, 2009
1 parent 3051041 commit e6881cced494d391e2d5f0e3d8f9054944bb91f1
Showing with 36 additions and 26 deletions.
  1. +36 −26 cake/console/libs/tasks/model.php
@@ -689,7 +689,7 @@ function _generatePossibleKeys() {
* @param string $useDbConfig Database configuration setting to use
* @access private
*/
function bake($name, $associations = array(), $validate = array(), $primaryKey = 'id', $useTable = null, $useDbConfig = 'default') {
function bake($name, $associations = array(), $validate = array(), $primaryKey = 'id', $useTable = null, $useDbConfig = 'default') {
if (is_object($name)) {
if (!is_array($associations)) {
@@ -731,35 +731,15 @@ function bakeTest($className, $useTable = null, $associations = array()) {
* @param string $useDbConfig Database configuration name
* @access public
*/
function listAll($useDbConfig = null, $interactive = true) {
if (!isset($useDbConfig)) {
$useDbConfig = $this->connection;
}
$db =& ConnectionManager::getDataSource($useDbConfig);
$usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix'];
if ($usePrefix) {
$tables = array();
foreach ($db->listSources() as $table) {
if (!strncmp($table, $usePrefix, strlen($usePrefix))) {
$tables[] = substr($table, strlen($usePrefix));
}
}
} else {
$tables = $db->listSources();
}
if (empty($tables)) {
$this->err(__('Your database does not have any tables.', true));
$this->_stop();
}
$this->__tables = $tables;
function listAll($useDbConfig = null) {
$this->__tables = $this->getAllTables($useDbConfig);
if ($interactive === true) {
if ($this->interactive === true) {
$this->out(__('Possible Models based on your current database:', true));
$this->_modelNames = array();
$count = count($tables);
$count = count($this->__tables);
for ($i = 0; $i < $count; $i++) {
$this->_modelNames[] = $this->_modelName($tables[$i]);
$this->_modelNames[] = $this->_modelName($this->__tables[$i]);
$this->out($i + 1 . ". " . $this->_modelNames[$i]);
}
}
@@ -793,6 +773,36 @@ function getTable($modelName, $useDbConfig = null) {
return $useTable;
}
/**
* Get an Array of all the tables in the supplied connection
* will halt the script if no tables are found.
*
* @param string $useDbConfig Connection name to scan.
* @return array Array of tables in the database.
**/
function getAllTables($useDbConfig = null) {
if (!isset($useDbConfig)) {
$useDbConfig = $this->connection;
}
$tables = array();
$db =& ConnectionManager::getDataSource($useDbConfig);
$usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix'];
if ($usePrefix) {
foreach ($db->listSources() as $table) {
if (!strncmp($table, $usePrefix, strlen($usePrefix))) {
$tables[] = substr($table, strlen($usePrefix));
}
}
} else {
$tables = $db->listSources();
}
if (empty($tables)) {
$this->err(__('Your database does not have any tables.', true));
$this->_stop();
}
return $tables;
}
/**
* Forces the user to specify the model he wants to bake, and returns the selected model name.
*

0 comments on commit e6881cc

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