Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
54 / 54
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Migration407
100.00% covered (success)
100.00%
54 / 54
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 getVersion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDependencies
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDescription
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 up
100.00% covered (success)
100.00%
51 / 51
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3/**
4 * Migration for phpMyFAQ 4.0.7.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2023-2026 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2026-01-25
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Setup\Migration\Versions;
21
22use phpMyFAQ\Setup\Migration\AbstractMigration;
23use phpMyFAQ\Setup\Migration\Operations\OperationRecorder;
24
25readonly class Migration407 extends AbstractMigration
26{
27    public function getVersion(): string
28    {
29        return '4.0.7';
30    }
31
32    public function getDependencies(): array
33    {
34        return ['4.0.5'];
35    }
36
37    public function getDescription(): string
38    {
39        return 'Fix language codes for fr_CA and pt_BR';
40    }
41
42    public function up(OperationRecorder $recorder): void
43    {
44        // Define the table/column mappings for language code fixes
45        $languageUpdates = [
46            ['table' => 'faqattachment', 'column' => 'record_lang'],
47            ['table' => 'faqcaptcha', 'column' => 'language'],
48            ['table' => 'faqcategories', 'column' => 'lang'],
49            ['table' => 'faqdata', 'column' => 'lang'],
50            ['table' => 'faqcategoryrelations', 'column' => 'category_lang'],
51            ['table' => 'faqcategoryrelations', 'column' => 'record_lang'],
52            ['table' => 'faqchanges', 'column' => 'lang'],
53            ['table' => 'faqdata_revisions', 'column' => 'lang'],
54            ['table' => 'faqglossary', 'column' => 'lang'],
55            ['table' => 'faqnews', 'column' => 'lang'],
56            ['table' => 'faqquestions', 'column' => 'lang'],
57            ['table' => 'faqsearches', 'column' => 'lang'],
58            ['table' => 'faqvisits', 'column' => 'lang'],
59        ];
60
61        // Update fr-ca to fr_ca
62        foreach ($languageUpdates as $update) {
63            $recorder->addSql(
64                sprintf(
65                    "UPDATE %s%s SET %s='fr_ca' WHERE %s='fr-ca'",
66                    $this->tablePrefix,
67                    $update['table'],
68                    $update['column'],
69                    $update['column'],
70                ),
71                sprintf('Fix fr-ca -> fr_ca in %s.%s', $update['table'], $update['column']),
72            );
73        }
74
75        // Update fr-ca language file reference in faqconfig
76        $recorder->addSql(
77            sprintf(
78                "UPDATE %sfaqconfig SET config_value='language_fr_ca.php' WHERE config_value='language_fr-ca.php'",
79                $this->tablePrefix,
80            ),
81            'Fix fr-ca language file config reference',
82        );
83
84        // Update pt-br to pt_br
85        foreach ($languageUpdates as $update) {
86            $recorder->addSql(
87                sprintf(
88                    "UPDATE %s%s SET %s='pt_br' WHERE %s='pt-br'",
89                    $this->tablePrefix,
90                    $update['table'],
91                    $update['column'],
92                    $update['column'],
93                ),
94                sprintf('Fix pt-br -> pt_br in %s.%s', $update['table'], $update['column']),
95            );
96        }
97
98        // Update pt-br language file reference in faqconfig
99        $recorder->addSql(
100            sprintf(
101                "UPDATE %sfaqconfig SET config_value='language_pt_br.php' WHERE config_value='language_pt-br.php'",
102                $this->tablePrefix,
103            ),
104            'Fix pt-br language file config reference',
105        );
106    }
107}