Completed
Pull Request — master (#347)
by Maxence
02:15
created

Version0017Date20191206144441::changeSchema()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 9.328
c 0
b 0
f 0
cc 4
nc 8
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
		if (!$table->hasColumn('contact_groupname')) {
73
			$table->addColumn(
74
				'contact_groupname', 'string', [
75
									   'notnull' => false,
76
									   'length'  => 127,
77
								   ]
78
			);
79
		}
80
81
		$table = $schema->getTable('circles_members');
82
		if (!$table->hasColumn('contact_id')) {
83
			$table->addColumn(
84
				'contact_id', 'string', [
85
								'notnull' => false,
86
								'length'  => 127,
87
							]
88
			);
89
			$table->dropPrimaryKey();
90
			$table->setPrimaryKey(['circle_id', 'user_id', 'contact_id']);
91
		}
92
93
		return $schema;
94
	}
95
96
	/**
97
	 * @param IOutput $output
98
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
99
	 * @param array $options
100
	 */
101
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
102
	}
103
}
104