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

Version0021Date20210105123456   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 89
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B changeSchema() 0 64 3
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Circles - Bring cloud-users closer together.
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2021
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
namespace OCA\Circles\Migration;
31
32
use Closure;
33
use Doctrine\DBAL\Schema\SchemaException;
34
use OCP\DB\ISchemaWrapper;
35
use OCP\IDBConnection;
36
use OCP\Migration\IOutput;
37
use OCP\Migration\SimpleMigrationStep;
38
39
40
/**
41
 * Class Version0021Date20210105123456
42
 *
43
 * @package OCA\Circles\Migration
44
 */
45
class Version0021Date20210105123456 extends SimpleMigrationStep {
46
47
48
	/** @var IDBConnection */
49
	private $connection;
50
51
52
	/**
53
	 * @param IDBConnection $connection
54
	 */
55
	public function __construct(IDBConnection $connection) {
56
		$this->connection = $connection;
57
	}
58
59
60
	/**
61
	 * @param IOutput $output
62
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
63
	 * @param array $options
64
	 *
65
	 * @return null|ISchemaWrapper
66
	 */
67
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
68
		/** @var ISchemaWrapper $schema */
69
		$schema = $schemaClosure();
70
71
		try {
72
			$circles = $schema->getTable('circle_circles');
73
			$circles->addColumn(
74
				'config', 'integer', [
75
								 'notnull'  => false,
76
								 'length'   => 11,
77
								 'unsigned' => true,
78
							 ]
79
			);
80
			$circles->addIndex(['config']);
81
		} catch (SchemaException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
Bug introduced by
The class Doctrine\DBAL\Schema\SchemaException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
82
		}
83
84
		if (!$schema->hasTable('circle_remotes')) {
85
			$table = $schema->createTable('circle_remotes');
86
			$table->addColumn(
87
				'id', 'integer', [
88
						'autoincrement' => true,
89
						'notnull'       => true,
90
						'length'        => 4,
91
						'unsigned'      => true,
92
					]
93
			);
94
			$table->addColumn(
95
				'uid', 'string', [
96
						 'notnull' => false,
97
						 'length'  => 20,
98
					 ]
99
			);
100
			$table->addColumn(
101
				'instance', 'string', [
102
							  'notnull' => false,
103
							  'length'  => 127,
104
						  ]
105
			);
106
			$table->addColumn(
107
				'href', 'string', [
108
						  'notnull' => false,
109
						  'length'  => 254,
110
					  ]
111
			);
112
			$table->addColumn(
113
				'item', 'text', [
114
						  'notnull' => false,
115
					  ]
116
			);
117
			$table->addColumn(
118
				'creation', 'datetime', [
119
							  'notnull' => false,
120
						  ]
121
			);
122
123
			$table->setPrimaryKey(['id']);
124
			$table->addUniqueIndex(['instance']);
125
			$table->addIndex(['uid']);
126
			$table->addIndex(['href']);
127
		}
128
129
		return $schema;
130
	}
131
132
133
}
134