summaryrefslogtreecommitdiff
path: root/app/Models/DatabaseDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2018-09-29 20:47:17 +0200
committerGravatar GitHub <noreply@github.com> 2018-09-29 20:47:17 +0200
commit8ee8a573f1f7e9cc45f9b3c46627d15670f14f3a (patch)
tree14200758ab43e4031f60b46b8c6e9018b43e53af /app/Models/DatabaseDAO.php
parent3ae1b57c9d2e23157be54e8fe9865b85872ff9e7 (diff)
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
Diffstat (limited to 'app/Models/DatabaseDAO.php')
-rw-r--r--app/Models/DatabaseDAO.php70
1 files changed, 45 insertions, 25 deletions
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;
}
}