Akonadi

itemdeletehandler.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "itemdeletehandler.h"
8 
9 #include "connection.h"
10 #include "storage/datastore.h"
11 #include "storage/itemqueryhelper.h"
12 #include "storage/selectquerybuilder.h"
13 #include "storage/transaction.h"
14 
15 #include <private/scope_p.h>
16 
17 using namespace Akonadi;
18 using namespace Akonadi::Server;
19 
20 ItemDeleteHandler::ItemDeleteHandler(AkonadiServer &akonadi)
21  : Handler(akonadi)
22 {
23 }
24 
25 bool ItemDeleteHandler::parseStream()
26 {
27  const auto &cmd = Protocol::cmdCast<Protocol::DeleteItemsCommand>(m_command);
28 
29  CommandContext context = connection()->context();
30  if (!context.setScopeContext(cmd.scopeContext())) {
31  return failureResponse(QStringLiteral("Invalid scope context"));
32  }
33 
35  ItemQueryHelper::scopeToQuery(cmd.items(), context, qb);
36 
37  DataStore *store = connection()->storageBackend();
38  Transaction transaction(store, QStringLiteral("REMOVE"));
39 
40  if (!qb.exec()) {
41  return failureResponse("Unable to execute query");
42  }
43 
44  const QVector<PimItem> items = qb.result();
45  if (items.isEmpty()) {
46  return failureResponse("No items found");
47  }
48  if (!store->cleanupPimItems(items)) {
49  return failureResponse("Deletion failed");
50  }
51 
52  if (!transaction.commit()) {
53  return failureResponse("Unable to commit transaction");
54  }
55 
56  return successResponse<Protocol::DeleteItemsResponse>();
57 }
This class handles all the database access.
Definition: datastore.h:94
bool isEmpty() const const
Helper class for DataStore transaction handling.
Definition: transaction.h:22
QVector< T > result()
Returns the result of this SELECT query.
virtual bool cleanupPimItems(const PimItem::List &items, bool silent=false)
Removes the pim item and all referenced data ( e.g.
Definition: datastore.cpp:1186
bool exec()
Executes the query, returns true on success.
Helper class for creating and executing database SELECT queries.
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition: handler.h:39
bool commit()
Commits the transaction.
Definition: transaction.cpp:29
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:48 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.