Skip to content

Commit

Permalink
Merge branch 'lastMod' into 'master'
Browse files Browse the repository at this point in the history
[mkcal] Don't change lastModified value of incidences on storage save.

See merge request mer-core/mkcal!25
  • Loading branch information
pvuorela committed Sep 12, 2019
2 parents 76ed7d6 + 82c3649 commit 69e1411
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/sqlitestorage.cpp
Expand Up @@ -2061,7 +2061,14 @@ bool SqliteStorage::Private::saveIncidences(QHash<QString, Incidence::Ptr> &list
validIncidences << *it;
}

(*it)->setLastModified(KDateTime::currentUtcDateTime());
// lastModified is a public field of iCal RFC, so user should be
// able to set its value to arbitrary date and time. This field is
// updated automatically at each incidence modification already by
// ExtendedCalendar::incidenceUpdated(). We're just ensuring that
// the lastModified is valid and set it if not.
if (!(*it)->lastModified().isValid()) {
(*it)->setLastModified(KDateTime::currentUtcDateTime());
}
qCDebug(lcMkcal) << operation << "incidence" << (*it)->uid() << "notebook" << notebookUid;
if (!mFormat->modifyComponents(*it, notebookUid, dbop, stmt1, stmt2, stmt3, stmt4,
stmt5, stmt6, stmt7, stmt8, stmt9, stmt10, stmt11)) {
Expand Down
23 changes: 23 additions & 0 deletions tests/tst_storage.cpp
Expand Up @@ -365,6 +365,29 @@ void tst_storage::tst_dateCreated()
}
}

// Check that lastModified field is not modified by storage,
// but actually updated whenever a modification is done to a stored incidence.
void tst_storage::tst_lastModified()
{
KDateTime dt(QDate(2019, 07, 26), QTime(11, 41), KDateTime::ClockTime);
KCalCore::Event::Ptr event = KCalCore::Event::Ptr(new KCalCore::Event);
event->setDtStart(dt.addDays(1));
event->setSummary("Modified date test event");
event->setLastModified(dt);

m_calendar->addEvent(event, NotebookId);
m_storage->save();
QCOMPARE(event->lastModified(), dt);

reloadDb();
auto fetchEvent = m_calendar->event(event->uid());
QVERIFY(fetchEvent);
QCOMPARE(fetchEvent->lastModified(), dt);

fetchEvent->setDtStart(dt.addDays(2));
QVERIFY(fetchEvent->lastModified().secsTo(KDateTime::currentUtcDateTime()) <= 1);
}

// Ensure that dissociateSingleOccurrence() for events
// given in various time zone or for all day events.
void tst_storage::tst_dissociateSingleOccurrence_data()
Expand Down
1 change: 1 addition & 0 deletions tests/tst_storage.h
Expand Up @@ -32,6 +32,7 @@ private slots:
void tst_rawEvents();
void tst_dateCreated_data();
void tst_dateCreated();
void tst_lastModified();
void tst_dissociateSingleOccurrence_data();
void tst_dissociateSingleOccurrence();
void tst_deleted();
Expand Down

0 comments on commit 69e1411

Please sign in to comment.