1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

Fix for importing.

This commit is contained in:
Jonathan.Wage 2007-10-08 22:47:59 +00:00
parent 8c413b2427
commit 94bf9a4c7c
3 changed files with 37 additions and 20 deletions

View file

@ -140,6 +140,17 @@ class Doctrine_Data_Export extends Doctrine_Data
continue; continue;
} }
// skip single primary keys, we need to maintain composite primary keys
$keys = $record->getTable()->getIdentifier();
if (!is_array($keys)) {
$keys = array($keys);
}
if (count($keys) <= 1 && in_array($key, $keys)) {
continue;
}
if ($relation = $this->isRelation($record, $key)) { if ($relation = $this->isRelation($record, $key)) {
$relationAlias = $relation['alias']; $relationAlias = $relation['alias'];
$relationRecord = $record->$relationAlias; $relationRecord = $record->$relationAlias;
@ -160,18 +171,7 @@ class Doctrine_Data_Export extends Doctrine_Data
$relationValue = $relationClassName . '_' . $value; $relationValue = $relationClassName . '_' . $value;
$preparedData[$className][$recordKey][$relationClassName] = $relationValue; $preparedData[$className][$recordKey][$relationClassName] = $relationValue;
} else { } else {
// skip single primary keys, we need to maintain composite primary keys
$keys = $record->getTable()->getIdentifier();
if (!is_array($keys)) {
$keys = array($keys);
}
if (count($keys) <= 1 && in_array($key, $keys)) {
continue;
}
$preparedData[$className][$recordKey][$key] = $value; $preparedData[$className][$recordKey][$key] = $value;
} }
} }

View file

@ -193,7 +193,7 @@ END;
} }
if (!empty($ret)) { if (!empty($ret)) {
return "\n\t\tpublic function setTableDefinition()"."\n\t\t{\n".implode("\n", $ret)."\n\t\t}"; return "\n\tpublic function setTableDefinition()"."\n\t{\n".implode("\n", $ret)."\n\t}";
} }
} }
public function buildSetUp(array $options, array $columns, array $relations) public function buildSetUp(array $options, array $columns, array $relations)
@ -264,7 +264,7 @@ END;
} }
if (!empty($ret)) { if (!empty($ret)) {
return "\n\t\tpublic function setUp()\n\t\t{\n".implode("\n", $ret)."\n\t\t}"; return "\n\tpublic function setUp()\n\t{\n".implode("\n", $ret)."\n\t}";
} }
} }
@ -311,11 +311,14 @@ END;
if ($this->generateBaseClasses()) { if ($this->generateBaseClasses()) {
// We only want to generate this one if it doesn't already exist // We only want to generate this one if it doesn't already exist
if (!file_exists($options['fileName'])) { if (file_exists($options['fileName'])) {
$optionsBak = $options; $optionsBak = $options;
unset($options['tableName']); unset($options['tableName']);
$options['inheritance']['extends'] = 'Base' . $options['className']; $options['inheritance']['extends'] = 'Base' . $options['className'];
$options['requires'] = array($this->baseClassesDirectory . DIRECTORY_SEPARATOR . $options['inheritance']['extends'] . $this->suffix);
$options['no_definition'] = true;
$this->writeDefinition($options, array(), array()); $this->writeDefinition($options, array(), array());
$options = $optionsBak; $options = $optionsBak;
@ -341,7 +344,21 @@ END;
{ {
$content = $this->buildDefinition($options, $columns, $relations); $content = $this->buildDefinition($options, $columns, $relations);
$bytes = file_put_contents($options['fileName'], '<?php' . PHP_EOL . $content); $code = "<?php\n";
if (isset($options['requires'])) {
if (!is_array($options['requires'])) {
$options['requires'] = array($options['requires']);
}
foreach ($options['requires'] as $require) {
$code .= "require_once('".$require."');";
}
}
$code .= PHP_EOL . $content;
$bytes = file_put_contents($options['fileName'], $code);
if ($bytes === false) { if ($bytes === false) {
throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $options['fileName']); throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $options['fileName']);

View file

@ -4,9 +4,9 @@ require_once('playground.php');
$dbh = new PDO('mysql:host=localhost;dbname=test', 'jwage', 'elite1baller'); $dbh = new PDO('mysql:host=localhost;dbname=test', 'jwage', 'elite1baller');
$conn = Doctrine_Manager::connection($dbh); $conn = Doctrine_Manager::connection($dbh);
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL);
//Doctrine::loadModels('test_models'); Doctrine::loadModels('test_models');
$import = new Doctrine_Import_Schema(); $data = new Doctrine_Data();
$import->generateBaseClasses(true); $data->importData('fixtures.yml');
$import->importSchema('schema.yml', 'yml', 'test_models');