ensureColumnIsNullable()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 10
ccs 0
cts 7
cp 0
crap 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OCA\FaceRecognition\Migration;
6
7
use Closure;
8
use OCP\DB\ISchemaWrapper;
9
use OCP\Migration\IOutput;
10
use OCP\Migration\SimpleMigrationStep;
11
12
/**
13
 * Auto-generated migration step: Please modify to your needs!
14
 */
15
class Version0820Date20210708130230 extends SimpleMigrationStep {
16
17
	/**
18
	 * @param IOutput $output
19
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
20
	 * @param array $options
21
	 * @return null|ISchemaWrapper
22
	 */
23
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
24
		/** @var ISchemaWrapper $schema */
25
		$schema = $schemaClosure();
26
27
		$this->ensureColumnIsNullable($schema, 'facerecog_persons', 'is_valid');
28
		$this->ensureColumnIsNullable($schema, 'facerecog_images', 'is_processed');
29
30
		return null;
31
	}
32
33
	protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool {
34
		$table = $schema->getTable($tableName);
35
		$column = $table->getColumn($columnName);
36
37
		if ($column->getNotnull()) {
38
			$column->setNotnull(false);
39
			return true;
40
		}
41
42
		return false;
43
	}
44
45
}
46