From b552abb3327f09baa1c0f4e821dc9f6bd6ef738e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 1 May 2018 17:02:11 +0200 Subject: JSON column for feeds (#1838) * Draft of JSON column for feeds https://github.com/FreshRSS/FreshRSS/issues/1654 * Add some per-feed options * Feed cURL timeout * Mark updated articles as read https://github.com/FreshRSS/FreshRSS/issues/891 * Mark as read upon reception https://github.com/FreshRSS/FreshRSS/issues/1702 * Ignore SSL (unsafe) https://github.com/FreshRSS/FreshRSS/issues/1811 * Try PHPCS workaround While waiting for a better syntax support --- app/SQL/install.sql.mysql.php | 1 + app/SQL/install.sql.pgsql.php | 1 + app/SQL/install.sql.sqlite.php | 1 + 3 files changed, 3 insertions(+) (limited to 'app/SQL') diff --git a/app/SQL/install.sql.mysql.php b/app/SQL/install.sql.mysql.php index b94a24298..747a0a6b3 100644 --- a/app/SQL/install.sql.mysql.php +++ b/app/SQL/install.sql.mysql.php @@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS `%1$sfeed` ( `error` boolean DEFAULT 0, `keep_history` MEDIUMINT NOT NULL DEFAULT -2, -- v0.7 `ttl` INT NOT NULL DEFAULT 0, -- v0.7.3 + `attributes` TEXT, -- v1.11.0 `cache_nbEntries` int DEFAULT 0, -- v0.7 `cache_nbUnreads` int DEFAULT 0, -- v0.7 PRIMARY KEY (`id`), diff --git a/app/SQL/install.sql.pgsql.php b/app/SQL/install.sql.pgsql.php index 23afdb783..99f5a05d3 100644 --- a/app/SQL/install.sql.pgsql.php +++ b/app/SQL/install.sql.pgsql.php @@ -22,6 +22,7 @@ $SQL_CREATE_TABLES = array( "error" smallint DEFAULT 0, "keep_history" INT NOT NULL DEFAULT -2, "ttl" INT NOT NULL DEFAULT 0, + "attributes" TEXT, -- v1.11.0 "cache_nbEntries" INT DEFAULT 0, "cache_nbUnreads" INT DEFAULT 0, FOREIGN KEY ("category") REFERENCES "%1$scategory" ("id") ON DELETE SET NULL ON UPDATE CASCADE diff --git a/app/SQL/install.sql.sqlite.php b/app/SQL/install.sql.sqlite.php index d8e670bc8..cbfb719e5 100644 --- a/app/SQL/install.sql.sqlite.php +++ b/app/SQL/install.sql.sqlite.php @@ -21,6 +21,7 @@ $SQL_CREATE_TABLES = array( `error` boolean DEFAULT 0, `keep_history` MEDIUMINT NOT NULL DEFAULT -2, `ttl` INT NOT NULL DEFAULT 0, + `attributes` TEXT, -- v1.11.0 `cache_nbEntries` int DEFAULT 0, `cache_nbUnreads` int DEFAULT 0, FOREIGN KEY (`category`) REFERENCES `category`(`id`) ON DELETE SET NULL ON UPDATE CASCADE, -- cgit v1.2.3 From e98e40b7b4d8ebd4f7e03ade2d3fb6be2c22cc52 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 29 May 2018 23:55:31 +0200 Subject: Fix check default category, and PostgreSQL seq bug (#1907) checkDefault() was broken as it was not necessarily creating the default category with the right ID. PostgreSQL required additional care. https://github.com/FreshRSS/FreshRSS/issues/1890#issuecomment-392869777 https://github.com/FreshRSS/FreshRSS/pull/1322 https://github.com/FreshRSS/FreshRSS/issues/1312#issuecomment-254009397 --- app/Models/CategoryDAO.php | 26 ++++++++++++++++++++++---- app/SQL/install.sql.pgsql.php | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'app/SQL') diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index 68db17db3..ef2c402a0 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -134,7 +134,11 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable if (isset($cat[0])) { return $cat[0]; } else { - return false; + if (FreshRSS_Context::$isCli) { + fwrite(STDERR, 'FreshRSS database error: Default category not found!' . "\n"); + } + Minz_Log::error('FreshRSS database error: Default category not found!'); + return null; } } public function checkDefault() { @@ -144,13 +148,27 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable $cat = new FreshRSS_Category(_t('gen.short.default_category')); $cat->_id(self::DEFAULTCATEGORYID); + $sql = 'INSERT INTO `' . $this->prefix . 'category`(id, name) VALUES(?, ?)'; + if (parent::$sharedDbType === 'pgsql') { + //Force call to nextval() + $sql .= " RETURNING nextval('" . $this->prefix . "category_id_seq');"; + } + $stm = $this->bd->prepare($sql); + $values = array( - 'id' => $cat->id(), - 'name' => $cat->name(), + $cat->id(), + $cat->name(), ); - $this->addCategory($values); + if ($stm && $stm->execute($values)) { + return $this->bd->lastInsertId('"' . $this->prefix . 'category_id_seq"'); + } else { + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::error('SQL error check default category: ' . json_encode($info)); + return false; + } } + return true; } public function count() { diff --git a/app/SQL/install.sql.pgsql.php b/app/SQL/install.sql.pgsql.php index 99f5a05d3..b80fbf1e7 100644 --- a/app/SQL/install.sql.pgsql.php +++ b/app/SQL/install.sql.pgsql.php @@ -52,7 +52,7 @@ $SQL_CREATE_TABLES = array( 'CREATE INDEX %1$sis_read_index ON "%1$sentry" ("is_read");', 'CREATE INDEX %1$sentry_lastSeen_index ON "%1$sentry" ("lastSeen");', -'INSERT INTO "%1$scategory" (name) SELECT \'%2$s\' WHERE NOT EXISTS (SELECT id FROM "%1$scategory" WHERE id = 1);', +'INSERT INTO "%1$scategory" (id, name) SELECT 1, \'%2$s\' WHERE NOT EXISTS (SELECT id FROM "%1$scategory" WHERE id = 1) RETURNING nextval(\'%1$scategory_id_seq\');', ); global $SQL_CREATE_TABLE_ENTRYTMP; -- cgit v1.2.3