aboutsummaryrefslogtreecommitdiff
path: root/app/Models/FeedDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-09-06 09:06:46 +0200
committerGravatar GitHub <noreply@github.com> 2024-09-06 09:06:46 +0200
commita81656c3ed5b8fe0f31794a4fbe0d1a907fca8e8 (patch)
tree8bf49bd876aaebc985a9fb1214863190a799cbee /app/Models/FeedDAO.php
parent8f7c3473a76809efc88814253722c76f0cc8eb04 (diff)
Upgrade to PHP 8.1 (#6711)
* Upgrade to PHP 8.1 As discussed in https://github.com/FreshRSS/FreshRSS/discussions/5474 https://www.php.net/releases/8.0/en.php https://www.php.net/releases/8.1/en.php Upgrade to available native type declarations https://php.net/language.types.declarations Upgrade to https://phpunit.de/announcements/phpunit-10.html which requires PHP 8.1+ (good timing, as version 9 was not maintained anymore) Upgrade `:oldest` Docker dev image to oldest Alpine version supporting PHP 8.1: Alpine 3.16, which includes PHP 8.1.22. * Include 6736 https://github.com/FreshRSS/FreshRSS/pull/6736
Diffstat (limited to 'app/Models/FeedDAO.php')
-rw-r--r--app/Models/FeedDAO.php39
1 files changed, 13 insertions, 26 deletions
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 11eef4e90..96a8fc3c5 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -36,9 +36,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
/**
* @param array{'url':string,'kind':int,'category':int,'name':string,'website':string,'description':string,'lastUpdate':int,'priority'?:int,
* 'pathEntries'?:string,'httpAuth':string,'error':int|bool,'ttl'?:int,'attributes'?:string|array<string|mixed>} $valuesTmp
- * @return int|false
*/
- public function addFeed(array $valuesTmp) {
+ public function addFeed(array $valuesTmp): int|false {
$sql = 'INSERT INTO `_feed` (url, kind, category, name, website, description, `lastUpdate`, priority, `pathEntries`, `httpAuth`, error, ttl, attributes)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
$stm = $this->pdo->prepare($sql);
@@ -81,8 +80,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
}
}
- /** @return int|false */
- public function addFeedObject(FreshRSS_Feed $feed) {
+ public function addFeedObject(FreshRSS_Feed $feed): int|false {
// Add feed only if we don’t find it in DB
$feed_search = $this->searchByUrl($feed->url());
if (!$feed_search) {
@@ -141,9 +139,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
/**
* @param array{'url'?:string,'kind'?:int,'category'?:int,'name'?:string,'website'?:string,'description'?:string,'lastUpdate'?:int,'priority'?:int,
* 'pathEntries'?:string,'httpAuth'?:string,'error'?:int,'ttl'?:int,'attributes'?:string|array<string,mixed>} $valuesTmp $valuesTmp
- * @return int|false
*/
- public function updateFeed(int $id, array $valuesTmp) {
+ public function updateFeed(int $id, array $valuesTmp): int|false {
$values = [];
$originalValues = $valuesTmp;
if (isset($valuesTmp['name'])) {
@@ -191,9 +188,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
/**
* @param non-empty-string $key
* @param string|array<mixed>|bool|int|null $value
- * @return int|false
*/
- public function updateFeedAttribute(FreshRSS_Feed $feed, string $key, $value) {
+ public function updateFeedAttribute(FreshRSS_Feed $feed, string $key, $value): int|false {
$feed->_attribute($key, $value);
return $this->updateFeed(
$feed->id(),
@@ -202,10 +198,9 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
}
/**
- * @return int|false
* @see updateCachedValues()
*/
- public function updateLastUpdate(int $id, bool $inError = false, int $mtime = 0) {
+ public function updateLastUpdate(int $id, bool $inError = false, int $mtime = 0): int|false {
$sql = 'UPDATE `_feed` SET `lastUpdate`=?, error=? WHERE id=?';
$values = [
$mtime <= 0 ? time() : $mtime,
@@ -223,14 +218,12 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
}
}
- /** @return int|false */
- public function mute(int $id, bool $value = true) {
+ public function mute(int $id, bool $value = true): int|false {
$sql = 'UPDATE `_feed` SET ttl=' . ($value ? '-' : '') . 'ABS(ttl) WHERE id=' . intval($id);
return $this->pdo->exec($sql);
}
- /** @return int|false */
- public function changeCategory(int $idOldCat, int $idNewCat) {
+ public function changeCategory(int $idOldCat, int $idNewCat): int|false {
$catDAO = FreshRSS_Factory::createCategoryDao();
$newCat = $catDAO->searchById($idNewCat);
if ($newCat === null) {
@@ -257,8 +250,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
}
}
- /** @return int|false */
- public function deleteFeed(int $id) {
+ public function deleteFeed(int $id): int|false {
$sql = 'DELETE FROM `_feed` WHERE id=?';
$stm = $this->pdo->prepare($sql);
@@ -275,9 +267,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
/**
* @param bool|null $muted to include only muted feeds
- * @return int|false
*/
- public function deleteFeedByCategory(int $id, ?bool $muted = null) {
+ public function deleteFeedByCategory(int $id, ?bool $muted = null): int|false {
$sql = 'DELETE FROM `_feed` WHERE category=?';
if ($muted) {
$sql .= ' AND ttl < 0';
@@ -454,9 +445,8 @@ SQL;
/**
* Update cached values for selected feeds, or all feeds if no feed ID is provided.
- * @return int|false
*/
- public function updateCachedValues(int ...$feedIds) {
+ public function updateCachedValues(int ...$feedIds): int|false {
//2 sub-requests with FOREIGN KEY(e.id_feed), INDEX(e.is_read) faster than 1 request with GROUP BY or CASE
$sql = <<<SQL
UPDATE `_feed`
@@ -480,7 +470,7 @@ SQL;
* Remember to call updateCachedValues() after calling this function
* @return int|false number of lines affected or false in case of error
*/
- public function markAsReadMaxUnread(int $id, int $n) {
+ public function markAsReadMaxUnread(int $id, int $n): int|false {
//Double SELECT for MySQL workaround ERROR 1093 (HY000)
$sql = <<<'SQL'
UPDATE `_entry` SET is_read=1
@@ -509,7 +499,7 @@ SQL;
* Remember to call updateCachedValues() after calling this function
* @return int|false number of lines affected or false in case of error
*/
- public function markAsReadNotSeen(int $id, int $minLastSeen) {
+ public function markAsReadNotSeen(int $id, int $minLastSeen): int|false {
$sql = <<<'SQL'
UPDATE `_entry` SET is_read=1
WHERE id_feed=:id_feed AND is_read=0 AND (`lastSeen` + 10 < :min_last_seen)
@@ -527,10 +517,7 @@ SQL;
}
}
- /**
- * @return int|false
- */
- public function truncate(int $id) {
+ public function truncate(int $id): int|false {
$sql = 'DELETE FROM `_entry` WHERE id_feed=:id';
$stm = $this->pdo->prepare($sql);
$this->pdo->beginTransaction();