Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
12.50% covered (danger)
12.50%
3 / 24
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Migration400Alpha2
12.50% covered (danger)
12.50%
3 / 24
75.00% covered (warning)
75.00%
3 / 4
30.12
0.00% covered (danger)
0.00%
0 / 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
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3/**
4 * Migration for phpMyFAQ 4.0.0-alpha.2.
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 Migration400Alpha2 extends AbstractMigration
26{
27    public function getVersion(): string
28    {
29        return '4.0.0-alpha.2';
30    }
31
32    public function getDependencies(): array
33    {
34        return ['4.0.0-alpha'];
35    }
36
37    public function getDescription(): string
38    {
39        return 'Forms table and forms_edit permission';
40    }
41
42    public function up(OperationRecorder $recorder): void
43    {
44        $recorder->deleteConfig('main.optionalMailAddress');
45
46        // Add new permission for editing forms
47        $recorder->grantPermission('forms_edit', 'Right to edit forms');
48
49        // Create forms table
50        if ($this->isMySql()) {
51            $recorder->addSql(sprintf(
52                'CREATE TABLE %sfaqforms (
53                    form_id INT(1) NOT NULL,
54                    input_id INT(11) NOT NULL,
55                    input_type VARCHAR(1000) NOT NULL,
56                    input_label VARCHAR(100) NOT NULL,
57                    input_active INT(1) NOT NULL,
58                    input_required INT(1) NOT NULL,
59                    input_lang VARCHAR(11) NOT NULL,
60                    PRIMARY KEY (form_id, input_id, input_lang))',
61                $this->tablePrefix,
62            ), 'Create forms table (MySQL)');
63            return;
64        }
65
66        if ($this->isSqlServer()) {
67            $recorder->addSql(sprintf(
68                'CREATE TABLE %sfaqforms (
69                    form_id INTEGER NOT NULL,
70                    input_id INTEGER NOT NULL,
71                    input_type NVARCHAR(1000) NOT NULL,
72                    input_label NVARCHAR(100) NOT NULL,
73                    input_active INTEGER NOT NULL,
74                    input_required INTEGER NOT NULL,
75                    input_lang NVARCHAR(11) NOT NULL,
76                    PRIMARY KEY (form_id, input_id, input_lang))',
77                $this->tablePrefix,
78            ), 'Create forms table (SQL Server)');
79            return;
80        }
81
82        $recorder->addSql(sprintf(
83            'CREATE TABLE %sfaqforms (
84                form_id INTEGER NOT NULL,
85                input_id INTEGER NOT NULL,
86                input_type VARCHAR(1000) NOT NULL,
87                input_label VARCHAR(100) NOT NULL,
88                input_active INTEGER NOT NULL,
89                input_required INTEGER NOT NULL,
90                input_lang VARCHAR(11) NOT NULL,
91                PRIMARY KEY (form_id, input_id, input_lang))',
92            $this->tablePrefix,
93        ), 'Create forms table');
94
95        // Note: The form inputs insertion is handled separately through the Forms class
96        // because it requires complex business logic that varies by installation
97    }
98}