Permalink
Browse files

Refactoring and merging duplicated code between CakeSchema and Fixtur…

…eTask
  • Loading branch information...
1 parent 236a679 commit 0fc6f58cfb7ba37a2910588222542fbb98c962a1 @markstory markstory committed Oct 3, 2009
Showing with 7 additions and 30 deletions.
  1. +1 −30 cake/console/libs/tasks/fixture.php
  2. +6 −0 cake/libs/model/cake_schema.php
View
31 cake/console/libs/tasks/fixture.php
@@ -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);
}
/**
View
6 cake/libs/model/cake_schema.php
@@ -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;

0 comments on commit 0fc6f58

Please sign in to comment.