|
23 | 23 | #include "qgsstyle.h"
|
24 | 24 | #include "qgssymbollayerutils.h"
|
25 | 25 | #include "qgsreadwritecontext.h"
|
| 26 | +#include "qgsuserprofilemanager.h" |
26 | 27 |
|
27 | 28 | #include <QFile>
|
28 | 29 | #include <QTextStream>
|
@@ -53,14 +54,32 @@ QgsVersionMigration *QgsVersionMigration::canMigrate( int fromVersion, int toVer
|
53 | 54 |
|
54 | 55 | QgsError Qgs2To3Migration::runMigration()
|
55 | 56 | {
|
56 |
| - QgsError error; |
| 57 | + QgsError errors; |
57 | 58 | QgsError settingsErrors = migrateSettings();
|
58 | 59 | if ( !settingsErrors.isEmpty() )
|
59 | 60 | {
|
60 |
| - // TODO Merge error messages |
| 61 | + for ( const auto &err : settingsErrors.messageList( ) ) |
| 62 | + { |
| 63 | + errors.append( err ); |
| 64 | + } |
61 | 65 | }
|
62 |
| - QgsError stylesError = migrateStyles(); |
63 |
| - return error; |
| 66 | + QgsError stylesErrors = migrateStyles(); |
| 67 | + if ( !stylesErrors.isEmpty() ) |
| 68 | + { |
| 69 | + for ( const auto &err : stylesErrors.messageList( ) ) |
| 70 | + { |
| 71 | + errors.append( err ); |
| 72 | + } |
| 73 | + } |
| 74 | + QgsError authDbErrors = migrateAuthDb(); |
| 75 | + if ( !authDbErrors.isEmpty() ) |
| 76 | + { |
| 77 | + for ( const auto &err : authDbErrors.messageList( ) ) |
| 78 | + { |
| 79 | + errors.append( err ); |
| 80 | + } |
| 81 | + } |
| 82 | + return errors; |
64 | 83 | }
|
65 | 84 |
|
66 | 85 | bool Qgs2To3Migration::requiresMigration()
|
@@ -242,6 +261,50 @@ QgsError Qgs2To3Migration::migrateSettings()
|
242 | 261 | return error;
|
243 | 262 | }
|
244 | 263 |
|
| 264 | +QgsError Qgs2To3Migration::migrateAuthDb() |
| 265 | +{ |
| 266 | + QgsError error; |
| 267 | + QString oldHome = QStringLiteral( "%1/.qgis2" ).arg( QDir::homePath() ); |
| 268 | + QString oldAuthDbFilePath = QStringLiteral( "%1/qgis-auth.db" ).arg( oldHome ); |
| 269 | + // Try to retrieve the current profile folder (I didn't find an QgsApplication API for it) |
| 270 | + QDir settingsDir = QFileInfo( QgsSettings().fileName() ).absoluteDir(); |
| 271 | + settingsDir.cdUp(); |
| 272 | + QString newAuthDbFilePath = QStringLiteral( "%1/qgis-auth.db" ).arg( settingsDir.absolutePath() ); |
| 273 | + // Do not overwrite! |
| 274 | + if ( QFile( newAuthDbFilePath ).exists( ) ) |
| 275 | + { |
| 276 | + QString msg = QString( "Could not copy old auth DB to %1: file already exists!" ).arg( newAuthDbFilePath ); |
| 277 | + QgsDebugMsg( msg ); |
| 278 | + error.append( msg ); |
| 279 | + |
| 280 | + } |
| 281 | + else |
| 282 | + { |
| 283 | + QgsDebugMsg( QString( "OLD AUTH DB FILE %1" ).arg( oldAuthDbFilePath ) ); |
| 284 | + QFile oldDbFile( oldAuthDbFilePath ); |
| 285 | + if ( oldDbFile.exists( ) ) |
| 286 | + { |
| 287 | + if ( oldDbFile.copy( newAuthDbFilePath ) ) |
| 288 | + { |
| 289 | + QgsDebugMsg( QStringLiteral( "Old auth DB successfully copied to %1" ).arg( newAuthDbFilePath ) ); |
| 290 | + } |
| 291 | + else |
| 292 | + { |
| 293 | + QString msg = QString( "Could not copy auth DB %1 to %2" ).arg( oldAuthDbFilePath, newAuthDbFilePath ); |
| 294 | + QgsDebugMsg( msg ); |
| 295 | + error.append( msg ); |
| 296 | + } |
| 297 | + } |
| 298 | + else |
| 299 | + { |
| 300 | + QString msg = QString( "Could not copy auth DB %1 to %2: old DB does not exists!" ).arg( oldAuthDbFilePath, newAuthDbFilePath ); |
| 301 | + QgsDebugMsg( msg ); |
| 302 | + error.append( msg ); |
| 303 | + } |
| 304 | + } |
| 305 | + return error; |
| 306 | +} |
| 307 | + |
245 | 308 | QList<QPair<QString, QString> > Qgs2To3Migration::walk( QString group, QString newkey )
|
246 | 309 | {
|
247 | 310 | mOldSettings->beginGroup( group );
|
|
0 commit comments