Changeset View
Changeset View
Standalone View
Standalone View
src/server/handler/collectionmodifyhandler.cpp
Show All 17 Lines | |||||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "collectionmodifyhandler.h" | 20 | #include "collectionmodifyhandler.h" | ||
21 | 21 | | |||
22 | #include "akonadi.h" | 22 | #include "akonadi.h" | ||
23 | #include "connection.h" | 23 | #include "connection.h" | ||
24 | #include "handlerhelper.h" | 24 | #include "handlerhelper.h" | ||
25 | #include "cachecleaner.h" | 25 | #include "cachecleaner.h" | ||
26 | #include "collectionreferencemanager.h" | | |||
27 | #include "intervalcheck.h" | 26 | #include "intervalcheck.h" | ||
28 | #include "storage/datastore.h" | 27 | #include "storage/datastore.h" | ||
29 | #include "storage/transaction.h" | 28 | #include "storage/transaction.h" | ||
30 | #include "storage/itemretriever.h" | 29 | #include "storage/itemretriever.h" | ||
31 | #include "storage/selectquerybuilder.h" | 30 | #include "storage/selectquerybuilder.h" | ||
32 | #include "storage/collectionqueryhelper.h" | 31 | #include "storage/collectionqueryhelper.h" | ||
33 | #include "search/searchmanager.h" | 32 | #include "search/searchmanager.h" | ||
34 | #include "akonadiserver_debug.h" | 33 | #include "akonadiserver_debug.h" | ||
Show All 24 Lines | 57 | if (!retriever.exec()) { | |||
59 | throw HandlerException(retriever.lastError()); | 58 | throw HandlerException(retriever.lastError()); | ||
60 | } | 59 | } | ||
61 | } | 60 | } | ||
62 | } | 61 | } | ||
63 | 62 | | |||
64 | DataStore *db = connection()->storageBackend(); | 63 | DataStore *db = connection()->storageBackend(); | ||
65 | Transaction transaction(db, QStringLiteral("MODIFY")); | 64 | Transaction transaction(db, QStringLiteral("MODIFY")); | ||
66 | QList<QByteArray> changes; | 65 | QList<QByteArray> changes; | ||
67 | bool referencedChanged = false; | | |||
68 | 66 | | |||
69 | if (cmd.modifiedParts() & Protocol::ModifyCollectionCommand::MimeTypes) { | 67 | if (cmd.modifiedParts() & Protocol::ModifyCollectionCommand::MimeTypes) { | ||
70 | QStringList mts = cmd.mimeTypes(); | 68 | QStringList mts = cmd.mimeTypes(); | ||
71 | const MimeType::List currentMts = collection.mimeTypes(); | 69 | const MimeType::List currentMts = collection.mimeTypes(); | ||
72 | bool equal = true; | 70 | bool equal = true; | ||
73 | for (const MimeType ¤tMt : currentMts) { | 71 | for (const MimeType ¤tMt : currentMts) { | ||
74 | const int removeMts = mts.removeAll(currentMt.name()); | 72 | const int removeMts = mts.removeAll(currentMt.name()); | ||
75 | if (removeMts > 0) { | 73 | if (removeMts > 0) { | ||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Line(s) | 215 | if (cmd.displayPref() != static_cast<Tristate>(collection.displayPref())) { | |||
219 | changes.append(AKONADI_PARAM_DISPLAY); | 217 | changes.append(AKONADI_PARAM_DISPLAY); | ||
220 | } | 218 | } | ||
221 | if (cmd.indexPref() != static_cast<Tristate>(collection.indexPref())) { | 219 | if (cmd.indexPref() != static_cast<Tristate>(collection.indexPref())) { | ||
222 | collection.setIndexPref(static_cast<Collection::Tristate>(cmd.indexPref())); | 220 | collection.setIndexPref(static_cast<Collection::Tristate>(cmd.indexPref())); | ||
223 | changes.append(AKONADI_PARAM_INDEX); | 221 | changes.append(AKONADI_PARAM_INDEX); | ||
224 | } | 222 | } | ||
225 | } | 223 | } | ||
226 | 224 | | |||
227 | if (cmd.modifiedParts() & Protocol::ModifyCollectionCommand::Referenced) { | | |||
228 | const bool wasReferencedFromSession = connection()->collectionReferenceManager()->isReferenced(collection.id(), connection()->sessionId()); | | |||
229 | connection()->collectionReferenceManager()->referenceCollection(connection()->sessionId(), collection, cmd.referenced()); | | |||
230 | const bool referenced = connection()->collectionReferenceManager()->isReferenced(collection.id()); | | |||
231 | if (cmd.referenced() != wasReferencedFromSession) { | | |||
232 | changes.append(AKONADI_PARAM_REFERENCED); | | |||
233 | } | | |||
234 | if (referenced != collection.referenced()) { | | |||
235 | referencedChanged = true; | | |||
236 | collection.setReferenced(referenced); | | |||
237 | } | | |||
238 | } | | |||
239 | | ||||
240 | if (cmd.modifiedParts() & Protocol::ModifyCollectionCommand::RemovedAttributes) { | 225 | if (cmd.modifiedParts() & Protocol::ModifyCollectionCommand::RemovedAttributes) { | ||
241 | Q_FOREACH (const QByteArray &attr, cmd.removedAttributes()) { | 226 | Q_FOREACH (const QByteArray &attr, cmd.removedAttributes()) { | ||
242 | if (db->removeCollectionAttribute(collection, attr)) { | 227 | if (db->removeCollectionAttribute(collection, attr)) { | ||
243 | changes.append(attr); | 228 | changes.append(attr); | ||
244 | } | 229 | } | ||
245 | } | 230 | } | ||
246 | } | 231 | } | ||
247 | 232 | | |||
Show All 32 Lines | 235 | for (auto iter = attrs.cbegin(), end = attrs.cend(); iter != end; ++iter) { | |||
280 | } | 265 | } | ||
281 | } | 266 | } | ||
282 | } | 267 | } | ||
283 | 268 | | |||
284 | if (!changes.isEmpty()) { | 269 | if (!changes.isEmpty()) { | ||
285 | if (collection.hasPendingChanges() && !collection.update()) { | 270 | if (collection.hasPendingChanges() && !collection.update()) { | ||
286 | return failureResponse("Unable to update collection"); | 271 | return failureResponse("Unable to update collection"); | ||
287 | } | 272 | } | ||
288 | //This must be after the collection was updated in the db. The resource will immediately request a copy of the collection. | | |||
289 | if (AkonadiServer::instance()->intervalChecker() && collection.referenced() && referencedChanged) { | | |||
290 | AkonadiServer::instance()->intervalChecker()->requestCollectionSync(collection); | | |||
291 | } | | |||
292 | db->notificationCollector()->collectionChanged(collection, changes); | 273 | db->notificationCollector()->collectionChanged(collection, changes); | ||
293 | //For backwards compatibility. Must be after the changed notification (otherwise the compression removes it). | 274 | //For backwards compatibility. Must be after the changed notification (otherwise the compression removes it). | ||
294 | if (changes.contains(AKONADI_PARAM_ENABLED)) { | 275 | if (changes.contains(AKONADI_PARAM_ENABLED)) { | ||
295 | if (collection.enabled()) { | 276 | if (collection.enabled()) { | ||
296 | db->notificationCollector()->collectionSubscribed(collection); | 277 | db->notificationCollector()->collectionSubscribed(collection); | ||
297 | } else { | 278 | } else { | ||
298 | db->notificationCollector()->collectionUnsubscribed(collection); | 279 | db->notificationCollector()->collectionUnsubscribed(collection); | ||
299 | } | 280 | } | ||
Show All 14 Lines |