Completed
Pull Request — master (#347)
by Maxence
01:45
created

Version0017Date20191206144441::changeSchema()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 45

Duplication

Lines 16
Ratio 35.56 %

Importance

Changes 0
Metric Value
dl 16
loc 45
rs 8.8888
c 0
b 0
f 0
cc 5
nc 16
nop 3
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2019
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
declare(strict_types=1);
28
29
namespace OCA\Circles\Migration;
30
31
use Closure;
32
use Doctrine\DBAL\Schema\SchemaException;
33
use OCP\DB\ISchemaWrapper;
34
use OCP\Migration\IOutput;
35
use OCP\Migration\SimpleMigrationStep;
36
37
/**
38
 * Auto-generated migration step: Please modify to your needs!
39
 */
40
class Version0017Date20191206144441 extends SimpleMigrationStep {
41
42
	/**
43
	 * @param IOutput $output
44
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
45
	 * @param array $options
46
	 */
47
	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
48
	}
49
50
	/**
51
	 * @param IOutput $output
52
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
53
	 * @param array $options
54
	 *
55
	 * @return null|ISchemaWrapper
56
	 * @throws SchemaException
57
	 */
58
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
59
		/** @var ISchemaWrapper $schema */
60
		$schema = $schemaClosure();
61
62
		$table = $schema->getTable('circles_circles');
63
		if (!$table->hasColumn('contact_addressbook')) {
64
			$table->addColumn(
65
				'contact_addressbook', 'integer', [
66
										 'notnull'  => false,
67
										 'unsigned' => true,
68
										 'length'   => 7,
69
									 ]
70
			);
71
		}
72 View Code Duplication
		if (!$table->hasColumn('contact_groupname')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
			$table->addColumn(
74
				'contact_groupname', 'string', [
75
									   'notnull' => false,
76
									   'length'  => 127,
77
								   ]
78
			);
79
		}
80
81
		$table = $schema->getTable('circles_members');
82 View Code Duplication
		if (!$table->hasColumn('contact_meta')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
			$table->addColumn(
84
				'contact_meta', 'string', [
85
								'notnull' => false,
86
								'length'  => 1000,
87
							]
88
			);
89
		}
90
		if (!$table->hasColumn('contact_id')) {
91
			$table->addColumn(
92
				'contact_id', 'string', [
93
								'notnull' => false,
94
								'length'  => 127,
95
							]
96
			);
97
			$table->dropPrimaryKey();
98
			$table->setPrimaryKey(['circle_id', 'user_id', 'contact_id']);
99
		}
100
101
		return $schema;
102
	}
103
104
	/**
105
	 * @param IOutput $output
106
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
107
	 * @param array $options
108
	 */
109
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
110
	}
111
}
112