diff --git a/resources/misc/db_update_mysql_4_5.sql b/resources/misc/db_update_mysql_4_5.sql index 95c50bb4e..8367a5c92 100755 --- a/resources/misc/db_update_mysql_4_5.sql +++ b/resources/misc/db_update_mysql_4_5.sql @@ -10,14 +10,14 @@ CREATE TABLE IF NOT EXISTS OwnCloudAccounts ( -- ! UPDATE Categories SET custom_id = (SELECT id FROM Categories t WHERE t.id = Categories.id) -WHERE Categories.custom_id IS NULL; +WHERE Categories.custom_id IS NULL OR Categories.custom_id = ''; -- ! UPDATE Feeds SET custom_id = (SELECT id FROM Feeds t WHERE t.id = Feeds.id) -WHERE Feeds.custom_id IS NULL; +WHERE Feeds.custom_id IS NULL OR Feeds.custom_id = ''; -- ! UPDATE Messages SET custom_id = (SELECT id FROM Messages t WHERE t.id = Messages.id) -WHERE Messages.custom_id IS NULL; +WHERE Messages.custom_id IS NULL OR Messages.custom_id = ''; -- ! UPDATE Information SET inf_value = '5' WHERE inf_key = 'schema_version'; \ No newline at end of file diff --git a/resources/misc/db_update_sqlite_4_5.sql b/resources/misc/db_update_sqlite_4_5.sql index 95c50bb4e..8367a5c92 100755 --- a/resources/misc/db_update_sqlite_4_5.sql +++ b/resources/misc/db_update_sqlite_4_5.sql @@ -10,14 +10,14 @@ CREATE TABLE IF NOT EXISTS OwnCloudAccounts ( -- ! UPDATE Categories SET custom_id = (SELECT id FROM Categories t WHERE t.id = Categories.id) -WHERE Categories.custom_id IS NULL; +WHERE Categories.custom_id IS NULL OR Categories.custom_id = ''; -- ! UPDATE Feeds SET custom_id = (SELECT id FROM Feeds t WHERE t.id = Feeds.id) -WHERE Feeds.custom_id IS NULL; +WHERE Feeds.custom_id IS NULL OR Feeds.custom_id = ''; -- ! UPDATE Messages SET custom_id = (SELECT id FROM Messages t WHERE t.id = Messages.id) -WHERE Messages.custom_id IS NULL; +WHERE Messages.custom_id IS NULL OR Messages.custom_id = ''; -- ! UPDATE Information SET inf_value = '5' WHERE inf_key = 'schema_version'; \ No newline at end of file diff --git a/src/services/abstract/feed.cpp b/src/services/abstract/feed.cpp index 83efa6089..5dde95f59 100755 --- a/src/services/abstract/feed.cpp +++ b/src/services/abstract/feed.cpp @@ -206,6 +206,7 @@ int Feed::updateMessages(const QList &messages) { if (message.m_customId.isEmpty()) { // We need to recognize existing messages according URL & AUTHOR. + // NOTE: This concerns messages from standard account. query_select_with_url.bindValue(QSL(":feed"), custom_id); query_select_with_url.bindValue(QSL(":url"), message.m_url); query_select_with_url.bindValue(QSL(":author"), message.m_author); @@ -222,6 +223,7 @@ int Feed::updateMessages(const QList &messages) { } else { // We can recognize existing messages via their custom ID. + // NOTE: This concerns messages from custom accounts, like TT-RSS or ownCloud News. query_select_with_id.bindValue(QSL(":account_id"), account_id); query_select_with_id.bindValue(QSL(":custom_id"), message.m_customId); @@ -243,7 +245,7 @@ int Feed::updateMessages(const QList &messages) { // 1) Message has custom ID AND (its date OR read status OR starred status are changed). // 2) Message has its date fetched from feed AND its date is different from date in DB. if (/* 1 */ (!message.m_customId.isEmpty() && (message.m_created.toMSecsSinceEpoch() != date_existing_message || message.m_isRead != is_read_existing_message || message.m_isImportant != is_important_existing_message)) || - /* 2 */ (message.m_createdFromFeed && message.m_created.toMSecsSinceEpoch() > date_existing_message)) { + /* 2 */ (message.m_createdFromFeed && message.m_created.toMSecsSinceEpoch() != date_existing_message)) { // Message exists, it is changed, update it. query_update.bindValue(QSL(":title"), message.m_title); query_update.bindValue(QSL(":is_read"), (int) message.m_isRead); @@ -288,6 +290,14 @@ int Feed::updateMessages(const QList &messages) { } } + // Now, fixup custom IDS for messages which initially did not have them, + // just to keep the data consistent. + if (database.exec("UPDATE Messages " + "SET custom_id = (SELECT id FROM Messages t WHERE t.id = Messages.id) " + "WHERE Messages.custom_id IS NULL OR Messages.custom_id = '';").lastError().isValid()) { + qWarning("Failed to set custom ID for all messages."); + } + if (!database.commit()) { database.rollback(); qDebug("Transaction commit for message downloader failed."); @@ -305,7 +315,7 @@ int Feed::updateMessages(const QList &messages) { updateCounts(true); items_to_update.append(this); - if (getParentServiceRoot()->recycleBin() != NULL && anything_updated ) { + if (getParentServiceRoot()->recycleBin() != NULL && anything_updated) { getParentServiceRoot()->recycleBin()->updateCounts(true); items_to_update.append(getParentServiceRoot()->recycleBin()); } diff --git a/src/services/abstract/feed.h b/src/services/abstract/feed.h index 5ff715792..c55232b5b 100755 --- a/src/services/abstract/feed.h +++ b/src/services/abstract/feed.h @@ -43,7 +43,7 @@ class Feed : public RootItem { enum Status { Normal = 0, NewMessages = 1, - Error = 2, + Error = 2, ParsingError = 3, OtherError = 4 };