1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Fixture; |
4
|
|
|
|
5
|
|
|
use AppBundle\Entity\User; |
6
|
|
|
use AppBundle\EventListener\User\IdentityListener; |
7
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
8
|
|
|
use Ds\Component\Database\Fixture\ResourceFixture; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class UserFixture |
12
|
|
|
*/ |
13
|
|
|
abstract class UserFixture extends ResourceFixture |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* {@inheritdoc} |
17
|
|
|
*/ |
18
|
|
|
public function load(ObjectManager $manager) |
19
|
|
|
{ |
20
|
|
|
$metadata = $manager->getClassMetadata(User::class); |
21
|
|
|
|
22
|
|
|
foreach ($metadata->entityListeners as $event => $listeners) { |
23
|
|
|
foreach ($listeners as $key => $listener) { |
24
|
|
|
if (IdentityListener::class === $listener['class']) { |
25
|
|
|
unset($metadata->entityListeners[$event][$key]); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$connection = $manager->getConnection(); |
|
|
|
|
31
|
|
|
$platform = $connection->getDatabasePlatform()->getName(); |
32
|
|
|
|
33
|
|
|
switch ($platform) { |
34
|
|
|
case 'postgresql': |
35
|
|
|
$connection->exec('ALTER SEQUENCE app_user_id_seq RESTART WITH 1'); |
36
|
|
|
break; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$userManager = $this->container->get('fos_user.user_manager'); |
40
|
|
|
$objects = $this->parse($this->getResource()); |
41
|
|
|
|
42
|
|
|
foreach ($objects as $object) { |
43
|
|
|
$user = $userManager->createUser(); |
44
|
|
|
$user |
45
|
|
|
->setUuid($object->uuid) |
46
|
|
|
->setUsername($object->username) |
47
|
|
|
->setEmail($object->email) |
48
|
|
|
->setPlainPassword($object->password) |
49
|
|
|
->setRoles($object->roles) |
50
|
|
|
->setOwner($object->owner) |
51
|
|
|
->setOwnerUuid($object->owner_uuid) |
52
|
|
|
->setIdentity($object->identity) |
53
|
|
|
->setIdentityUuid($object->identity_uuid) |
54
|
|
|
->setEnabled($object->enabled) |
55
|
|
|
->setTenant($object->tenant); |
56
|
|
|
$userManager->updateUser($user); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|