Issues (125)

lib/Migration/Version0910Date20221109095949.php (1 issue)

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
use OCP\IDBConnection;
13
14
class Version0910Date20221109095949 extends SimpleMigrationStep {
15
16
	private $connection;
17
18
	public function __construct(IDBConnection $connection) {
19
		$this->connection = $connection;
20
	}
21
22
	/**
23
	 * @param IOutput $output
24
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
25
	 * @param array $options
26
	 */
27
	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
28
	}
29
30
	/**
31
	 * @param IOutput $output
32
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
33
	 * @param array $options
34
	 * @return null|ISchemaWrapper
35
	 */
36
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
37
		$schema = $schemaClosure();
38
39
		$table = $schema->getTable('facerecog_faces');
40
		if ($table->hasColumn('width'))
41
			return null;
42
43
		/**
44
		 * NOTE: These columns should just be notnull.
45
		 * In this migration add an default, since the previous rows would be null and cannot be migrated.
46
		 */
47
		$table->addColumn('x', 'integer', [
48
			'notnull' => true,
49
			'default' => -1,
50
			'length' => 4,
51
		]);
52
		$table->addColumn('y', 'integer', [
53
			'notnull' => true,
54
			'default' => -1,
55
			'length' => 4,
56
		]);
57
		$table->addColumn('width', 'integer', [
58
			'notnull' => true,
59
			'default' => -1,
60
			'length' => 4,
61
		]);
62
		$table->addColumn('height', 'integer', [
63
			'notnull' => true,
64
			'default' => -1,
65
			'length' => 4,
66
		]);
67
68
		return $schema;
69
	}
70
71
	/**
72
	 * @param IOutput $output
73
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
74
	 * @param array $options
75
	 */
76
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
77
		$update = $this->connection->getQueryBuilder();
78
		$update->update('facerecog_faces')
79
			->set('x', $update->createParameter('new_x'))
80
			->set('y', $update->createParameter('new_y'))
81
			->set('width', $update->createParameter('new_width'))
82
			->set('height', $update->createParameter('new_height'))
83
			->where($update->expr()->eq('id', $update->createParameter('id')));
84
85
		$query = $this->connection->getQueryBuilder();
86
		$query->select('*')->from('facerecog_faces');
87
88
		$result = $query->execute();
0 ignored issues
show
Deprecated Code introduced by
The function OCP\DB\QueryBuilder\IQueryBuilder::execute() has been deprecated: 22.0.0 Use executeQuery or executeStatement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

88
		$result = /** @scrutinizer ignore-deprecated */ $query->execute();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
89
		while ($row = $result->fetch()) {
90
			$update->setParameter('new_x', $row['left']);
91
			$update->setParameter('new_y', $row['top']);
92
			$update->setParameter('new_width', $row['right'] - $row['left']);
93
			$update->setParameter('new_height', $row['bottom'] - $row['top']);
94
			$update->setParameter('id', $row['id']);
95
			$update->executeStatement();
96
		}
97
		$result->closeCursor();
98
	}
99
100
}
101