Refactoring and merging duplicated code between CakeSchema and FixtureTask

This commit is contained in:
mark_story 2009-10-03 16:15:56 -04:00
parent 236a679b17
commit 0fc6f58cfb
2 changed files with 7 additions and 30 deletions

View file

@ -256,36 +256,7 @@ class FixtureTask extends Shell {
* @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 file

@ -409,7 +409,13 @@ class CakeSchema extends Object {
}
$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;