~ubuntu-branches/ubuntu/vivid/akonadi/vivid

« back to all changes in this revision

Viewing changes to server/src/handler/colcopy.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2013-11-11 17:38:58 UTC
  • mfrom: (1.1.46)
  • Revision ID: package-import@ubuntu.com-20131111173858-kltz6s4ebjishfej
Tags: 1.10.80-0ubuntu1
* New upstream release
 - Update install files
 - Update disable_dbus_requiring_tests.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
using namespace Akonadi;
31
31
 
32
 
bool ColCopy::copyCollection(const Collection & source, const Collection & target)
 
32
bool ColCopy::copyCollection( const Collection &source, const Collection &target )
33
33
{
34
34
  if ( !CollectionQueryHelper::canBeMovedTo( source, target ) ) {
35
35
    // We don't accept source==target, or source being an ancestor of target.
47
47
  }
48
48
 
49
49
  DataStore *db = connection()->storageBackend();
50
 
  if ( !db->appendCollection( col ) )
 
50
  if ( !db->appendCollection( col ) ) {
51
51
    return false;
 
52
  }
52
53
 
53
54
  Q_FOREACH ( const MimeType &mt, source.mimeTypes() ) {
54
 
    if ( !col.addMimeType( mt ) )
 
55
    if ( !col.addMimeType( mt ) ) {
55
56
      return false;
 
57
    }
56
58
  }
57
59
 
58
60
  Q_FOREACH ( const CollectionAttribute &attr, source.attributes() ) {
59
61
    CollectionAttribute newAttr = attr;
60
62
    newAttr.setId( -1 );
61
63
    newAttr.setCollectionId( col.id() );
62
 
    if ( !newAttr.insert() )
 
64
    if ( !newAttr.insert() ) {
63
65
      return false;
 
66
    }
64
67
  }
65
68
 
66
69
  // copy sub-collections
67
70
  Q_FOREACH ( const Collection &child, source.children() ) {
68
 
    if ( !copyCollection( child, col ) )
 
71
    if ( !copyCollection( child, col ) ) {
69
72
      return false;
 
73
    }
70
74
  }
71
75
 
72
76
  // copy items
73
77
  Q_FOREACH ( const PimItem &item, source.items() ) {
74
 
    if ( !copyItem( item, col ) )
 
78
    if ( !copyItem( item, col ) ) {
75
79
      return false;
 
80
    }
76
81
  }
77
82
 
78
83
  return true;
80
85
 
81
86
bool ColCopy::parseStream()
82
87
{
83
 
  QByteArray tmp =  m_streamParser->readString();
 
88
  QByteArray tmp = m_streamParser->readString();
84
89
  const Collection source = HandlerHelper::collectionFromIdOrName( tmp );
85
 
  if ( !source.isValid() )
 
90
  if ( !source.isValid() ) {
86
91
    return failureResponse( "No valid source specified" );
 
92
  }
87
93
 
88
 
  tmp =  m_streamParser->readString();
 
94
  tmp = m_streamParser->readString();
89
95
  const Collection target = HandlerHelper::collectionFromIdOrName( tmp );
90
 
  if ( !target.isValid() )
 
96
  if ( !target.isValid() ) {
91
97
    return failureResponse( "No valid target specified" );
 
98
  }
92
99
 
93
100
  // retrieve all not yet cached items of the source
94
101
  ItemRetriever retriever( connection() );
95
102
  retriever.setCollection( source, true );
96
103
  retriever.setRetrieveFullPayload( true );
97
 
  if (!retriever.exec()) {
 
104
  if ( !retriever.exec() ) {
98
105
    return failureResponse( retriever.lastError() );
99
106
  }
100
107
 
101
108
  DataStore *store = connection()->storageBackend();
102
109
  Transaction transaction( store );
103
110
 
104
 
  if ( !copyCollection( source, target ) )
 
111
  if ( !copyCollection( source, target ) ) {
105
112
    return failureResponse( "Failed to copy collection" );
 
113
  }
106
114
 
107
 
  if ( !transaction.commit() )
 
115
  if ( !transaction.commit() ) {
108
116
    return failureResponse( "Cannot commit transaction." );
 
117
  }
109
118
 
110
119
  return successResponse( "COLCOPY complete" );
111
120
}
112