Passed
Push — master ( d93244...31d6f2 )
by Pauli
03:37
created

PodcastChannelMapper::findUniqueEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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