1 From 1ce732668b2b3e4d735665bd60e1a18f139b1de2 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= <dvratil@redhat.com>
3 Date: Fri, 5 Dec 2014 18:49:15 +0100
4 Subject: [PATCH 23/30] Always create a new PartType when it does not exist
6 Fixes a regression introduced in previous commit that caused Part operations
7 to fail when specified PartType did not exist in Akonadi storage yet.
9 server/src/handler/append.cpp | 4 ++--
10 server/src/storage/datastore.cpp | 2 +-
11 server/src/storage/parttypehelper.cpp | 16 +++++++++++++++-
12 server/src/storage/parttypehelper.h | 8 ++++++++
13 4 files changed, 26 insertions(+), 4 deletions(-)
15 diff --git a/server/src/handler/append.cpp b/server/src/handler/append.cpp
16 index b594e27..15fb9ea 100644
17 --- a/server/src/handler/append.cpp
18 +++ b/server/src/handler/append.cpp
19 @@ -134,7 +134,7 @@ bool Append::commit()
21 // wrap data into a part
23 - part.setPartType( PartType::retrieveByFQName( QLatin1String("PLD"), QLatin1String("RFC822") ) );
24 + part.setPartType( PartTypeHelper::fromFqName( QLatin1String("PLD"), QLatin1String("RFC822") ) );
25 part.setData( m_data );
26 part.setPimItemId( item.id() );
27 part.setDatasize( dataSize );
28 @@ -148,7 +148,7 @@ bool Append::commit()
29 //akDebug() << "Append handler: doPreprocessing is" << doPreprocessing;
30 if ( doPreprocessing ) {
32 - hiddenAttribute.setPartType( PartType::retrieveByFQName( QLatin1String("ATR"), QLatin1String("HIDDEN") ) );
33 + hiddenAttribute.setPartType( PartTypeHelper::fromFqName( QLatin1String("ATR"), QLatin1String("HIDDEN") ) );
34 hiddenAttribute.setData( QByteArray() );
35 hiddenAttribute.setPimItemId( item.id() );
36 hiddenAttribute.setDatasize( 0 );
37 diff --git a/server/src/storage/datastore.cpp b/server/src/storage/datastore.cpp
38 index 0983d84..c9fa0c3 100644
39 --- a/server/src/storage/datastore.cpp
40 +++ b/server/src/storage/datastore.cpp
41 @@ -1027,7 +1027,7 @@ bool DataStore::unhideAllPimItems()
44 return PartHelper::remove( Part::partTypeIdFullColumnName(),
45 - PartType::retrieveByFQName( QLatin1String("ATR"), QLatin1String("HIDDEN") ).id() );
46 + PartTypeHelper::fromFqName( QLatin1String("ATR"), QLatin1String("HIDDEN") ).id() );
47 } catch ( ... ) {} // we can live with this failing
50 diff --git a/server/src/storage/parttypehelper.cpp b/server/src/storage/parttypehelper.cpp
51 index 7654108..bcff9c6 100644
52 --- a/server/src/storage/parttypehelper.cpp
53 +++ b/server/src/storage/parttypehelper.cpp
54 @@ -37,7 +37,8 @@ QPair< QString, QString > PartTypeHelper::parseFqName(const QString& fqName)
55 PartType PartTypeHelper::fromFqName(const QString& fqName)
57 const QPair<QString, QString> p = parseFqName( fqName );
58 - return PartType::retrieveByFQName(p.first, p.second);
59 + return fromFqName(p.first, p.second);
63 PartType PartTypeHelper::fromFqName(const QByteArray& fqName)
64 @@ -45,6 +46,19 @@ PartType PartTypeHelper::fromFqName(const QByteArray& fqName)
65 return fromFqName( QLatin1String(fqName) );
68 +PartType PartTypeHelper::fromFqName(const QString& ns, const QString& name)
70 + PartType partType = PartType::retrieveByFQName(ns, name);
71 + if (!partType.isValid()) {
72 + PartType pt(name, ns);
74 + throw PartTypeException( "Failed to append part type" );
81 Query::Condition PartTypeHelper::conditionFromFqName(const QString& fqName)
83 const QPair<QString, QString> p = parseFqName( fqName );
84 diff --git a/server/src/storage/parttypehelper.h b/server/src/storage/parttypehelper.h
85 index 4c4f42f..6d3cf74 100644
86 --- a/server/src/storage/parttypehelper.h
87 +++ b/server/src/storage/parttypehelper.h
88 @@ -48,6 +48,14 @@ namespace PartTypeHelper
89 PartType fromFqName( const QByteArray &fqName );
92 + * Retrieve (or create) PartType for the given namespace and name
93 + * @param ns Namespace
95 + * @throws PartTypeException
97 + PartType fromFqName( const QString &ns, const QString &name );
100 * Returns a query condition that matches the given part.
101 * @param fqName fully-qualified part type name
102 * @throws PartTypeException