mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-26 08:35:00 +00:00
Fix fixtures
- Inject parameters directly instead of getting from container - User PasswordHasher instead of EncoderFactory - set parameters directly and correctly encode values to json
This commit is contained in:
@@ -16,6 +16,7 @@ use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
|
||||
|
||||
/**
|
||||
@@ -23,6 +24,11 @@ use Doctrine\Persistence\ObjectManager;
|
||||
*/
|
||||
class LoadCountries extends Fixture implements OrderedFixtureInterface
|
||||
{
|
||||
private array $availableLanguages;
|
||||
public function __construct(private readonly ParameterBagInterface $parameterBag)
|
||||
{
|
||||
$this->availableLanguages = $this->parameterBag->get('chill_main.available_languages');
|
||||
}
|
||||
public function getOrder(): int
|
||||
{
|
||||
return 20;
|
||||
@@ -32,7 +38,7 @@ class LoadCountries extends Fixture implements OrderedFixtureInterface
|
||||
{
|
||||
echo "loading countries... \n";
|
||||
|
||||
$languages = $this->container->getParameter('chill_main.available_languages');
|
||||
$languages = $this->availableLanguages;
|
||||
|
||||
foreach (LoadCountriesCommand::prepareCountryList($languages) as $country) {
|
||||
$manager->persist($country);
|
||||
|
@@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\Language;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
|
||||
/**
|
||||
* Load languages into database.
|
||||
@@ -29,6 +30,12 @@ class LoadLanguages extends Fixture implements OrderedFixtureInterface
|
||||
// This array contains regional code to not exclude
|
||||
private array $regionalVersionToInclude = ['ro_MD'];
|
||||
|
||||
private array $availableLanguages;
|
||||
public function __construct(private readonly ParameterBagInterface $parameterBag)
|
||||
{
|
||||
$this->availableLanguages = $this->parameterBag->get('chill_main.available_languages');
|
||||
}
|
||||
|
||||
public function getOrder(): int
|
||||
{
|
||||
return 10;
|
||||
@@ -62,7 +69,7 @@ class LoadLanguages extends Fixture implements OrderedFixtureInterface
|
||||
{
|
||||
$names = [];
|
||||
|
||||
foreach ($this->container->getParameter('chill_main.available_languages') as $lang) {
|
||||
foreach ($this->availableLanguages as $lang) {
|
||||
$names[$lang] = \Symfony\Component\Intl\Languages::getName($languageCode, $lang);
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
|
||||
/**
|
||||
* Load fixtures users into database.
|
||||
@@ -53,6 +53,14 @@ class LoadUsers extends Fixture implements OrderedFixtureInterface
|
||||
'centerB_permission_group_social', ],
|
||||
],
|
||||
];
|
||||
|
||||
private UserPasswordHasherInterface $passwordHasher;
|
||||
|
||||
public function __construct(UserPasswordHasherInterface $passwordHasher)
|
||||
{
|
||||
$this->passwordHasher = $passwordHasher;
|
||||
}
|
||||
|
||||
public function getOrder(): int
|
||||
{
|
||||
return 1000;
|
||||
@@ -74,17 +82,11 @@ class LoadUsers extends Fixture implements OrderedFixtureInterface
|
||||
|
||||
$defaultEncoder = new \Symfony\Component\PasswordHasher\Hasher\MessageDigestPasswordHasher('sha512', true, 5000);
|
||||
|
||||
$encoderFactory = new EncoderFactory([
|
||||
User::class => $defaultEncoder,
|
||||
]);
|
||||
$hashedPassword = $this->passwordHasher->hashPassword($user, 'password');
|
||||
|
||||
$user
|
||||
->setUsername($username)
|
||||
->setPassword(
|
||||
$encoderFactory
|
||||
->getEncoder($user)
|
||||
->encodePassword('password', $user->getSalt())
|
||||
)
|
||||
->setPassword($hashedPassword)
|
||||
->setEmail(sprintf('%s@chill.social', \str_replace(' ', '', (string) $username)));
|
||||
|
||||
foreach ($params['groupCenterRefs'] as $groupCenterRef) {
|
||||
|
@@ -52,12 +52,12 @@ class LoadCustomFields extends AbstractFixture implements OrderedFixtureInterfac
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
private function createCustomFieldChoice(): \Chill\CustomFieldsBundle\CustomFields\CustomFieldChoice
|
||||
private function createCustomFieldChoice(): CustomFieldChoice
|
||||
{
|
||||
return $this->customFieldChoice;
|
||||
}
|
||||
|
||||
private function createCustomFieldText(): \Chill\CustomFieldsBundle\CustomFields\CustomFieldText
|
||||
private function createCustomFieldText(): CustomFieldText
|
||||
{
|
||||
return $this->customFieldText;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class LoadCustomFields extends AbstractFixture implements OrderedFixtureInterfac
|
||||
private function loadData(ObjectManager $manager): void
|
||||
{
|
||||
$personIds = $this->entityManager
|
||||
->createQuery('SELECT person.id FROM ChillPersonBundle:Person person')
|
||||
->createQuery('SELECT person.id FROM '.Person::class.' person')
|
||||
->getScalarResult();
|
||||
|
||||
// get possible values for cfGroup
|
||||
|
@@ -84,20 +84,9 @@ final readonly class SocialWorkMetadata implements SocialWorkMetadataInterface
|
||||
$temporaryJsonCriterias[] = [$field, $key, $value, sprintf(':placeholder_%s_%s', $field, $key)];
|
||||
}
|
||||
|
||||
$jsonParameters = array_reduce(
|
||||
$temporaryJsonCriterias,
|
||||
static function (array $carry, array $row): array {
|
||||
[,, $value, $placeholder] = $row;
|
||||
|
||||
return array_merge(
|
||||
$carry,
|
||||
[
|
||||
$placeholder => sprintf('"%s"', $value),
|
||||
]
|
||||
);
|
||||
},
|
||||
[]
|
||||
);
|
||||
foreach ($temporaryJsonCriterias as [$field, $key, $value, $placeholder]) {
|
||||
$qb->setParameter(ltrim($placeholder, ':'), json_encode($value));
|
||||
}
|
||||
|
||||
$jsonPredicates = array_map(
|
||||
static function (array $row) use ($expr): Comparison {
|
||||
@@ -121,7 +110,7 @@ final readonly class SocialWorkMetadata implements SocialWorkMetadataInterface
|
||||
return $qb
|
||||
->select('s')
|
||||
->where(...$jsonPredicates)
|
||||
->setParameters($jsonParameters)
|
||||
// ->setParameters($jsonParameters)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
Reference in New Issue
Block a user