Passed
Push — split-cluster-person ( 5b741f )
by Matias
05:21
created

Version000604Date20200908224225::changeSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 11
ccs 0
cts 8
cp 0
crap 2
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\IDBConnection;
10
use OCP\Migration\IOutput;
11
use OCP\Migration\SimpleMigrationStep;
12
13
/**
14
 * Auto-generated migration step: Please modify to your needs!
15
 */
16
class Version000604Date20200908224225 extends SimpleMigrationStep {
17
18
	/** @var IDBConnection */
19
	protected $connection;
20
21
	public function __construct(IDBConnection $connection) {
22
		$this->connection = $connection;
23
	}
24
25
	/**
26
	 * @param IOutput $output
27
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
28
	 * @param array $options
29
	 * @return null|ISchemaWrapper
30
	 */
31
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
32
		/** @var ISchemaWrapper $schema */
33
		$schema = $schemaClosure();
34
35
		$personsTable = $schema->getTable('facerecog_persons');
36
		$personsTable->changeColumn('name', [
37
			'notnull' => false,
38
			'default' => null,
39
		]);
40
41
		return $schema;
42
	}
43
44
	/**
45
	 * @param IOutput $output
46
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
47
	 * @param array $options
48
	 */
49
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
50
		$query = $this->connection->getQueryBuilder();
51
		$query->update('facerecog_persons')
52
			->set('name', $query->createNamedParameter(null))
53
			->where($query->expr()->iLike('name', 'New person %'));
54
		$query->execute();
55
	}
56
57
}
58