From 0fc6f58cfb7ba37a2910588222542fbb98c962a1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 3 Oct 2009 16:15:56 -0400 Subject: [PATCH] Refactoring and merging duplicated code between CakeSchema and FixtureTask --- cake/console/libs/tasks/fixture.php | 31 +---------------------------- cake/libs/model/cake_schema.php | 6 ++++++ 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/cake/console/libs/tasks/fixture.php b/cake/console/libs/tasks/fixture.php index b1f59fe471c..311c7d3c0ec 100644 --- a/cake/console/libs/tasks/fixture.php +++ b/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); } /** diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index bebf6516a6b..6af92f463d2 100644 --- a/cake/libs/model/cake_schema.php +++ b/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;