Issues (125)

lib/Migration/Version000515Date20200409003814.php (2 issues)

1
<?php
2
declare(strict_types=1);
3
4
namespace OCA\FaceRecognition\Migration;
5
6
use Closure;
7
8
use OCP\DB\ISchemaWrapper;
9
10
use OCP\IDBConnection;
11
use OCP\Migration\SimpleMigrationStep;
12
use OCP\Migration\IOutput;
13
14
class Version000515Date20200409003814 extends SimpleMigrationStep {
15
16
	/** @var IDBConnection */
17
	protected $connection;
18
19
	/**
20
	 * @param IDBConnection $connection
21
	 */
22
	public function __construct(IDBConnection $connection) {
23
		$this->connection = $connection;
24
	}
25
26
	/**
27
	 * @param IOutput $output
28
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
29
	 * @param array $options
30
	 *
31
	 * @return void
32
	 */
33
	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
34
	}
35
36
	/**
37
	 * @param IOutput $output
38
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39
	 * @param array $options
40
	 *
41
	 * @return void
42
	 */
43
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
44
		$this->migratePreferencesKey('preferences', 'facerecognition', 'recreate-clusters', 'recreate_clusters');
45
		$this->migratePreferencesKey('preferences', 'facerecognition', 'force-create-clusters', 'force_create_clusters');
46
47
		$this->migratePreferencesKey('appconfig', 'facerecognition', 'handle-external-files', 'handle_external_files');
48
		$this->migratePreferencesKey('appconfig', 'facerecognition', 'handle-shared-files', 'handle_shared_files');
49
		$this->migratePreferencesKey('appconfig', 'facerecognition', 'min-confidence', 'min_confidence');
50
		$this->migratePreferencesKey('appconfig', 'facerecognition', 'show-not-grouped', 'show_not_grouped');
51
52
		$this->deletePreferencesKey('appconfig', 'facerecognition', 'memory-limits');
53
		$this->deletePreferencesKey('appconfig', 'facerecognition', 'queue-done');
54
		$this->deletePreferencesKey('appconfig', 'facerecognition', 'starttime');
55
	}
56
57
	/**
58
	 * @param IOutput $output
59
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
60
	 * @param array $options
61
	 *
62
	 * @return void
63
	 */
64
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
65
	}
66
67
	/**
68
	 * @param string $table
69
	 * @param string $appName
70
	 */
71
	protected function migratePreferencesKey(string $table, string $appName, string $key, string $toKey): void {
72
		$qb = $this->connection->getQueryBuilder();
73
		$qb->update($table)
74
			->set('configkey', $qb->createNamedParameter($toKey))
75
			->where($qb->expr()->eq('configkey', $qb->createNamedParameter($key)))
76
			->andWhere($qb->expr()->eq('appid', $qb->createNamedParameter($appName)));
77
		$qb->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

77
		/** @scrutinizer ignore-deprecated */ $qb->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...
78
	}
79
80
	/**
81
	 * @param string $table
82
	 * @param string $appName
83
	 * @param string $key
84
	 */
85
	protected function deletePreferencesKey(string $table, string $appName, string $key): void {
86
		$qb = $this->connection->getQueryBuilder();
87
		$qb->delete($table)
88
			->where($qb->expr()->eq('appid', $qb->createNamedParameter($appName)))
89
			->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter($key)));
90
		$qb->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

90
		/** @scrutinizer ignore-deprecated */ $qb->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...
91
	}
92
93
}
94