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

Version0019Date20201106110741::changeSchema()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 3
nc 3
nop 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 2019
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
31
namespace OCA\Circles\Migration;
32
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 Version0019Date20201106110741
44
 *
45
 * @package OCA\Circles\Migration
46
 */
47
class Version0019Date20201106110741 extends SimpleMigrationStep {
48
49
50
	/** @var IDBConnection */
51
	private $connection;
52
53
54
	/**
55
	 * @param IDBConnection $connection
56
	 */
57
	public function __construct(IDBConnection $connection) {
58
		$this->connection = $connection;
59
	}
60
61
62
	/**
63
	 * @param IOutput $output
64
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
65
	 * @param array $options
66
	 *
67
	 * @return null|ISchemaWrapper
68
	 * @throws SchemaException
69
	 */
70
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
71
		/** @var ISchemaWrapper $schema */
72
		$schema = $schemaClosure();
73
74
		if ($schema->hasTable('circle_members')) {
75
			$table = $schema->getTable('circle_members');
76
			if (!$table->hasColumn('cached_update')) {
77
				$table->addColumn(
78
					'cached_update', 'datetime', [
79
									   'notnull' => false,
80
								   ]
81
				);
82
			}
83
		}
84
85
		return $schema;
86
	}
87
88
}
89
90