Fix for importing.
This commit is contained in:
parent
8c413b2427
commit
94bf9a4c7c
@ -140,6 +140,17 @@ class Doctrine_Data_Export extends Doctrine_Data
|
||||
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)) {
|
||||
$relationAlias = $relation['alias'];
|
||||
$relationRecord = $record->$relationAlias;
|
||||
@ -160,18 +171,7 @@ class Doctrine_Data_Export extends Doctrine_Data
|
||||
$relationValue = $relationClassName . '_' . $value;
|
||||
|
||||
$preparedData[$className][$recordKey][$relationClassName] = $relationValue;
|
||||
} 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;
|
||||
}
|
||||
|
||||
} else {
|
||||
$preparedData[$className][$recordKey][$key] = $value;
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ END;
|
||||
}
|
||||
|
||||
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)
|
||||
@ -264,7 +264,7 @@ END;
|
||||
}
|
||||
|
||||
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()) {
|
||||
|
||||
// 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;
|
||||
|
||||
unset($options['tableName']);
|
||||
$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());
|
||||
|
||||
$options = $optionsBak;
|
||||
@ -341,7 +344,21 @@ END;
|
||||
{
|
||||
$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) {
|
||||
throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $options['fileName']);
|
||||
|
@ -4,9 +4,9 @@ require_once('playground.php');
|
||||
$dbh = new PDO('mysql:host=localhost;dbname=test', 'jwage', 'elite1baller');
|
||||
$conn = Doctrine_Manager::connection($dbh);
|
||||
$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();
|
||||
$import->generateBaseClasses(true);
|
||||
$import->importSchema('schema.yml', 'yml', 'test_models');
|
||||
$data = new Doctrine_Data();
|
||||
$data->importData('fixtures.yml');
|
Loading…
x
Reference in New Issue
Block a user