From 8ee8a573f1f7e9cc45f9b3c46627d15670f14f3a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 29 Sep 2018 20:47:17 +0200 Subject: Custom labels (#2027) * First draft of custom tags https://github.com/FreshRSS/FreshRSS/issues/928 https://github.com/FreshRSS/FreshRSS/issues/1367 * SMALLINT to BIGINT for id_entry And uppercase SQL types * Fix layout for unreads * Start UI menu * Change menu order * Clean database helpers https://github.com/FreshRSS/FreshRSS/pull/2027#discussion_r217971535 * Travis rules do not understand PostgreSQL constants Grrr * Tag controller + UI * Add column attributes to tags * Use only favicon for now, for label * Fix styling for different themes * Constant for maximum InnoDB index length in Unicode https://github.com/FreshRSS/FreshRSS/pull/2027#discussion_r219052200 (I would have personnally prefered keeping the readability of a real value instead of a constant, in this case of many SQL fields) * Use FreshRSS_Factory::createCategoryDao * Add view of all articles containing any tag * Fix search in tags * Mark as read tags * Partial auto-update unread tags * More auto update tag unreads * Add tag deletion * Do not purge tagged articles * Minor comment * Fix SQLite and UI bug * Google Reader API support for user tags Add SQL check that tag names must be distinct from category names * whitespace * Add missing API for EasyRSS * Compatibility SQLite Problematic parentheses * Add SQL DISTINCT for cases with multiple tags * Fix for PostgreSQL PostgreSQL needs some additional type hint to avoid "could not determine data type of parameter $1" http://www.postgresql-archive.org/Could-not-determine-data-type-of-parameter-1-tp2171092p2171094.html --- app/Models/DatabaseDAO.php | 70 +++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 25 deletions(-) (limited to 'app/Models/DatabaseDAO.php') diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php index b8e5577e4..54076d7a9 100644 --- a/app/Models/DatabaseDAO.php +++ b/app/Models/DatabaseDAO.php @@ -4,6 +4,16 @@ * This class is used to test database is well-constructed. */ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { + + //MySQL error codes + const ER_BAD_FIELD_ERROR = '42S22'; + const ER_BAD_TABLE_ERROR = '42S02'; + const ER_TRUNCATED_WRONG_VALUE_FOR_FIELD = '1366'; + + //MySQL InnoDB maximum index length for UTF8MB4 + //https://dev.mysql.com/doc/refman/8.0/en/innodb-restrictions.html + const LENGTH_INDEX_UNICODE = 191; + public function tablesAreCorrect() { $sql = 'SHOW TABLES'; $stm = $this->bd->prepare($sql); @@ -14,6 +24,9 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { $this->prefix . 'category' => false, $this->prefix . 'feed' => false, $this->prefix . 'entry' => false, + $this->prefix . 'entrytmp' => false, + $this->prefix . 'tag' => false, + $this->prefix . 'entrytag' => false, ); foreach ($res as $value) { $tables[array_pop($value)] = true; @@ -43,7 +56,7 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { public function categoryIsCorrect() { return $this->checkTable('category', array( - 'id', 'name' + 'id', 'name', )); } @@ -51,14 +64,33 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { return $this->checkTable('feed', array( 'id', 'url', 'category', 'name', 'website', 'description', 'lastUpdate', 'priority', 'pathEntries', 'httpAuth', 'error', 'keep_history', 'ttl', 'attributes', - 'cache_nbEntries', 'cache_nbUnreads' + 'cache_nbEntries', 'cache_nbUnreads', )); } public function entryIsCorrect() { return $this->checkTable('entry', array( - 'id', 'guid', 'title', 'author', 'content_bin', 'link', 'date', 'is_read', - 'is_favorite', 'id_feed', 'tags' + 'id', 'guid', 'title', 'author', 'content_bin', 'link', 'date', 'lastSeen', 'hash', 'is_read', + 'is_favorite', 'id_feed', 'tags', + )); + } + + public function entrytmpIsCorrect() { + return $this->checkTable('entrytmp', array( + 'id', 'guid', 'title', 'author', 'content_bin', 'link', 'date', 'lastSeen', 'hash', 'is_read', + 'is_favorite', 'id_feed', 'tags', + )); + } + + public function tagIsCorrect() { + return $this->checkTable('tag', array( + 'id', 'name', 'attributes', + )); + } + + public function entrytagIsCorrect() { + return $this->checkTable('entrytag', array( + 'id_tag', 'id_entry', )); } @@ -97,28 +129,16 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { public function optimize() { $ok = true; - - $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'entry`'; //MySQL - $stm = $this->bd->prepare($sql); - $ok &= $stm != false; - if ($stm) { - $ok &= $stm->execute(); - } - - $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'feed`'; //MySQL - $stm = $this->bd->prepare($sql); - $ok &= $stm != false; - if ($stm) { - $ok &= $stm->execute(); + $tables = array('category', 'feed', 'entry', 'entrytmp', 'tag', 'entrytag'); + + foreach ($tables as $table) { + $sql = 'OPTIMIZE TABLE `' . $this->prefix . $table . '`'; //MySQL + $stm = $this->bd->prepare($sql); + $ok &= $stm != false; + if ($stm) { + $ok &= $stm->execute(); + } } - - $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'category`'; //MySQL - $stm = $this->bd->prepare($sql); - $ok &= $stm != false; - if ($stm) { - $ok &= $stm->execute(); - } - return $ok; } } -- cgit v1.2.3