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