diff options
Diffstat (limited to 'app/Models')
| -rw-r--r-- | app/Models/CategoryDAO.php | 7 | ||||
| -rw-r--r-- | app/Models/DatabaseDAO.php | 14 | ||||
| -rw-r--r-- | app/Models/Entry.php | 2 | ||||
| -rw-r--r-- | app/Models/FeedDAO.php | 3 | ||||
| -rw-r--r-- | app/Models/StatsDAO.php | 25 |
5 files changed, 44 insertions, 7 deletions
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index 5dfecb36d..2477d0ea2 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -435,6 +435,8 @@ SQL; $feedsDao = []; $feedDao = FreshRSS_Factory::createFeedDao(); foreach ($listDAO as $line) { + FreshRSS_DatabaseDAO::pdoInt($line, ['c_id', 'c_kind', 'c_last_update', 'c_error', + 'id', 'kind', 'priority', 'error', 'cache_nbEntries', 'cache_nbUnreads', 'ttl']); if (!empty($previousLine['c_id']) && $line['c_id'] !== $previousLine['c_id']) { // End of the current category, we add it to the $list $cat = new FreshRSS_Category( @@ -444,7 +446,7 @@ SQL; $cat->_id($previousLine['c_id']); $cat->_kind($previousLine['c_kind']); $cat->_attributes('', $previousLine['c_attributes'] ?? '[]'); - $list[$previousLine['c_id']] = $cat; + $list[(int)$previousLine['c_id']] = $cat; $feedsDao = []; //Prepare for next category } @@ -464,7 +466,7 @@ SQL; $cat->_lastUpdate($previousLine['c_last_update'] ?? 0); $cat->_error($previousLine['c_error'] ?? 0); $cat->_attributes('', $previousLine['c_attributes'] ?? []); - $list[$previousLine['c_id']] = $cat; + $list[(int)$previousLine['c_id']] = $cat; } return $list; @@ -478,6 +480,7 @@ SQL; $list = []; foreach ($listDAO as $dao) { + FreshRSS_DatabaseDAO::pdoInt($dao, ['id', 'kind', 'lastUpdate', 'error']); $cat = new FreshRSS_Category( $dao['name'] ); diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php index 89327d6c9..05ca98355 100644 --- a/app/Models/DatabaseDAO.php +++ b/app/Models/DatabaseDAO.php @@ -393,4 +393,18 @@ SQL; return true; } + + /** + * Ensure that some PDO columns are `int` and not `string`. + * Compatibility with PHP 7. + * @param array<string|int|null> $table + * @param array<string> $columns + */ + public static function pdoInt(array &$table, array $columns): void { + foreach ($columns as $column) { + if (isset($table[$column]) && is_string($table[$column])) { + $table[$column] = (int)$table[$column]; + } + } + } } diff --git a/app/Models/Entry.php b/app/Models/Entry.php index e19a637d7..476c5a8cf 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -52,6 +52,8 @@ class FreshRSS_Entry extends Minz_Model { /** @param array{'id'?:string,'id_feed'?:int,'guid'?:string,'title'?:string,'author'?:string,'content'?:string,'link'?:string,'date'?:int|string,'lastSeen'?:int, * 'hash'?:string,'is_read'?:bool|int,'is_favorite'?:bool|int,'tags'?:string|array<string>,'attributes'?:string,'thumbnail'?:string,'timestamp'?:string} $dao */ public static function fromArray(array $dao): FreshRSS_Entry { + FreshRSS_DatabaseDAO::pdoInt($dao, ['id_feed', 'date', 'lastSeen', 'is_read', 'is_favorite']); + if (empty($dao['content'])) { $dao['content'] = ''; } diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 42a4e77f1..82e33dd84 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -584,6 +584,7 @@ SQL; $list = []; foreach ($listDAO as $key => $dao) { + FreshRSS_DatabaseDAO::pdoInt($dao, ['id', 'kind', 'category', 'lastUpdate', 'priority', 'error', 'ttl', 'cache_nbUnreads', 'cache_nbEntries']); if (!isset($dao['name'])) { continue; } @@ -627,6 +628,6 @@ SQL; return -1; } $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); - return $res[0] ?? 0; + return (int)($res[0] ?? 0); } } diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index 2cef6c183..0e0bad623 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -49,8 +49,13 @@ WHERE e.id_feed = f.id {$filter} SQL; $res = $this->fetchAssoc($sql); - /** @var array<array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}>|null $res */ - return $res[0] ?? false; + if (!empty($res[0])) { + $dao = $res[0]; + /** @var array<array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}> $res */ + FreshRSS_DatabaseDAO::pdoInt($dao, ['total', 'count_unreads', 'count_reads', 'count_favorites']); + return $dao; + } + return false; } /** @@ -286,7 +291,13 @@ LIMIT 10 SQL; $res = $this->fetchAssoc($sql); /** @var array<array{'id':int,'name':string,'category':string,'count':int}>|null $res */ - return $res == null ? [] : $res; + if (is_array($res)) { + foreach ($res as &$dao) { + FreshRSS_DatabaseDAO::pdoInt($dao, ['id', 'count']); + } + return $res; + } + return []; } /** @@ -306,7 +317,13 @@ ORDER BY name SQL; $res = $this->fetchAssoc($sql); /** @var array<array{'id':int,'name':string,'last_date':int,'nb_articles':int}>|null $res */ - return $res == null ? [] : $res; + if (is_array($res)) { + foreach ($res as &$dao) { + FreshRSS_DatabaseDAO::pdoInt($dao, ['id', 'last_date', 'nb_articles']); + } + return $res; + } + return []; } /** |
