aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-08-26 13:04:06 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-08-26 13:04:11 (GMT)
commit1adcbb3e1617446832dbc697374a43ff6effbd71 (patch)
treec298a1f3c96e1fb85f47229da0c33af44795cddb
parent99bd252078997e04ac98655c95a79bd974d938ff (diff)
MOVE: commit current transaction before emitting notification
-rw-r--r--src/server/handler/move.cpp142
1 files changed, 70 insertions, 72 deletions
diff --git a/src/server/handler/move.cpp b/src/server/handler/move.cpp
index 05182ef..90bdfd3 100644
--- a/src/server/handler/move.cpp
+++ b/src/server/handler/move.cpp
@@ -44,97 +44,95 @@ void Move::itemsRetrieved(const QList<qint64> &ids)
const QDateTime mtime = QDateTime::currentDateTime();
- if (qb.exec()) {
- const QVector<PimItem> items = qb.result();
- if (items.isEmpty()) {
- successResponse<Protocol::MoveItemsResponse>();
- return;
- }
+ if (!qb.exec()) {
+ failureResponse("Unable to execute query");
+ return;
+ }
- // Split the list by source collection
- QMap<Entity::Id /* collection */, PimItem> toMove;
- QMap<Entity::Id /* collection */, Collection> sources;
- Q_FOREACH (/*sic!*/ PimItem item, items) {
- if (!item.isValid()) {
- failureResponse("Invalid item in result set!?");
- return;
- }
+ const QVector<PimItem> items = qb.result();
+ if (items.isEmpty()) {
+ successResponse<Protocol::MoveItemsResponse>();
+ return;
+ }
- const Collection source = item.collection();
- if (!source.isValid()) {
- failureResponse("Item without collection found!?");
- return;
- }
- if (!sources.contains(source.id())) {
- sources.insert(source.id(), source);
- }
+ // Split the list by source collection
+ QMap<Entity::Id /* collection */, PimItem> toMove;
+ QMap<Entity::Id /* collection */, Collection> sources;
+ Q_FOREACH (/*sic!*/ PimItem item, items) {
+ if (!item.isValid()) {
+ failureResponse("Invalid item in result set!?");
+ return;
+ }
- Q_ASSERT(item.collectionId() != mDestination.id());
+ const Collection source = item.collection();
+ if (!source.isValid()) {
+ failureResponse("Item without collection found!?");
+ return;
+ }
+ if (!sources.contains(source.id())) {
+ sources.insert(source.id(), source);
+ }
- item.setCollectionId(mDestination.id());
- item.setAtime(mtime);
- item.setDatetime(mtime);
- // if the resource moved itself, we assume it did so because the change happend in the backend
- if (connection()->context()->resource().id() != mDestination.resourceId()) {
- item.setDirty(true);
- }
+ Q_ASSERT(item.collectionId() != mDestination.id());
- if (!item.update()) {
- failureResponse("Unable to update item");
- return;
- }
+ item.setCollectionId(mDestination.id());
+ item.setAtime(mtime);
+ item.setDatetime(mtime);
+ // if the resource moved itself, we assume it did so because the change happend in the backend
+ if (connection()->context()->resource().id() != mDestination.resourceId()) {
+ item.setDirty(true);
+ }
- toMove.insertMulti(source.id(), item);
+ if (!item.update()) {
+ failureResponse("Unable to update item");
+ return;
}
- // Emit notification for each source collection separately
- QVector<PimItem::Id> itemsToResetRID;
- Collection source;
- PimItem::List itemsToMove;
- for (auto it = toMove.cbegin(), end = toMove.cend(); it != end; ++it) {
- if (source.id() != it.key()) {
- if (!itemsToMove.isEmpty()) {
- store->notificationCollector()->itemsMoved(itemsToMove, source, mDestination);
- }
- source = sources.value(it.key());
- itemsToMove.clear();
- }
+ toMove.insertMulti(source.id(), item);
+ }
- itemsToMove.push_back(*it);
+ if (!transaction.commit()) {
+ failureResponse("Unable to commit transaction.");
+ return;
+ }
- // reset RID on inter-resource moves, but only after generating the change notification
- // so that this still contains the old one for the source resource
- const bool isInterResourceMove = it->collection().resource().id() != source.resource().id();
- if (isInterResourceMove) {
- itemsToResetRID.push_back(it->id());
+ // Emit notification for each source collection separately
+ QVector<PimItem::Id> itemsToResetRID;
+ Collection source;
+ PimItem::List itemsToMove;
+ for (auto it = toMove.cbegin(), end = toMove.cend(); it != end; ++it) {
+ if (source.id() != it.key()) {
+ if (!itemsToMove.isEmpty()) {
+ store->notificationCollector()->itemsMoved(itemsToMove, source, mDestination);
}
+ source = sources.value(it.key());
+ itemsToMove.clear();
}
- if (!itemsToMove.isEmpty()) {
- store->notificationCollector()->itemsMoved(itemsToMove, source, mDestination);
- }
+ itemsToMove.push_back(*it);
- // Batch-reset RID for all inter-resource moves
- if (!itemsToResetRID.isEmpty()) {
- QueryBuilder qb(PimItem::tableName(), QueryBuilder::Update);
- qb.setColumnValue(PimItem::remoteIdColumn(), QString());
- ItemQueryHelper::itemSetToQuery(itemsToResetRID, connection()->context(), qb);
- if (!qb.exec()) {
- failureResponse("Unable to update RID");
- return;
- }
+ // reset RID on inter-resource moves, but only after generating the change notification
+ // so that this still contains the old one for the source resource
+ const bool isInterResourceMove = it->collection().resource().id() != source.resource().id();
+ if (isInterResourceMove) {
+ itemsToResetRID.push_back(it->id());
}
-
- } else {
- failureResponse("Unable to execute query");
- return;
}
- if (!transaction.commit()) {
- failureResponse("Unable to commit transaction.");
- return;
+ if (!itemsToMove.isEmpty()) {
+ store->notificationCollector()->itemsMoved(itemsToMove, source, mDestination);
}
+ // Batch-reset RID for all inter-resource moves
+ if (!itemsToResetRID.isEmpty()) {
+ QueryBuilder qb(PimItem::tableName(), QueryBuilder::Update);
+ qb.setColumnValue(PimItem::remoteIdColumn(), QString());
+ ItemQueryHelper::itemSetToQuery(itemsToResetRID, connection()->context(), qb);
+ if (!qb.exec()) {
+ failureResponse("Unable to update RID");
+ return;
+ }
+ }
}
bool Move::parseStream()