fixing any depreciations in fixtures feature

This commit is contained in:
Mathieu Jaumotte 2021-01-14 18:57:02 +01:00
parent 3d02785da2
commit e053bf999e
2 changed files with 34 additions and 19 deletions

View File

@ -30,9 +30,9 @@ use Symfony\Component\HttpFoundation\RequestStack;
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer;
use Symfony\Bridge\Twig\TwigEngine;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
*
@ -60,9 +60,16 @@ class CustomFieldChoice extends AbstractCustomField
* @var TranslatableStringHelper Helper that find the string in current locale from an array of translation
*/
private $translatableStringHelper;
/**
* CustomFieldChoice constructor.
*
* @param TranslatorInterface $translator
* @param TwigEngine $templating
* @param TranslatableStringHelper $translatableStringHelper
*/
public function __construct(
Translator $translator,
TranslatorInterface $translator,
TwigEngine $templating,
TranslatableStringHelper $translatableStringHelper)
{

View File

@ -66,10 +66,23 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface
public function load(ObjectManager $manager)
{
echo "Loading Options \n";
// load companies
$this->loadingCompanies($manager);
$this->loadingWords($manager);
// 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);
$manager->flush();
@ -98,6 +111,7 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface
->setKey('word')
;
$manager->persist($parent);
//Load children
$expected_nb_children = rand(10, 50);
for ($i=0; $i < $expected_nb_children; $i++) {
@ -111,7 +125,7 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface
}
private function loadingCompanies(\Doctrine\Persistence\ObjectManager $manager)
{
{
echo "Loading companies \n";
$companiesParents = array(
array(
@ -134,32 +148,26 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface
foreach ($companiesParents as $text) {
// sf4 check: erreur non résolue ici avec $text: In PDOStatement.php line 81: Notice: Array to string conversion
//
// et avec error_reporting(0):
// An exception occurred while executing 'INSERT INTO custom_field_long_choice_options (id, key, text, internal_key, active, parent_id) VALUES (?, ?, ?, ?, ?, ?)' with params [1304, "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
$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(
$manager->persist(
$this->createChildOption($parent, array(
'fr' => $companyName,
'nl' => $companyName,
'en' => $companyName
)));
}
}
}