From e083ca7487d361795e4af4355c0e045bfaf30d22 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Mon, 8 Feb 2021 23:00:18 +0100 Subject: [PATCH] Bug fix : companies fixtures loading fails (Option->text is an json_array) --- DataFixtures/ORM/LoadOption.php | 67 ++++++++++--------------- Entity/CustomFieldLongChoice/Option.php | 2 +- 2 files changed, 28 insertions(+), 41 deletions(-) diff --git a/DataFixtures/ORM/LoadOption.php b/DataFixtures/ORM/LoadOption.php index 6bb894031..b859612c5 100644 --- a/DataFixtures/ORM/LoadOption.php +++ b/DataFixtures/ORM/LoadOption.php @@ -27,7 +27,7 @@ use Doctrine\Persistence\ObjectManager; error_reporting(0); /** * Load some Options - * + * * * @author Julien Fastré */ @@ -38,26 +38,26 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface * @var \Faker\Generator */ public $fakerFr; - + /** * * @var \Faker\Generator */ public $fakerEn; - + /** * * @var \Faker\Generator */ public $fakerNl; - + public function __construct() { $this->fakerFr = \Faker\Factory::create('fr_FR'); $this->fakerEn = \Faker\Factory::create('en_EN'); $this->fakerNl = \Faker\Factory::create('nl_NL'); } - + public function getOrder() { return 1000; @@ -66,52 +66,39 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface public function load(ObjectManager $manager) { echo "Loading Options \n"; - + // load companies - - /* - * TODO sf4 - disabled to avoid error : - * - * An exception occurred while executing 'INSERT INTO custom_field_long_choice_options (id, key, text, internal_key, active, parent_id) - * VALUES (?, ?, ?, ?, ?, ?)' with params [1153, "company", {"fr":"Grandes Entreprises","nl":"Grotes Bedrijven","en":"Big Companies"}, "", 1, null]: - * - * SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type json - * DETAIL: Token "Array" is invalid. - * CONTEXT: JSON data, line 1: Array - * - */ - - //$this->loadingCompanies($manager); - //$this->loadingWords($manager); - + $this->loadingCompanies($manager); + $this->loadingWords($manager); + $manager->flush(); - + } - + private function loadingWords(\Doctrine\Persistence\ObjectManager $manager) { echo "Loading some words...\n"; - + $parents = array( array( 'fr' => 'Categorie 1', 'nl' => 'Categorie 1', 'en' => 'Category 1' - ), + ), array( 'fr' => 'Categorie 2', 'nl' => 'Categorie 2', 'en' => 'Category 2' ) ); - + foreach ($parents as $text) { $parent = (new Option()) ->setText($text) ->setKey('word') ; $manager->persist($parent); - + //Load children $expected_nb_children = rand(10, 50); for ($i=0; $i < $expected_nb_children; $i++) { @@ -123,7 +110,7 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface } } } - + private function loadingCompanies(\Doctrine\Persistence\ObjectManager $manager) { echo "Loading companies \n"; @@ -145,21 +132,21 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface ) ); - + foreach ($companiesParents as $text) { - + $parent = (new Option()) ->setText($text) ->setKey('company') ; $manager->persist($parent); - + //Load children $expected_nb_children = rand(10, 50); for ($i=0; $i < $expected_nb_children; $i++) { - + $companyName = $this->fakerFr->company; - + $manager->persist( $this->createChildOption($parent, array( 'fr' => $companyName, @@ -167,14 +154,14 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface 'en' => $companyName ))); } - + } } - + private $counter = 0; - + /** - * + * * @param Option $parent * @param array $text * @return Option @@ -182,13 +169,13 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface private function createChildOption(Option $parent, array $text) { $this->counter ++; - + return (new Option()) ->setText($text) ->setParent($parent) ->setActive(true) ->setInternalKey($parent->getKey().'-'.$this->counter); - ; + ; } } diff --git a/Entity/CustomFieldLongChoice/Option.php b/Entity/CustomFieldLongChoice/Option.php index 99c2bd1e9..06174a9a6 100644 --- a/Entity/CustomFieldLongChoice/Option.php +++ b/Entity/CustomFieldLongChoice/Option.php @@ -50,7 +50,7 @@ class Option * A json representation of text (multilingual) * * @var array - * @ORM\Column(type="text") + * @ORM\Column(type="json_array") */ private $text;