Akonadi

collectiondeletehandler.cpp
1 /*
2  SPDX-FileCopyrightText: 2006 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "collectiondeletehandler.h"
8 
9 #include "connection.h"
10 #include "handlerhelper.h"
11 #include "search/searchmanager.h"
12 #include "storage/collectionqueryhelper.h"
13 #include "storage/datastore.h"
14 #include "storage/selectquerybuilder.h"
15 #include "storage/transaction.h"
16 
17 #include <private/scope_p.h>
18 
19 using namespace Akonadi;
20 using namespace Akonadi::Server;
21 
22 CollectionDeleteHandler::CollectionDeleteHandler(AkonadiServer &akonadi)
23  : Handler(akonadi)
24 {
25 }
26 
27 bool CollectionDeleteHandler::deleteRecursive(Collection &col)
28 {
29  Collection::List children = col.children();
30  for (Collection &child : children) {
31  if (!deleteRecursive(child)) {
32  return false;
33  }
34  }
35 
36  DataStore *db = connection()->storageBackend();
37  return db->cleanupCollection(col);
38 }
39 
40 bool CollectionDeleteHandler::parseStream()
41 {
42  const auto &cmd = Protocol::cmdCast<Protocol::DeleteCollectionCommand>(m_command);
43 
44  Collection collection = HandlerHelper::collectionFromScope(cmd.collection(), connection()->context());
45  if (!collection.isValid()) {
46  return failureResponse(QStringLiteral("No such collection."));
47  }
48 
49  // handle virtual folders
50  if (collection.resource().name() == QLatin1String(AKONADI_SEARCH_RESOURCE)) {
51  // don't delete virtual root
52  if (collection.parentId() == 0) {
53  return failureResponse(QStringLiteral("Cannot delete virtual root collection"));
54  }
55  }
56 
57  Transaction transaction(storageBackend(), QStringLiteral("DELETE"));
58 
59  if (!deleteRecursive(collection)) {
60  return failureResponse(QStringLiteral("Unable to delete collection"));
61  }
62 
63  if (!transaction.commit()) {
64  return failureResponse(QStringLiteral("Unable to commit transaction"));
65  }
66 
67  return successResponse<Protocol::DeleteCollectionResponse>();
68 }
This class handles all the database access.
Definition: datastore.h:94
Helper class for DataStore transaction handling.
Definition: transaction.h:22
Represents a collection of PIM items.
Definition: collection.h:61
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition: handler.h:39
virtual bool cleanupCollection(Collection &collection)
removes the given collection and all its content
Definition: datastore.cpp:801
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 Thu Oct 6 2022 04:03:44 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.