mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-03 20:09:42 +00:00
108 lines
3.5 KiB
PHP
108 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\MainBundle\DataFixtures\ORM;
|
|
|
|
use Chill\MainBundle\Entity\Center;
|
|
use Chill\MainBundle\Entity\GroupCenter;
|
|
use Chill\MainBundle\Entity\PermissionsGroup;
|
|
use Chill\MainBundle\Entity\RoleScope;
|
|
use Chill\MainBundle\Entity\User;
|
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
|
use Doctrine\Persistence\ObjectManager;
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
|
|
/**
|
|
* Load fixtures users into database.
|
|
*
|
|
* create a user for each permission_group and center.
|
|
* username and password are identicals.
|
|
*/
|
|
class LoadUsers extends Fixture implements OrderedFixtureInterface
|
|
{
|
|
public static $refs = [
|
|
'center a_social' => [
|
|
'groupCenterRefs' => ['centerA_permission_group_social'],
|
|
],
|
|
'center a_administrative' => [
|
|
'groupCenterRefs' => ['centerA_permission_group_administrative'],
|
|
],
|
|
'center a_direction' => [
|
|
'groupCenterRefs' => ['centerA_permission_group_direction'],
|
|
],
|
|
'center b_social' => [
|
|
'groupCenterRefs' => ['centerB_permission_group_social'],
|
|
],
|
|
'center b_administrative' => [
|
|
'groupCenterRefs' => ['centerB_permission_group_administrative'],
|
|
],
|
|
'center b_direction' => [
|
|
'groupCenterRefs' => ['centerB_permission_group_direction'],
|
|
],
|
|
'multi_center' => [
|
|
'groupCenterRefs' => ['centerA_permission_group_social',
|
|
'centerB_permission_group_social', ],
|
|
],
|
|
];
|
|
|
|
public function __construct(private readonly UserPasswordHasherInterface $passwordHasher)
|
|
{
|
|
}
|
|
|
|
public function getOrder(): int
|
|
{
|
|
return 1000;
|
|
}
|
|
|
|
public function load(ObjectManager $manager): void
|
|
{
|
|
$roleScope = new RoleScope();
|
|
$roleScope->setRole('CHILL_MAIN_COMPOSE_EXPORT');
|
|
$permissionGroup = new PermissionsGroup();
|
|
$permissionGroup->setName('export');
|
|
$permissionGroup->addRoleScope($roleScope);
|
|
|
|
$manager->persist($roleScope);
|
|
$manager->persist($permissionGroup);
|
|
|
|
foreach (self::$refs as $username => $params) {
|
|
$user = new User();
|
|
|
|
$defaultEncoder = new \Symfony\Component\PasswordHasher\Hasher\MessageDigestPasswordHasher('sha512', true, 5000);
|
|
|
|
$hashedPassword = $this->passwordHasher->hashPassword($user, 'password');
|
|
|
|
$user
|
|
->setUsername($username)
|
|
->setPassword($hashedPassword)
|
|
->setEmail(sprintf('%s@chill.social', \str_replace(' ', '', (string) $username)));
|
|
|
|
foreach ($params['groupCenterRefs'] as $groupCenterRef) {
|
|
$user->addGroupCenter($gc = $this->getReference($groupCenterRef, GroupCenter::class));
|
|
|
|
$exportGroupCenter = new GroupCenter();
|
|
$exportGroupCenter->setPermissionsGroup($permissionGroup);
|
|
$exportGroupCenter->setCenter($gc->getCenter());
|
|
$manager->persist($exportGroupCenter);
|
|
|
|
$user->addGroupCenter($exportGroupCenter);
|
|
}
|
|
|
|
echo 'Creating user '.$username."... \n";
|
|
$manager->persist($user);
|
|
$this->addReference($username, $user);
|
|
}
|
|
|
|
$manager->flush();
|
|
}
|
|
}
|