From 0866fdaee85bc8530437436abe7f8536b8b0f4f0 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 19 Jul 2022 15:17:08 +0200 Subject: Add database field attributes for entries (#4444) * Add database field attributes for entries Just like we already have for categories, feeds, etc. No core use yet, but allows in particular extensions to save per-entry data * Fix PHPStand * Fix wrong variable --- app/Models/EntryDAOPGSQL.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'app/Models/EntryDAOPGSQL.php') diff --git a/app/Models/EntryDAOPGSQL.php b/app/Models/EntryDAOPGSQL.php index 13bf8b41f..8702db706 100644 --- a/app/Models/EntryDAOPGSQL.php +++ b/app/Models/EntryDAOPGSQL.php @@ -20,6 +20,14 @@ class FreshRSS_EntryDAOPGSQL extends FreshRSS_EntryDAOSQLite { protected function autoUpdateDb(array $errorInfo) { if (isset($errorInfo[0])) { + if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_FIELD_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_COLUMN) { + $errorLines = explode("\n", $errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise + foreach (['attributes'] as $column) { + if (stripos($errorLines[0], $column) !== false) { + return $this->addColumn($column); + } + } + } if ($errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_TABLE) { if (stripos($errorInfo[2], 'tag') !== false) { $tagDAO = FreshRSS_Factory::createTagDao(); @@ -32,10 +40,6 @@ class FreshRSS_EntryDAOPGSQL extends FreshRSS_EntryDAOSQLite { return false; } - protected function addColumn(string $name) { - return false; - } - public function commitNewEntries() { //TODO: Update to PostgreSQL 9.5+ syntax with ON CONFLICT DO NOTHING $sql = 'DO $$ @@ -44,9 +48,9 @@ maxrank bigint := (SELECT MAX(id) FROM `_entrytmp`); rank bigint := (SELECT maxrank - COUNT(*) FROM `_entrytmp`); BEGIN INSERT INTO `_entry` - (id, guid, title, author, content, link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags) + (id, guid, title, author, content, link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags, attributes) (SELECT rank + row_number() OVER(ORDER BY date, id) AS id, guid, title, author, content, - link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags + link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags, attributes FROM `_entrytmp` AS etmp WHERE NOT EXISTS ( SELECT 1 FROM `_entry` AS ereal -- cgit v1.2.3