Completed
Push — master ( bca2e7...1f8246 )
by Maxence
02:35 queued 11s
created

Version0022Date20220607181712::changeSchema()   B

Complexity

Conditions 7
Paths 27

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 8.2666
c 0
b 0
f 0
cc 7
nc 27
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
6
/**
7
 * Circles - Bring cloud-users closer together.
8
 *
9
 * This file is licensed under the Affero General Public License version 3 or
10
 * later. See the COPYING file.
11
 *
12
 * @author Maxence Lange <[email protected]>
13
 * @copyright 2021
14
 * @license GNU AGPL version 3 or any later version
15
 *
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
 *
29
 */
30
31
32
namespace OCA\Circles\Migration;
33
34
use Closure;
35
use Doctrine\DBAL\Schema\SchemaException;
36
use OCP\DB\ISchemaWrapper;
37
use OCP\IDBConnection;
38
use OCP\Migration\IOutput;
39
use OCP\Migration\SimpleMigrationStep;
40
41
42
/**
43
 * Class Version0022Date20220526113601
44
 *
45
 * @package OCA\Circles\Migration
46
 */
47
class Version0022Date20220607181712 extends SimpleMigrationStep {
48
49
50
	/**
51
	 * @param IDBConnection $connection
52
	 */
53
	public function __construct(IDBConnection $connection) {
54
	}
55
56
57
	/**
58
	 * @param IOutput $output
59
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
60
	 * @param array $options
61
	 *
62
	 * @return null|ISchemaWrapper
63
	 * @throws SchemaException
64
	 */
65
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
66
		/** @var ISchemaWrapper $schema */
67
		$schema = $schemaClosure();
68
69
		if ($schema->hasTable('circles_event')) {
70
			$table = $schema->getTable('circles_event');
71
			if (!$table->hasColumn('updated')) {
72
				$table->addColumn(
73
					'updated', 'datetime', [
74
								 'notnull' => false,
75
							 ]
76
				);
77
			}
78
		}
79
80
		if ($schema->hasTable('circles_member')) {
81
			$table = $schema->getTable('circles_member');
82
			if (!$table->hasColumn('invited_by')) {
83
				$table->addColumn(
84
					'invited_by', 'string', [
85
									'notnull' => false,
86
									'default' => '',
87
									'length'  => 31,
88
								]
89
				);
90
			}
91
		}
92
93
		if ($schema->hasTable('circles_circle')) {
94
			$table = $schema->getTable('circles_circle');
95
			if (!$table->hasColumn('sanitized_name')) {
96
				$table->addColumn(
97
					'sanitized_name', 'string', [
98
										'notnull' => false,
99
										'default' => '',
100
										'length'  => 127
101
									]
102
				);
103
104
				$table->addIndex(['sanitized_name']);
105
			}
106
		}
107
108
		return $schema;
109
	}
110
111
}
112
113