Passed
Push — master ( d578ca...a531df )
by Yannick
09:55
created

Version20240310160200   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 33 1
A getDescription() 0 3 1
1
<?php
2
3
4
declare(strict_types=1);
5
6
/* For licensing terms, see /license.txt */
7
8
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
9
10
use Chamilo\CoreBundle\Entity\User;
11
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
12
use Chamilo\CoreBundle\Repository\Node\UserRepository;
13
use Doctrine\DBAL\Schema\Schema;
14
15
class Version20240310160200 extends AbstractMigrationChamilo
16
{
17
    public function getDescription(): string
18
    {
19
        return 'Adds a fallback user to the user table.';
20
    }
21
22
    public function up(Schema $schema): void
23
    {
24
        $container = $this->getContainer();
25
        $doctrine = $container->get('doctrine');
26
27
        $em = $doctrine->getManager();
28
29
        /* @var UserRepository $repo*/
30
        $repo = $container->get(UserRepository::class);
31
32
        $plainPassword = 'fallback_user';
33
        $encodedPassword = password_hash($plainPassword, PASSWORD_DEFAULT);
34
35
        $fallbackUser = new User();
36
        $fallbackUser
37
            ->setUsername('fallback_user')
38
            ->setEmail('[email protected]')
39
            ->setPassword($encodedPassword)
40
            ->setCreatorId(1)
41
            ->setStatus(User::ROLE_FALLBACK)
42
            ->setLastname('Fallback')
43
            ->setFirstname('User')
44
            ->setOfficialCode('FALLBACK')
45
            ->setAuthSource('platform')
46
            ->setPhone('0000000000')
47
            ->setLocale('en')
48
            ->setActive(User::SOFT_DELETED)
49
            ->setTimezone('UTC');
50
        $em->flush();
51
52
        error_log($fallbackUser->getFullname());
53
54
        $repo->updateUser($fallbackUser);
55
    }
56
}
57