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 Pauli Järvinen <[email protected]> |
10
|
|
|
* @copyright Pauli Järvinen 2021 - 2025 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace OCA\Music\Db; |
14
|
|
|
|
15
|
|
|
use OCP\IConfig; |
16
|
|
|
use OCP\IDBConnection; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Type hint a base class method to help Scrutinizer |
20
|
|
|
* @method PodcastChannel insert(PodcastChannel $channel) |
21
|
|
|
* @phpstan-extends BaseMapper<PodcastChannel> |
22
|
|
|
*/ |
23
|
|
|
class PodcastChannelMapper extends BaseMapper { |
24
|
|
|
public function __construct(IDBConnection $db, IConfig $config) { |
25
|
|
|
parent::__construct($db, $config, 'music_podcast_channels', PodcastChannel::class, 'title', ['user_id', 'rss_hash']); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return int[] |
30
|
|
|
*/ |
31
|
|
|
public function findAllIdsWithNoUpdateSince(string $userId, \DateTime $timeLimit) : array { |
32
|
|
|
$sql = "SELECT `id` FROM `{$this->getTableName()}` WHERE `user_id` = ? AND `update_checked` < ?"; |
33
|
|
|
$result = $this->execute($sql, [$userId, $timeLimit->format(BaseMapper::SQL_DATE_FORMAT)]); |
34
|
|
|
|
35
|
|
|
return \array_map('intval', $result->fetchAll(\PDO::FETCH_COLUMN)); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Overridden from the base implementation to provide support for table-specific rules |
40
|
|
|
* |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
* @see BaseMapper::advFormatSqlCondition() |
43
|
|
|
*/ |
44
|
|
|
protected function advFormatSqlCondition(string $rule, string $sqlOp, string $conv) : string { |
45
|
|
|
$condForRule = [ |
46
|
|
|
'podcast_episode' => "`*PREFIX*music_podcast_channels`.`id` IN (SELECT `channel_id` FROM `*PREFIX*music_podcast_episodes` `e` WHERE $conv(`e`.`title`) $sqlOp $conv(?))", |
47
|
|
|
'time' => "`*PREFIX*music_podcast_channels`.`id` IN (SELECT * FROM (SELECT `channel_id` FROM `*PREFIX*music_podcast_episodes` GROUP BY `channel_id` HAVING SUM(`duration`) $sqlOp ?) mysqlhack)", |
48
|
|
|
'pubdate' => "`published` $sqlOp ?" |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
return $condForRule[$rule] ?? parent::advFormatSqlCondition($rule, $sqlOp, $conv); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|