From d2e2805fac1675b54b26a2b089323425cdc2afb1 Mon Sep 17 00:00:00 2001 From: Toni Uebernickel Date: Tue, 21 Feb 2012 23:37:29 +0100 Subject: [PATCH 1/7] add handling of array type in data loader --- DataFixtures/Loader/AbstractDataLoader.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/DataFixtures/Loader/AbstractDataLoader.php b/DataFixtures/Loader/AbstractDataLoader.php index c4bb9ea..8cd2e37 100644 --- a/DataFixtures/Loader/AbstractDataLoader.php +++ b/DataFixtures/Loader/AbstractDataLoader.php @@ -161,10 +161,19 @@ abstract class AbstractDataLoader extends AbstractDataHandler implements DataLoa } foreach ($data as $name => $value) { - if (is_array($value) && 's' == substr($name, -1)) { - // many to many relationship - $this->loadManyToMany($obj, substr($name, 0, -1), $value); - continue; + try { + if (is_array($value) && 's' == substr($name, -1)) { + // many to many relationship + $this->loadManyToMany($obj, substr($name, 0, -1), $value); + continue; + } + } catch (\PropelException $e) { + // Check whether this is actually an array stored in the object. + if ('Cannot fetch TableMap for undefined table: '.substr($name, 0, -1) === $e->getMessage()) { + if ($tableMap->getColumn($name)->getType() !== 'ARRAY') { + throw $e; + } + } } $isARealColumn = true; From 82170e1718912812d9585c8a04706181913c2ad9 Mon Sep 17 00:00:00 2001 From: Toni Uebernickel Date: Wed, 22 Feb 2012 10:15:41 +0100 Subject: [PATCH 2/7] dump array columns as array --- DataFixtures/Dumper/AbstractDataDumper.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DataFixtures/Dumper/AbstractDataDumper.php b/DataFixtures/Dumper/AbstractDataDumper.php index 2fbc64c..1985c9b 100644 --- a/DataFixtures/Dumper/AbstractDataDumper.php +++ b/DataFixtures/Dumper/AbstractDataDumper.php @@ -150,6 +150,11 @@ abstract class AbstractDataDumper extends AbstractDataHandler implements DataDum } } elseif (!$isPrimaryKey || ($isPrimaryKey && !$tableMap->isUseIdGenerator())) { + if (!empty($row[$col]) && 'ARRAY' === $column->getType()) { + $serialized = substr($row[$col], 2, -2); + $row[$col] = $serialized ? explode(' | ', $serialized) : array(); + } + // We did not want auto incremented primary keys $values[$col] = $row[$col]; } From 563a368687c36c1fb35ec7abff5075497f5e7362 Mon Sep 17 00:00:00 2001 From: Toni Uebernickel Date: Wed, 22 Feb 2012 10:19:26 +0100 Subject: [PATCH 3/7] add tests for array dump and load --- Tests/DataFixtures/Dumper/YamlDataDumperTest.php | 6 ++++-- Tests/DataFixtures/Loader/YamlDataLoaderTest.php | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/DataFixtures/Dumper/YamlDataDumperTest.php b/Tests/DataFixtures/Dumper/YamlDataDumperTest.php index 25876e1..9a55703 100644 --- a/Tests/DataFixtures/Dumper/YamlDataDumperTest.php +++ b/Tests/DataFixtures/Dumper/YamlDataDumperTest.php @@ -25,16 +25,18 @@ class YamlDataDumperTest extends TestCase fb1: Id: 10 Title: Hello + Tags: null fb2: Id: 20 Title: World + Tags: [foo, bar, baz] YML; $array = array( '\Foo\Bar' => array( - 'fb1' => array('Id' => 10, 'Title' => 'Hello'), - 'fb2' => array('Id' => 20, 'Title' => 'World') + 'fb1' => array('Id' => 10, 'Title' => 'Hello', 'Tags' => null), + 'fb2' => array('Id' => 20, 'Title' => 'World', 'Tags' => array('foo', 'bar', 'baz')) ) ); diff --git a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php index adbd0a1..4ff6249 100644 --- a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php +++ b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php @@ -27,9 +27,11 @@ class YamlDataLoaderTest extends TestCase fb1: Id: 10 Title: Hello + Tags: null fb2: Id: 20 Title: World + Tags: [foo, bar, baz] YML; $this->tmpfile = (string) tmpfile(); file_put_contents($this->tmpfile, $fixtures); @@ -54,6 +56,8 @@ YML; $this->assertEquals(2, count($subarray), 'There is two fixtures objects'); $this->assertArrayHasKey('fb1', $subarray); $this->assertArrayHasKey('fb2', $subarray); + $this->assertTrue(is_array($subarray['fb2']['Tags'])); + $this->assertEquals(array('foo', 'bar', 'baz'), $subarray['fb2']['Tags']); } } From 264708ab1640e687b3ef91413f4da088ddf7a261 Mon Sep 17 00:00:00 2001 From: Toni Uebernickel Date: Fri, 24 Feb 2012 00:22:04 +0100 Subject: [PATCH 4/7] fix minor code styles --- DataFixtures/Loader/AbstractDataLoader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DataFixtures/Loader/AbstractDataLoader.php b/DataFixtures/Loader/AbstractDataLoader.php index 8cd2e37..2ab531a 100644 --- a/DataFixtures/Loader/AbstractDataLoader.php +++ b/DataFixtures/Loader/AbstractDataLoader.php @@ -162,7 +162,7 @@ abstract class AbstractDataLoader extends AbstractDataHandler implements DataLoa foreach ($data as $name => $value) { try { - if (is_array($value) && 's' == substr($name, -1)) { + if (is_array($value) && 's' === substr($name, -1)) { // many to many relationship $this->loadManyToMany($obj, substr($name, 0, -1), $value); continue; @@ -170,7 +170,7 @@ abstract class AbstractDataLoader extends AbstractDataHandler implements DataLoa } catch (\PropelException $e) { // Check whether this is actually an array stored in the object. if ('Cannot fetch TableMap for undefined table: '.substr($name, 0, -1) === $e->getMessage()) { - if ($tableMap->getColumn($name)->getType() !== 'ARRAY') { + if ('ARRAY' !== $tableMap->getColumn($name)->getType()) { throw $e; } } From ebf5aece637f769156b72554ef34d65332b5a149 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Sat, 3 Mar 2012 18:47:08 +0100 Subject: [PATCH 5/7] Removed the use of CLASS_DEFAULT constant --- DataFixtures/Loader/AbstractDataLoader.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DataFixtures/Loader/AbstractDataLoader.php b/DataFixtures/Loader/AbstractDataLoader.php index 2ab531a..36a57b8 100644 --- a/DataFixtures/Loader/AbstractDataLoader.php +++ b/DataFixtures/Loader/AbstractDataLoader.php @@ -214,8 +214,7 @@ abstract class AbstractDataLoader extends AbstractDataHandler implements DataLoa // save the object for future reference if (method_exists($obj, 'getPrimaryKey')) { - $class_default = constant(constant($class.'::PEER').'::CLASS_DEFAULT'); - $this->object_references[Propel::importClass($class_default).'_'.$key] = $obj; + $this->object_references[$class.'_'.$key] = $obj; } } } From 77d338f39bdb35a99c90856468c7a121db739105 Mon Sep 17 00:00:00 2001 From: Luca Saba Date: Mon, 12 Mar 2012 22:05:09 +0100 Subject: [PATCH 6/7] Correct a typo in a comment in AbstractPropelCommand --- Command/AbstractPropelCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/AbstractPropelCommand.php b/Command/AbstractPropelCommand.php index 3593408..6ebde7a 100644 --- a/Command/AbstractPropelCommand.php +++ b/Command/AbstractPropelCommand.php @@ -108,7 +108,7 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand // build.properties $this->createBuildPropertiesFile($kernel, $this->cacheDir.'/build.properties'); - // buidtime-conf.xml + // buildtime-conf.xml $this->createBuildTimeFile($this->cacheDir.'/buildtime-conf.xml'); // Verbosity From 9491c1b27c878eb3aa4065431285902e256b5d0e Mon Sep 17 00:00:00 2001 From: Toni Uebernickel Date: Wed, 14 Mar 2012 10:16:09 +0100 Subject: [PATCH 7/7] backport f589d31 from master --- DataFixtures/Loader/AbstractDataLoader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DataFixtures/Loader/AbstractDataLoader.php b/DataFixtures/Loader/AbstractDataLoader.php index 36a57b8..9cd0ba4 100644 --- a/DataFixtures/Loader/AbstractDataLoader.php +++ b/DataFixtures/Loader/AbstractDataLoader.php @@ -189,13 +189,13 @@ abstract class AbstractDataLoader extends AbstractDataHandler implements DataLoa if ($isARealColumn) { if ($column->isForeignKey() && null !== $value) { $relatedTable = $this->dbMap->getTable($column->getRelatedTableName()); - if (!isset($this->object_references[$relatedTable->getPhpName().'_'.$value])) { + if (!isset($this->object_references[$relatedTable->getClassname().'_'.$value])) { throw new \InvalidArgumentException( - sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedTable->getPhpName()) + sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedTable->getClassname()) ); } $value = $this - ->object_references[$relatedTable->getPhpName().'_'.$value] + ->object_references[$relatedTable->getClassname().'_'.$value] ->getByName($column->getRelatedName(), BasePeer::TYPE_COLNAME); } }