Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
63.33% |
38 / 60 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Migration405 | |
63.33% |
38 / 60 |
|
75.00% |
3 / 4 |
11.15 | |
0.00% |
0 / 1 |
| getVersion | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDependencies | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDescription | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| up | |
61.40% |
35 / 57 |
|
0.00% |
0 / 1 |
6.44 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Migration for phpMyFAQ 4.0.5. |
| 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 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Setup\Migration\Versions; |
| 21 | |
| 22 | use phpMyFAQ\Setup\Migration\AbstractMigration; |
| 23 | use phpMyFAQ\Setup\Migration\Operations\OperationRecorder; |
| 24 | |
| 25 | readonly class Migration405 extends AbstractMigration |
| 26 | { |
| 27 | public function getVersion(): string |
| 28 | { |
| 29 | return '4.0.5'; |
| 30 | } |
| 31 | |
| 32 | public function getDependencies(): array |
| 33 | { |
| 34 | return ['4.0.0-beta.2']; |
| 35 | } |
| 36 | |
| 37 | public function getDescription(): string |
| 38 | { |
| 39 | return 'Remove old section permissions, increase forms input_label column'; |
| 40 | } |
| 41 | |
| 42 | public function up(OperationRecorder $recorder): void |
| 43 | { |
| 44 | // Delete old permissions |
| 45 | $recorder->addSql( |
| 46 | sprintf("DELETE FROM %sfaqright WHERE name = 'view_sections'", $this->tablePrefix), |
| 47 | 'Delete view_sections permission', |
| 48 | ); |
| 49 | |
| 50 | $recorder->addSql( |
| 51 | sprintf("DELETE FROM %sfaqright WHERE name = 'add_section'", $this->tablePrefix), |
| 52 | 'Delete add_section permission', |
| 53 | ); |
| 54 | |
| 55 | $recorder->addSql( |
| 56 | sprintf("DELETE FROM %sfaqright WHERE name = 'edit_section'", $this->tablePrefix), |
| 57 | 'Delete edit_section permission', |
| 58 | ); |
| 59 | |
| 60 | $recorder->addSql( |
| 61 | sprintf("DELETE FROM %sfaqright WHERE name = 'delete_section'", $this->tablePrefix), |
| 62 | 'Delete delete_section permission', |
| 63 | ); |
| 64 | |
| 65 | // Update faqforms table - increase input_label size |
| 66 | if ($this->isMySql()) { |
| 67 | $recorder->addSql( |
| 68 | sprintf( |
| 69 | 'ALTER TABLE %sfaqforms CHANGE input_label input_label VARCHAR(500) NOT NULL', |
| 70 | $this->tablePrefix, |
| 71 | ), |
| 72 | 'Increase faqforms.input_label column size (MySQL)', |
| 73 | ); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | if ($this->isPostgreSql()) { |
| 78 | $recorder->addSql( |
| 79 | sprintf('ALTER TABLE %sfaqforms ALTER COLUMN input_label TYPE VARCHAR(500)', $this->tablePrefix), |
| 80 | 'Increase faqforms.input_label column size (PostgreSQL part 1)', |
| 81 | ); |
| 82 | |
| 83 | $recorder->addSql( |
| 84 | sprintf('ALTER TABLE %sfaqforms ALTER COLUMN input_label SET NOT NULL', $this->tablePrefix), |
| 85 | 'Increase faqforms.input_label column size (PostgreSQL part 2)', |
| 86 | ); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | if ($this->isSqlite()) { |
| 91 | // SQLite requires table rebuild |
| 92 | $recorder->addSql( |
| 93 | sprintf('ALTER TABLE %sfaqforms RENAME TO %sfaqforms_old', $this->tablePrefix, $this->tablePrefix), |
| 94 | 'Rename faqforms table (SQLite)', |
| 95 | ); |
| 96 | |
| 97 | $recorder->addSql(sprintf('CREATE TABLE %sfaqforms ( |
| 98 | form_id INTEGER NOT NULL, |
| 99 | input_id INTEGER NOT NULL, |
| 100 | input_type VARCHAR(1000) NOT NULL, |
| 101 | input_label VARCHAR(500) NOT NULL, |
| 102 | input_active INTEGER NOT NULL, |
| 103 | input_required INTEGER NOT NULL, |
| 104 | input_lang VARCHAR(11) NOT NULL |
| 105 | )', $this->tablePrefix), 'Create new faqforms table (SQLite)'); |
| 106 | |
| 107 | $recorder->addSql( |
| 108 | sprintf('INSERT INTO %sfaqforms |
| 109 | SELECT |
| 110 | form_id, input_id, input_type, input_label, input_active, input_required, input_lang |
| 111 | FROM %sfaqforms_old', $this->tablePrefix, $this->tablePrefix), |
| 112 | 'Copy data to new faqforms table (SQLite)', |
| 113 | ); |
| 114 | |
| 115 | $recorder->addSql( |
| 116 | sprintf('DROP TABLE %sfaqforms_old', $this->tablePrefix), |
| 117 | 'Drop old faqforms table (SQLite)', |
| 118 | ); |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | if ($this->isSqlServer()) { |
| 123 | $recorder->addSql( |
| 124 | sprintf('ALTER TABLE %sfaqforms ALTER COLUMN input_label NVARCHAR(500) NOT NULL', $this->tablePrefix), |
| 125 | 'Increase faqforms.input_label column size (SQL Server)', |
| 126 | ); |
| 127 | } |
| 128 | } |
| 129 | } |