|
1 | 1 | <?php |
| 2 | + |
2 | 3 | declare(strict_types=1); |
| 4 | + |
3 | 5 | /** |
4 | 6 | * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
5 | 7 | * SPDX-License-Identifier: AGPL-3.0-or-later |
6 | 8 | */ |
| 9 | + |
7 | 10 | namespace OCA\Forms\Migration; |
| 11 | + |
8 | 12 | use Closure; |
9 | 13 | use OCP\DB\ISchemaWrapper; |
10 | 14 | use OCP\DB\Types; |
| 15 | +use OCP\IDBConnection; |
11 | 16 | use OCP\Migration\IOutput; |
12 | 17 | use OCP\Migration\SimpleMigrationStep; |
| 18 | + |
13 | 19 | class Version050300Date20250914000000 extends SimpleMigrationStep { |
| 20 | + |
| 21 | + public function __construct( |
| 22 | + protected IDBConnection $db, |
| 23 | + ) { |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @param IOutput $output |
| 28 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
| 29 | + * @param array $options |
| 30 | + * @return null|ISchemaWrapper |
| 31 | + */ |
14 | 32 | public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
15 | 33 | /** @var ISchemaWrapper $schema */ |
16 | 34 | $schema = $schemaClosure(); |
17 | | - $table = $schema->getTable('forms_v2_forms'); |
18 | | - if (!$table->hasColumn('max_submissions')) { |
19 | | - $table->addColumn('max_submissions', Types::INTEGER, [ |
20 | | - 'notnull' => false, |
21 | | - 'default' => null, |
22 | | - 'comment' => 'Maximum number of submissions, null means unlimited', |
23 | | - ]); |
24 | | - } |
25 | | - $tableOptions = $schema->getTable('forms_v2_options'); |
26 | | - if (!$tableOptions->hasColumn('option_type')) { |
27 | | - $tableOptions->addColumn('option_type', Types::STRING, [ |
| 35 | + $table = $schema->getTable('forms_v2_options'); |
| 36 | + |
| 37 | + if (!$table->hascolumn('option_type')) { |
| 38 | + $table->addColumn('option_type', Types::STRING, [ |
28 | 39 | 'notnull' => false, |
29 | 40 | 'default' => null, |
30 | | - 'length' => 64, |
31 | 41 | ]); |
32 | 42 | } |
| 43 | + |
33 | 44 | return $schema; |
34 | 45 | } |
| 46 | + |
| 47 | + /** |
| 48 | + * @param IOutput $output |
| 49 | + * @param Closure(): ISchemaWrapper $schemaClosure |
| 50 | + * @param array $options |
| 51 | + */ |
| 52 | + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { |
| 53 | + $qbUpdate = $this->db->getQueryBuilder(); |
| 54 | + |
| 55 | + $qbUpdate->update('forms_v2_options') |
| 56 | + ->set('option_type', $qbUpdate->createNamedParameter('choice')) |
| 57 | + ->where($qbUpdate->expr()->isNull('option_type')) |
| 58 | + ->executeStatement(); |
| 59 | + } |
35 | 60 | } |
0 commit comments