Completed
Pull Request — master (#461)
by Maxence
01:52
created

Version0019Date20200713184401::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
30
namespace OCA\Circles\Migration;
31
32
33
use Closure;
34
use Doctrine\DBAL\Schema\SchemaException;
35
use OCP\DB\ISchemaWrapper;
36
use OCP\IDBConnection;
37
use OCP\Migration\IOutput;
38
use OCP\Migration\SimpleMigrationStep;
39
40
41
/**
42
 * Class Version0019Date20200713184401
43
 *
44
 * @package OCA\Circles\Migration
45
 */
46
class Version0019Date20200713184401 extends SimpleMigrationStep {
47
48
49
	/** @var IDBConnection */
50
	private $connection;
51
52
53
	/**
54
	 * @param IDBConnection $connection
55
	 */
56
	public function __construct(IDBConnection $connection) {
57
		$this->connection = $connection;
58
	}
59
60
61
	/**
62
	 * @param IOutput $output
63
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
64
	 * @param array $options
65
	 *
66
	 * @return null|ISchemaWrapper
67
	 * @throws SchemaException
68
	 */
69
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
70
		/** @var ISchemaWrapper $schema */
71
		$schema = $schemaClosure();
72
73
		if ($schema->hasTable('circle_members')) {
74
			$table = $schema->getTable('circle_members');
75
			if (!$table->hasColumn('cached_name')) {
76
				$table->addColumn(
77
					'cached_name', 'string', [
78
									  'notnull' => true,
79
									  'length'  => 255,
80
									  'default' => ''
81
								  ]
82
				);
83
			}
84
		}
85
86
		return $schema;
87
	}
88
89
}
90