Issues (173)

lib/Db/AmpacheSessionMapper.php (3 issues)

1
<?php declare(strict_types=1);
2
3
/**
4
 * ownCloud - Music app
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Morris Jobke <[email protected]>
10
 * @author Pauli Järvinen <[email protected]>
11
 * @copyright Morris Jobke 2013, 2014
12
 * @copyright Pauli Järvinen 2020 - 2025
13
 */
14
15
namespace OCA\Music\Db;
16
17
use OCP\IDBConnection;
18
19
use OCA\Music\AppFramework\Db\Mapper;
20
21
/**
22
 * @method AmpacheSession findEntity(string $sql, array $params)
23
 * @extends Mapper<AmpacheSession>
24
 */
25
class AmpacheSessionMapper extends Mapper {
26
	public function __construct(IDBConnection $db) {
27
		parent::__construct($db, 'music_ampache_sessions', AmpacheSession::class);
28
	}
29
30
	/**
31
	 * @param string $token
32
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
33
	 */
34
	public function findByToken($token) : AmpacheSession {
35
		$sql = 'SELECT *
36
				FROM `*PREFIX*music_ampache_sessions`
37
				WHERE `token` = ? AND `expiry` > ?';
38
		$params = [$token, \time()];
39
40
		return $this->findEntity($sql, $params);
41
	}
42
43
	public function extend(string $token, int $expiry) : void {
44
		$sql = 'UPDATE `*PREFIX*music_ampache_sessions`
45
				SET `expiry` = ?
46
				WHERE `token` = ?';
47
48
		$params = [$expiry, $token];
49
		$result = $this->execute($sql, $params);
50
		$result->closeCursor();
0 ignored issues
show
Deprecated Code introduced by
The function OCP\DB\IPreparedStatement::closeCursor() has been deprecated: 21.0.0 use \OCP\DB\IResult::closeCursor on the \OCP\DB\IResult returned by \OCP\IDBConnection::prepare ( Ignorable by Annotation )

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

50
		/** @scrutinizer ignore-deprecated */ $result->closeCursor();

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...
51
	}
52
53
	public function cleanUp() : void {
54
		$sql = 'DELETE FROM `*PREFIX*music_ampache_sessions`
55
				WHERE `expiry` < ?';
56
		$params = [\time()];
57
		$result = $this->execute($sql, $params);
58
		$result->closeCursor();
0 ignored issues
show
Deprecated Code introduced by
The function OCP\DB\IPreparedStatement::closeCursor() has been deprecated: 21.0.0 use \OCP\DB\IResult::closeCursor on the \OCP\DB\IResult returned by \OCP\IDBConnection::prepare ( Ignorable by Annotation )

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

58
		/** @scrutinizer ignore-deprecated */ $result->closeCursor();

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...
59
	}
60
61
	public function revokeSessions(int $ampacheUserId) : void {
62
		$sql = 'DELETE FROM `*PREFIX*music_ampache_sessions`
63
				WHERE `ampache_user_id` = ?';
64
		$params = [$ampacheUserId];
65
		$result = $this->execute($sql, $params);
66
		$result->closeCursor();
0 ignored issues
show
Deprecated Code introduced by
The function OCP\DB\IPreparedStatement::closeCursor() has been deprecated: 21.0.0 use \OCP\DB\IResult::closeCursor on the \OCP\DB\IResult returned by \OCP\IDBConnection::prepare ( Ignorable by Annotation )

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

66
		/** @scrutinizer ignore-deprecated */ $result->closeCursor();

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...
67
	}
68
}
69