|
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\Migrations\AbstractMigrationChamilo; |
|
10
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
11
|
|
|
|
|
12
|
|
|
final class Version20240713125400 extends AbstractMigrationChamilo |
|
13
|
|
|
{ |
|
14
|
|
|
public function getDescription(): string |
|
15
|
|
|
{ |
|
16
|
|
|
return 'Replace ROLE_RRHH with ROLE_HR in user.roles'; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function up(Schema $schema): void |
|
20
|
|
|
{ |
|
21
|
|
|
$conn = $this->connection; |
|
22
|
|
|
|
|
23
|
|
|
$users = $conn->fetchAllAssociative("SELECT id, roles FROM user WHERE roles LIKE '%ROLE_RRHH%'"); |
|
24
|
|
|
|
|
25
|
|
|
foreach ($users as $user) { |
|
26
|
|
|
$roles = unserialize($user['roles']); |
|
27
|
|
|
|
|
28
|
|
|
if ($roles !== false) { |
|
29
|
|
|
$updatedRoles = array_map(function ($role) { |
|
30
|
|
|
return $role === 'ROLE_RRHH' ? 'ROLE_HR' : $role; |
|
31
|
|
|
}, $roles); |
|
32
|
|
|
|
|
33
|
|
|
$newRolesSerialized = serialize($updatedRoles); |
|
34
|
|
|
$conn->executeUpdate( |
|
35
|
|
|
'UPDATE user SET roles = ? WHERE id = ?', |
|
36
|
|
|
[$newRolesSerialized, $user['id']] |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function down(Schema $schema): void |
|
44
|
|
|
{ |
|
45
|
|
|
$conn = $this->connection; |
|
46
|
|
|
|
|
47
|
|
|
$users = $conn->fetchAllAssociative("SELECT id, roles FROM user WHERE roles LIKE '%ROLE_HR%'"); |
|
48
|
|
|
|
|
49
|
|
|
foreach ($users as $user) { |
|
50
|
|
|
$roles = unserialize($user['roles']); |
|
51
|
|
|
|
|
52
|
|
|
if ($roles !== false) { |
|
53
|
|
|
$updatedRoles = array_map(function ($role) { |
|
54
|
|
|
return $role === 'ROLE_HR' ? 'ROLE_RRHH' : $role; |
|
55
|
|
|
}, $roles); |
|
56
|
|
|
|
|
57
|
|
|
$newRolesSerialized = serialize($updatedRoles); |
|
58
|
|
|
|
|
59
|
|
|
$conn->executeUpdate( |
|
60
|
|
|
'UPDATE user SET roles = ? WHERE id = ?', |
|
61
|
|
|
[$newRolesSerialized, $user['id']] |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|