Completed
Push — master ( 564b36...cbd880 )
by Julius
01:11 queued 01:11
created

Version30709Date20201111104147   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 13
lcom 0
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
F changeSchema() 0 20 11
A ensureColumnIsNullable() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OCA\Richdocuments\Migration;
6
7
use Closure;
8
use OCP\DB\ISchemaWrapper;
9
use OCP\Migration\IOutput;
10
use OCP\Migration\SimpleMigrationStep;
11
12
class Version30709Date20201111104147 extends SimpleMigrationStep {
13
14
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
15
		/** @var ISchemaWrapper $schema */
16
		$schema = $schemaClosure();
17
18
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'version');
19
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'canwrite') || $result;
20
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'token') || $result;
21
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'hide_download') || $result;
22
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'direct') || $result;
23
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'is_remote_token') || $result;
24
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'remote_server') || $result;
25
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'remote_server_token') || $result;
26
27
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_direct', 'timestamp') || $result;
28
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_assets', 'timestamp') || $result;
29
30
31
32
		return $result ? $schema : null;
33
	}
34
35
	protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool {
36
		$table = $schema->getTable($tableName);
37
		$column = $table->getColumn($columnName);
38
39
		if ($column->getNotnull()) {
40
			$column->setNotnull(false);
41
			return true;
42
		}
43
44
		return false;
45
	}
46
}
47