mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Refactoring and merging duplicated code between CakeSchema and FixtureTask
This commit is contained in:
parent
236a679b17
commit
0fc6f58cfb
2 changed files with 7 additions and 30 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue