Commit 84eaea70 authored by zYne's avatar zYne

--no commit message

--no commit message
parent 5bb1dbb8
......@@ -820,55 +820,9 @@ class Doctrine_Export extends Doctrine_Connection_Module
}
try {
$columns = array();
$primary = array();
foreach ($table->getColumns() as $name => $column) {
$definition = $column[2];
$definition['type'] = $column[0];
$definition['length'] = $column[1];
switch ($definition['type']) {
case 'enum':
if (isset($definition['default'])) {
$definition['default'] = $table->enumIndex($name, $definition['default']);
}
break;
case 'boolean':
if (isset($definition['default'])) {
$definition['default'] = $table->getConnection()->convertBooleans($definition['default']);
}
break;
}
$columns[$name] = $definition;
if(isset($definition['primary']) && $definition['primary']) {
$primary[] = $name;
}
}
if ($table->getAttribute(Doctrine::ATTR_EXPORT) & Doctrine::EXPORT_CONSTRAINTS) {
foreach ($table->getRelations() as $name => $relation) {
$fk = $relation->toArray();
$fk['foreignTable'] = $relation->getTable()->getTableName();
if ($relation->getTable() === $this && in_array($relation->getLocal(), $primary)) {
continue;
}
if ($relation->hasConstraint()) {
$options['foreignKeys'][] = $fk;
} elseif ($relation instanceof Doctrine_Relation_LocalKey) {
$options['foreignKeys'][] = $fk;
}
}
}
$options['primary'] = $primary;
$data = $table->getExportableFormat();
$this->conn->export->createTable($table->getOption('tableName'), $columns, array_merge($table->getOptions(), $options));
$this->conn->export->createTable($data[0], $data[1], $data[2]);
} catch(Doctrine_Connection_Exception $e) {
// we only want to silence table already exists errors
if($e->getPortableCode() !== Doctrine::ERR_ALREADY_EXISTS) {
......
......@@ -310,6 +310,64 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
{
$this->conn->export->exportTable($this);
}
/**
* getExportableFormat
* returns exportable presentation of this object
*
* @return array
*/
public function getExportableFormat()
{
$columns = array();
$primary = array();
foreach ($this->getColumns() as $name => $column) {
$definition = $column[2];
$definition['type'] = $column[0];
$definition['length'] = $column[1];
switch ($definition['type']) {
case 'enum':
if (isset($definition['default'])) {
$definition['default'] = $this->enumIndex($name, $definition['default']);
}
break;
case 'boolean':
if (isset($definition['default'])) {
$definition['default'] = $this->getConnection()->convertBooleans($definition['default']);
}
break;
}
$columns[$name] = $definition;
if(isset($definition['primary']) && $definition['primary']) {
$primary[] = $name;
}
}
if ($this->getAttribute(Doctrine::ATTR_EXPORT) & Doctrine::EXPORT_CONSTRAINTS) {
foreach ($this->getRelations() as $name => $relation) {
$fk = $relation->toArray();
$fk['foreignTable'] = $relation->getTable()->getTableName();
if ($relation->getTable() === $this && in_array($relation->getLocal(), $primary)) {
continue;
}
if ($relation->hasConstraint()) {
$options['foreignKeys'][] = $fk;
} elseif ($relation instanceof Doctrine_Relation_LocalKey) {
$options['foreignKeys'][] = $fk;
}
}
}
$options['primary'] = $primary;
return array($this->getOption('tableName'), $columns, array_merge($this->getOptions(), $options));
}
/**
* exportConstraints
* exports the constraints of this table into database based on option definitions
......@@ -372,7 +430,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
public function getOptions()
{
return $this->options;
return $this->options;
}
/**
* addForeignKey
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment