Skip to content

Commit

Permalink
Refactoring and merging duplicated code between CakeSchema and Fixtur…
Browse files Browse the repository at this point in the history
…eTask
  • Loading branch information
markstory committed Oct 3, 2009
1 parent 236a679 commit 0fc6f58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
31 changes: 1 addition & 30 deletions cake/console/libs/tasks/fixture.php
Expand Up @@ -256,36 +256,7 @@ function generateFixtureFile($model, $otherVars) {
* @return string fields definitions
**/
function _generateSchema($tableInfo) {
$cols = array();
$out = "array(\n";
foreach ($tableInfo as $field => $fieldInfo) {
if (is_array($fieldInfo)) {
if (!in_array($field, array('indexes', 'tableParameters'))) {
$col = "\t\t'{$field}' => array('type'=>'" . $fieldInfo['type'] . "', ";
$col .= join(', ', $this->_Schema->__values($fieldInfo));
} elseif ($field == 'indexes') {
$col = "\t\t'indexes' => array(";
$props = array();
foreach ((array)$fieldInfo as $key => $index) {
$props[] = "'{$key}' => array(".join(', ', $this->_Schema->__values($index)).")";
}
$col .= join(', ', $props);
} elseif ($field == 'tableParameters') {
//@todo add charset, collate and engine here
$col = "\t\t'tableParameters' => array(";
$props = array();
foreach ((array)$fieldInfo as $key => $param) {
$props[] = "'{$key}' => '$param'";
}
$col .= join(', ', $props);
}
$col .= ")";
$cols[] = $col;
}
}
$out .= join(",\n", $cols);
$out .= "\n\t)";
return $out;
return $this->_Schema->generateTable('table', $tableInfo);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions cake/libs/model/cake_schema.php
Expand Up @@ -409,7 +409,13 @@ function generateTable($table, $fields) {
}
$col .= join(', ', $props);
} elseif ($field == 'tableParameters') {
//@todo add charset, collate and engine here
$col = "\t\t'tableParameters' => array(";
$props = array();
foreach ((array)$value as $key => $param) {
$props[] = "'{$key}' => '$param'";
}
$col .= join(', ', $props);
}
$col .= ")";
$cols[] = $col;
Expand Down

0 comments on commit 0fc6f58

Please sign in to comment.