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