Passed
Pull Request — master (#6357)
by
unknown
10:25
created

Version20250612070100::up()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 33
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 14
nc 2
nop 1
dl 0
loc 33
rs 9.7998
c 1
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
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 Version20250612070100 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Replace per-profile login redirection settings with a unified redirect_after_login JSON setting';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        // Remove deprecated per-role login redirection settings
22
        $this->connection->executeStatement("
23
            DELETE FROM settings
24
            WHERE variable IN (
25
                'page_after_login',
26
                'student_page_after_login',
27
                'teacher_page_after_login',
28
                'drh_page_after_login',
29
                'sessionadmin_page_after_login'
30
            )
31
        ");
32
33
        // Create the new setting only if it does not exist, with no default value
34
        $existing = $this->connection->fetchOne("
35
            SELECT COUNT(*)
36
            FROM settings
37
            WHERE variable = 'redirect_after_login'
38
        ");
39
40
        if ($existing == 0) {
41
            $this->connection->insert('settings', [
42
                'variable' => 'redirect_after_login',
43
                'type' => 'textfield',
44
                'category' => 'registration',
45
                'selected_value' => '',
46
                'title' => 'Redirect after login (per profile)',
47
                'comment' => 'Define redirection per profile after login using a JSON object',
48
                'scope' => null,
49
                'access_url' => 1,
50
                'access_url_changeable' => 0,
51
                'access_url_locked' => 0,
52
            ]);
53
        }
54
    }
55
}
56