mirror of https://github.com/KDE/kasts.git
Continue update of episodes even if gpodder server is unavailable
This commit is contained in:
parent
8097ffe513
commit
c44abc66ba
|
@ -211,83 +211,107 @@ void SyncJob::syncSubscriptions()
|
||||||
if (subRequest->error() || subRequest->aborted()) {
|
if (subRequest->error() || subRequest->aborted()) {
|
||||||
if (subRequest->aborted()) {
|
if (subRequest->aborted()) {
|
||||||
Q_EMIT infoMessage(this, getProgressMessage(Aborted));
|
Q_EMIT infoMessage(this, getProgressMessage(Aborted));
|
||||||
|
emitResult();
|
||||||
|
return;
|
||||||
} else if (subRequest->error()) {
|
} else if (subRequest->error()) {
|
||||||
setError(SyncJobError::SubscriptionDownloadError);
|
setError(SyncJobError::SubscriptionDownloadError);
|
||||||
setErrorText(subRequest->errorString());
|
setErrorText(subRequest->errorString());
|
||||||
Q_EMIT infoMessage(this, getProgressMessage(Error));
|
Q_EMIT infoMessage(this, getProgressMessage(Error));
|
||||||
}
|
}
|
||||||
emitResult();
|
// If this is a force sync (i.e. processing all updates), then
|
||||||
return;
|
// continue with fetching podcasts updates, otherwise it's not
|
||||||
}
|
// possible to update new episodes if the sync server happens to be
|
||||||
qCDebug(kastsSync) << "Finished device update request";
|
// down or is not reachable.
|
||||||
|
if (m_forceFetchAll) {
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare(QStringLiteral("SELECT url FROM Feeds;"));
|
||||||
|
Database::instance().execute(query);
|
||||||
|
while (query.next()) {
|
||||||
|
QString url = query.value(0).toString();
|
||||||
|
if (!m_feedsToBeUpdatedSubs.contains(url)) {
|
||||||
|
m_feedsToBeUpdatedSubs += url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_feedUpdateTotal = m_feedsToBeUpdatedSubs.count();
|
||||||
|
setProcessedAmount(KJob::Unit::Items, processedAmount(KJob::Unit::Items) + 2); // skip upload step
|
||||||
|
Q_EMIT infoMessage(this, getProgressMessage(SubscriptionFetch));
|
||||||
|
|
||||||
qulonglong newSubscriptionTimestamp = subRequest->timestamp();
|
QTimer::singleShot(0, this, &SyncJob::fetchModifiedSubscriptions);
|
||||||
QStringList remoteAddFeedList, remoteRemoveFeedList;
|
|
||||||
|
|
||||||
removeSubscriptionChangeConflicts(remoteAddFeedList, remoteRemoveFeedList);
|
|
||||||
|
|
||||||
for (const QString &url : subRequest->addList()) {
|
|
||||||
qCDebug(kastsSync) << "Sync add feed:" << url;
|
|
||||||
if (DataManager::instance().feedExists(url)) {
|
|
||||||
qCDebug(kastsSync) << "this one we have; do nothing";
|
|
||||||
} else {
|
} else {
|
||||||
qCDebug(kastsSync) << "this one we don't have; add this feed";
|
emitResult();
|
||||||
remoteAddFeedList << url;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
qCDebug(kastsSync) << "Finished device update request";
|
||||||
|
|
||||||
for (const QString &url : subRequest->removeList()) {
|
qulonglong newSubscriptionTimestamp = subRequest->timestamp();
|
||||||
qCDebug(kastsSync) << "Sync remove feed:" << url;
|
QStringList remoteAddFeedList, remoteRemoveFeedList;
|
||||||
if (DataManager::instance().feedExists(url)) {
|
|
||||||
qCDebug(kastsSync) << "this one we have; needs to be removed";
|
removeSubscriptionChangeConflicts(remoteAddFeedList, remoteRemoveFeedList);
|
||||||
remoteRemoveFeedList << url;
|
|
||||||
} else {
|
for (const QString &url : subRequest->addList()) {
|
||||||
qCDebug(kastsSync) << "this one we don't have; it was already removed locally; do nothing";
|
qCDebug(kastsSync) << "Sync add feed:" << url;
|
||||||
|
if (DataManager::instance().feedExists(url)) {
|
||||||
|
qCDebug(kastsSync) << "this one we have; do nothing";
|
||||||
|
} else {
|
||||||
|
qCDebug(kastsSync) << "this one we don't have; add this feed";
|
||||||
|
remoteAddFeedList << url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
qCDebug(kastsSync) << "localAddFeedList" << localAddFeedList;
|
for (const QString &url : subRequest->removeList()) {
|
||||||
qCDebug(kastsSync) << "localRemoveFeedList" << localRemoveFeedList;
|
qCDebug(kastsSync) << "Sync remove feed:" << url;
|
||||||
qCDebug(kastsSync) << "remoteAddFeedList" << remoteAddFeedList;
|
if (DataManager::instance().feedExists(url)) {
|
||||||
qCDebug(kastsSync) << "remoteRemoveFeedList" << remoteRemoveFeedList;
|
qCDebug(kastsSync) << "this one we have; needs to be removed";
|
||||||
|
remoteRemoveFeedList << url;
|
||||||
|
} else {
|
||||||
|
qCDebug(kastsSync) << "this one we don't have; it was already removed locally; do nothing";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now we apply the remote changes locally:
|
qCDebug(kastsSync) << "localAddFeedList" << localAddFeedList;
|
||||||
Sync::instance().applySubscriptionChangesLocally(remoteAddFeedList, remoteRemoveFeedList);
|
qCDebug(kastsSync) << "localRemoveFeedList" << localRemoveFeedList;
|
||||||
|
qCDebug(kastsSync) << "remoteAddFeedList" << remoteAddFeedList;
|
||||||
|
qCDebug(kastsSync) << "remoteRemoveFeedList" << remoteRemoveFeedList;
|
||||||
|
|
||||||
// We defer fetching the new feeds, since we will fetch them later on.
|
// Now we apply the remote changes locally:
|
||||||
// if this is the first sync or a force sync, then add all local feeds to
|
Sync::instance().applySubscriptionChangesLocally(remoteAddFeedList, remoteRemoveFeedList);
|
||||||
// be updated
|
|
||||||
if (!subscriptionTimestampExists || m_forceFetchAll) {
|
// We defer fetching the new feeds, since we will fetch them later on.
|
||||||
QSqlQuery query;
|
// if this is the first sync or a force sync, then add all local feeds to
|
||||||
query.prepare(QStringLiteral("SELECT url FROM Feeds;"));
|
// be updated
|
||||||
Database::instance().execute(query);
|
if (!subscriptionTimestampExists || m_forceFetchAll) {
|
||||||
while (query.next()) {
|
QSqlQuery query;
|
||||||
QString url = query.value(0).toString();
|
query.prepare(QStringLiteral("SELECT url FROM Feeds;"));
|
||||||
if (!m_feedsToBeUpdatedSubs.contains(url)) {
|
Database::instance().execute(query);
|
||||||
|
while (query.next()) {
|
||||||
|
QString url = query.value(0).toString();
|
||||||
|
if (!m_feedsToBeUpdatedSubs.contains(url)) {
|
||||||
|
m_feedsToBeUpdatedSubs += url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the new feeds to the list of feeds that need to be refreshed.
|
||||||
|
// We check with feedExists to make sure not to add the same podcast
|
||||||
|
// with a slightly different url
|
||||||
|
for (const QString &url : remoteAddFeedList) {
|
||||||
|
if (!DataManager::instance().feedExists(url)) {
|
||||||
m_feedsToBeUpdatedSubs += url;
|
m_feedsToBeUpdatedSubs += url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_feedUpdateTotal = m_feedsToBeUpdatedSubs.count();
|
||||||
|
|
||||||
|
qCDebug(kastsSync) << "newSubscriptionTimestamp" << newSubscriptionTimestamp;
|
||||||
|
updateDBTimestamp(newSubscriptionTimestamp, subscriptionTimestampLabel);
|
||||||
|
|
||||||
|
setProcessedAmount(KJob::Unit::Items, processedAmount(KJob::Unit::Items) + 1);
|
||||||
|
Q_EMIT infoMessage(this, getProgressMessage(SubscriptionUpload));
|
||||||
|
|
||||||
|
QTimer::singleShot(0, this, [=]() {
|
||||||
|
uploadSubscriptions(localAddFeedList, localRemoveFeedList);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the new feeds to the list of feeds that need to be refreshed.
|
|
||||||
// We check with feedExists to make sure not to add the same podcast
|
|
||||||
// with a slightly different url
|
|
||||||
for (const QString &url : remoteAddFeedList) {
|
|
||||||
if (!DataManager::instance().feedExists(url)) {
|
|
||||||
m_feedsToBeUpdatedSubs += url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_feedUpdateTotal = m_feedsToBeUpdatedSubs.count();
|
|
||||||
|
|
||||||
qCDebug(kastsSync) << "newSubscriptionTimestamp" << newSubscriptionTimestamp;
|
|
||||||
updateDBTimestamp(newSubscriptionTimestamp, subscriptionTimestampLabel);
|
|
||||||
|
|
||||||
setProcessedAmount(KJob::Unit::Items, processedAmount(KJob::Unit::Items) + 1);
|
|
||||||
Q_EMIT infoMessage(this, getProgressMessage(SubscriptionUpload));
|
|
||||||
|
|
||||||
QTimer::singleShot(0, this, [=]() {
|
|
||||||
uploadSubscriptions(localAddFeedList, localRemoveFeedList);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue