Passed
Pull Request — master (#875)
by Pauli
04:43 queued 02:11
created

findAllIdsWithNoUpdateSince()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
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
11
 */
12
13
namespace OCA\Music\Db;
14
15
use \OCP\AppFramework\Db\Entity;
16
use \OCP\IDBConnection;
17
18
/**
19
 * Type hint a base class methdo to help Scrutinizer
20
 * @method PodcastChannel insert(PodcastChannel $channel)
21
 */
22
class PodcastChannelMapper extends BaseMapper {
23
	public function __construct(IDBConnection $db) {
24
		parent::__construct($db, 'music_podcast_channels', '\OCA\Music\Db\PodcastChannel', 'title');
25
	}
26
27
	/**
28
	 * @return int[]
29
	 */
30
	public function findAllIdsWithNoUpdateSince(string $userId, \DateTime $timeLimit) : array {
31
		$sql = "SELECT `id` FROM `{$this->getTableName()}` WHERE `user_id` = ? AND `update_checked` < ?";
32
		$result = $this->execute($sql, [$userId, $timeLimit->format(BaseMapper::SQL_DATE_FORMAT)]);
33
34
		return \array_map('intval', $result->fetchAll(\PDO::FETCH_COLUMN));
35
	}
36
37
	/**
38
	 * @see \OCA\Music\Db\BaseMapper::findUniqueEntity()
39
	 * @param PodcastChannel $channel
40
	 * @return PodcastChannel
41
	 */
42
	protected function findUniqueEntity(Entity $channel) : Entity {
43
		$sql = $this->selectUserEntities("`rss_hash` = ?");
44
		return $this->findEntity($sql, [$channel->getUserId(), $channel->getRssHash()]);
45
	}
46
}
47