Skip to content

Commit

Permalink
Merge branch 'delete' into 'master'
Browse files Browse the repository at this point in the history
[mkcal] Don't fail to load incidence after occurrence as been deleted.  Contributes to JB#24579

See merge request mer-core/mkcal!36
  • Loading branch information
chriadam committed Apr 7, 2020
2 parents b36df21 + b6a247d commit b7bcf18
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/sqlitestorage.cpp
Expand Up @@ -1633,6 +1633,17 @@ bool SqliteStorage::notifyOpened(const Incidence::Ptr &incidence)
return false;
}

static bool isContaining(const QMultiHash<QString, Incidence::Ptr> &list, const Incidence::Ptr &incidence)
{
QMultiHash<QString, Incidence::Ptr>::ConstIterator it = list.find(incidence->uid());
for (; it != list.constEnd(); ++it) {
if ((*it)->recurrenceId() == incidence->recurrenceId()) {
return true;
}
}
return false;
}

int SqliteStorage::Private::loadIncidences(sqlite3_stmt *stmt1,
const char *query2, int qsize2,
const char *query3, int qsize3,
Expand Down Expand Up @@ -1674,9 +1685,13 @@ int SqliteStorage::Private::loadIncidences(sqlite3_stmt *stmt1,
mFormat->selectComponents(stmt1, stmt2, stmt3, stmt4, stmt5, stmt6, notebookUid))) {
bool hasNotebook = mCalendar->hasValidNotebook(notebookUid);
bool added = true;
if (mIncidencesToInsert.contains(incidence->uid()) ||
mIncidencesToUpdate.contains(incidence->uid()) ||
mIncidencesToDelete.contains(incidence->uid()) ||
// Cannot use .contains(incidence->uid(), incidence) here, like
// in the rest of the file, since incidence here is a new one
// returned by the selectComponents() that cannot by design be already
// in the multihash tables.
if (isContaining(mIncidencesToInsert, incidence) ||
isContaining(mIncidencesToUpdate, incidence) ||
isContaining(mIncidencesToDelete, incidence) ||
(mStorage->validateNotebooks() && !hasNotebook)) {
qCWarning(lcMkcal) << "not loading" << incidence->uid() << notebookUid
<< (!hasNotebook ? "(invalidated notebook)" : "(local changes)");
Expand Down
48 changes: 48 additions & 0 deletions tests/tst_storage.cpp
Expand Up @@ -1766,6 +1766,54 @@ void tst_storage::tst_alarms()
#endif
}

void tst_storage::tst_load()
{
mKCal::Notebook::Ptr notebook =
mKCal::Notebook::Ptr(new mKCal::Notebook("123456789-load",
"test notebook",
QLatin1String(""),
"#001122",
false, // Not shared.
true, // Is master.
false, // Not synced to Ovi.
false, // Writable.
true, // Visible.
QLatin1String(""),
QLatin1String(""),
0));
m_storage->addNotebook(notebook);

KCalCore::Event::Ptr event = KCalCore::Event::Ptr(new KCalCore::Event);
event->setDtStart(KDateTime::currentUtcDateTime());
event->setSummary("Deleted event");
event->setCreated(KDateTime::currentUtcDateTime().addSecs(-3));
event->recurrence()->setDaily(1);
KCalCore::Event::Ptr occurrence(event->clone());
occurrence->clearRecurrence();
occurrence->setDtStart(event->dtStart().addDays(1));
occurrence->setRecurrenceId(event->dtStart().addDays(1));
occurrence->setSummary("Deleted occurrence");
event->recurrence()->addExDateTime(occurrence->recurrenceId());

QVERIFY(m_calendar->addEvent(event, notebook->uid()));
QVERIFY(m_calendar->addEvent(occurrence, notebook->uid()));
QVERIFY(m_storage->save());
reloadDb();

QVERIFY(m_calendar->events().isEmpty());

QVERIFY(m_storage->load(occurrence->uid(), occurrence->recurrenceId()));
QCOMPARE(m_calendar->events().length(), 1);
QVERIFY(m_calendar->deleteIncidence(m_calendar->incidence(occurrence->uid(), occurrence->recurrenceId())));
QVERIFY(m_calendar->events().isEmpty());
QVERIFY(m_storage->load(occurrence->uid(), occurrence->recurrenceId()));
QVERIFY(m_calendar->events().isEmpty());

QVERIFY(m_storage->load(event->uid()));
QCOMPARE(m_calendar->events().length(), 1);
QVERIFY(m_calendar->deleteIncidence(m_calendar->incidence(event->uid())));
}

void tst_storage::openDb(bool clear)
{
m_calendar = ExtendedCalendar::Ptr(new ExtendedCalendar(KDateTime::Spec::LocalZone()));
Expand Down
1 change: 1 addition & 0 deletions tests/tst_storage.h
Expand Up @@ -69,6 +69,7 @@ private slots:
void tst_deleteAllEvents();
void tst_calendarProperties();
void tst_alarms();
void tst_load();

private:
void openDb(bool clear = false);
Expand Down

0 comments on commit b7bcf18

Please sign in to comment.