Passed
Push — master ( 4cb66f...8fadc8 )
by Morris
11:53
created

Version16000Date20190427105638::changeSchema()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2019 Daniel Kesselberg <[email protected]>
5
 *
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace OC\Core\Migrations;
24
25
use Closure;
26
use OCP\DB\ISchemaWrapper;
27
use OCP\IDBConnection;
28
use OCP\Migration\SimpleMigrationStep;
29
use OCP\Migration\IOutput;
30
31
32
class Version16000Date20190427105638 extends SimpleMigrationStep {
33
34
	/** @var IDBConnection */
35
	private $connection;
36
37
	public function __construct(IDBConnection $connection) {
38
		$this->connection = $connection;
39
	}
40
41
	/**
42
	 * @param IOutput $output
43
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
44
	 * @param array $options
45
	 */
46
	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
47
		$this->connection
48
			->getQueryBuilder()
49
			->delete('collres_accesscache')
50
			->execute();
51
	}
52
53
	/**
54
	 * @param IOutput $output
55
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
56
	 * @param array $options
57
	 * @return null|ISchemaWrapper
58
	 * @throws \Doctrine\DBAL\Schema\SchemaException
59
	 * @throws \Doctrine\DBAL\DBALException
60
	 */
61
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
62
		/** @var ISchemaWrapper $schema */
63
		$schema = $schemaClosure();
64
65
		if ($schema->hasTable('collres_accesscache')) {
66
			$table = $schema->getTable('collres_accesscache');
67
			$table->dropColumn('access');
68
		}
69
70
		return $schema;
71
	}
72
}
73