|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\DataFixtures; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\AccessUrl; |
|
10
|
|
|
use Chamilo\CoreBundle\Entity\User; |
|
11
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture; |
|
12
|
|
|
use Doctrine\Persistence\ObjectManager; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
15
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
|
16
|
|
|
|
|
17
|
|
|
class AccessUserUrlFixtures extends Fixture implements ContainerAwareInterface |
|
18
|
|
|
{ |
|
19
|
|
|
private ContainerInterface $container; |
|
20
|
|
|
|
|
21
|
|
|
public function setContainer(ContainerInterface $container = null): void |
|
22
|
|
|
{ |
|
23
|
|
|
$this->container = $container; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function load(ObjectManager $manager): void |
|
27
|
|
|
{ |
|
28
|
|
|
$container = $this->container; |
|
29
|
|
|
/** @var User $admin */ |
|
30
|
|
|
$admin = $this->getReference(AccessUserFixtures::ADMIN_USER_REFERENCE); |
|
31
|
|
|
$anon = $this->getReference(AccessUserFixtures::ANON_USER_REFERENCE); |
|
32
|
|
|
|
|
33
|
|
|
// Login as admin |
|
34
|
|
|
$token = new UsernamePasswordToken( |
|
35
|
|
|
$admin, |
|
36
|
|
|
$admin->getPassword(), |
|
37
|
|
|
'public', |
|
38
|
|
|
$admin->getRoles() |
|
39
|
|
|
); |
|
40
|
|
|
$container->get('security.token_storage')->setToken($token); |
|
41
|
|
|
// retrieve the test user |
|
42
|
|
|
|
|
43
|
|
|
// simulate $testUser being logged in |
|
44
|
|
|
/*$client = static::createClient(); |
|
45
|
|
|
$client->loginUser($admin);*/ |
|
46
|
|
|
|
|
47
|
|
|
$accessUrl = (new AccessUrl()) |
|
48
|
|
|
->setUrl(AccessUrl::DEFAULT_ACCESS_URL) |
|
49
|
|
|
->setDescription('') |
|
50
|
|
|
->setActive(1) |
|
51
|
|
|
->setCreatedBy(1) |
|
52
|
|
|
; |
|
53
|
|
|
|
|
54
|
|
|
$manager->persist($accessUrl); |
|
55
|
|
|
$manager->flush(); |
|
56
|
|
|
|
|
57
|
|
|
$accessUrl->addUser($admin); |
|
58
|
|
|
$accessUrl->addUser($anon); |
|
59
|
|
|
$manager->flush(); |
|
60
|
|
|
|
|
61
|
|
|
$this->addReference(AccessUserFixtures::ACCESS_URL_REFERENCE, $accessUrl); |
|
62
|
|
|
|
|
63
|
|
|
$settingsManager = $container->get('chamilo.settings.manager'); |
|
64
|
|
|
$settingsManager->installSchemas($accessUrl); |
|
65
|
|
|
|
|
66
|
|
|
$manager->flush(); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|