|
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
|
|
|
|