1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
8
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\User; |
10
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
11
|
|
|
use Chamilo\CoreBundle\Repository\Node\UserRepository; |
12
|
|
|
use Doctrine\DBAL\Schema\Schema; |
13
|
|
|
|
14
|
|
|
use const PASSWORD_DEFAULT; |
15
|
|
|
|
16
|
|
|
class Version20230720142900 extends AbstractMigrationChamilo |
17
|
|
|
{ |
18
|
|
|
public function getDescription(): string |
19
|
|
|
{ |
20
|
|
|
return 'Adds a fallback user to the user table.'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function up(Schema $schema): void |
24
|
|
|
{ |
25
|
|
|
$repo = $this->container->get(UserRepository::class); |
|
|
|
|
26
|
|
|
|
27
|
|
|
// Check if fallback user already exists |
28
|
|
|
$existingFallbackUser = $repo->findOneBy(['username' => 'fallback_user']); |
29
|
|
|
|
30
|
|
|
if ($existingFallbackUser) { |
31
|
|
|
// User already exists, no need to create it again |
32
|
|
|
error_log('Fallback user already exists: ' . $existingFallbackUser->getFullname()); |
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// Create fallback user if not exists |
37
|
|
|
$plainPassword = 'fallback_user'; |
38
|
|
|
$encodedPassword = password_hash($plainPassword, PASSWORD_DEFAULT); |
39
|
|
|
|
40
|
|
|
$fallbackUser = new User(); |
41
|
|
|
$fallbackUser |
42
|
|
|
->setUsername('fallback_user') |
43
|
|
|
->setEmail('[email protected]') |
44
|
|
|
->setPassword($encodedPassword) |
45
|
|
|
->setCreatorId(1) |
46
|
|
|
->setStatus(User::ROLE_FALLBACK) |
47
|
|
|
->setLastname('Fallback') |
48
|
|
|
->setFirstname('User') |
49
|
|
|
->setOfficialCode('FALLBACK') |
50
|
|
|
->setAuthSource('platform') |
51
|
|
|
->setPhone('0000000000') |
52
|
|
|
->setLocale('en') |
53
|
|
|
->setActive(User::SOFT_DELETED) |
54
|
|
|
->setTimezone('UTC') |
55
|
|
|
; |
56
|
|
|
|
57
|
|
|
$this->entityManager->persist($fallbackUser); |
|
|
|
|
58
|
|
|
$this->entityManager->flush(); |
59
|
|
|
|
60
|
|
|
error_log('Fallback user created: ' . $fallbackUser->getFullname()); |
61
|
|
|
|
62
|
|
|
$repo->updateUser($fallbackUser); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.