[DataFixtures] Fixed the dumper layer
This commit is contained in:
parent
12aa5b16a1
commit
6ad6e99f22
|
@ -10,6 +10,7 @@
|
|||
|
||||
namespace Propel\PropelBundle\DataFixtures\Dumper;
|
||||
|
||||
use \PDO;
|
||||
use \Propel;
|
||||
use \BaseObject;
|
||||
|
||||
|
@ -25,26 +26,21 @@ abstract class AbstractDataDumper extends AbstractDataHandler implements DataDum
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dump($filename = null, $connectionName)
|
||||
public function dump($filename, $connectionName = null)
|
||||
{
|
||||
$this->loadMapBuilders();
|
||||
$this->con = Propel::getConnection($connectionName);
|
||||
$this->dbMap = Propel::getDatabaseMap($connectionName);
|
||||
|
||||
$array = $this->getDataAsArray($connectionName);
|
||||
|
||||
if (null === $filename) {
|
||||
$filename = 'fixture_' . time();
|
||||
if (null === $filename || '' === $filename) {
|
||||
throw new \Exception('Invalid filename provided.');
|
||||
}
|
||||
|
||||
$filename .= '.' . $this->getFileExtension();
|
||||
$data = $this->transformArrayToData($array);
|
||||
$this->loadMapBuilders($connectionName);
|
||||
$this->con = Propel::getConnection($connectionName);
|
||||
|
||||
$array = $this->getDataAsArray($connectionName);
|
||||
$data = $this->transformArrayToData($array);
|
||||
|
||||
if (false === file_put_contents($filename, $data)) {
|
||||
throw new \Exception(sprintf('Cannot write file: %s', $filename));
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +70,7 @@ abstract class AbstractDataDumper extends AbstractDataHandler implements DataDum
|
|||
{
|
||||
$tables = array();
|
||||
foreach ($this->dbMap->getTables() as $table) {
|
||||
$tables[] = $table->getPhpName();
|
||||
$tables[] = $table->getClassname();
|
||||
}
|
||||
|
||||
$tables = $this->fixOrderingOfForeignKeyData($tables);
|
||||
|
@ -86,6 +82,8 @@ abstract class AbstractDataDumper extends AbstractDataHandler implements DataDum
|
|||
$haveParents = false;
|
||||
$fixColumn = null;
|
||||
|
||||
$shortTableName = substr($tableName, strrpos($tableName, '\\') + 1, strlen($tableName));
|
||||
|
||||
foreach ($tableMap->getColumns() as $column) {
|
||||
$col = strtolower($column->getName());
|
||||
if ($column->isForeignKey()) {
|
||||
|
@ -129,7 +127,7 @@ abstract class AbstractDataDumper extends AbstractDataHandler implements DataDum
|
|||
$dumpData[$tableName] = array();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$pk = $tableName;
|
||||
$pk = $shortTableName;
|
||||
$values = array();
|
||||
$primaryKeys = array();
|
||||
$foreignKeys = array();
|
||||
|
|
|
@ -23,5 +23,5 @@ interface DataDumperInterface
|
|||
* @param string $filename The file name to write data.
|
||||
* @param string $connectionName The Propel connection name.
|
||||
*/
|
||||
function dump($filename = null, $connectionName);
|
||||
function dump($filename, $connectionName = null);
|
||||
}
|
||||
|
|
|
@ -24,17 +24,6 @@ class YamlDataDumper extends AbstractDataDumper
|
|||
*/
|
||||
protected function transformArrayToData($data)
|
||||
{
|
||||
var_dump($data);
|
||||
die();
|
||||
|
||||
return Yaml::dump($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getFileExtension()
|
||||
{
|
||||
return 'yml';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue