Skip to content
Permalink
Browse files

[auth][bugfix] Migrate qgis-auth.db from QGIS 2 to 3

Fixes #17403
  • Loading branch information
elpaso committed Nov 6, 2017
1 parent cd23779 commit 7e699361615a618d628ce55b91f2e468142b52c9
Showing with 68 additions and 4 deletions.
  1. +67 −4 src/app/qgsversionmigration.cpp
  2. +1 −0 src/app/qgsversionmigration.h
@@ -23,6 +23,7 @@
#include "qgsstyle.h"
#include "qgssymbollayerutils.h"
#include "qgsreadwritecontext.h"
#include "qgsuserprofilemanager.h"

#include <QFile>
#include <QTextStream>
@@ -53,14 +54,32 @@ QgsVersionMigration *QgsVersionMigration::canMigrate( int fromVersion, int toVer

QgsError Qgs2To3Migration::runMigration()
{
QgsError error;
QgsError errors;
QgsError settingsErrors = migrateSettings();
if ( !settingsErrors.isEmpty() )
{
// TODO Merge error messages
for ( const auto &err : settingsErrors.messageList( ) )
{
errors.append( err );
}
}
QgsError stylesError = migrateStyles();
return error;
QgsError stylesErrors = migrateStyles();
if ( !stylesErrors.isEmpty() )
{
for ( const auto &err : stylesErrors.messageList( ) )
{
errors.append( err );
}
}
QgsError authDbErrors = migrateAuthDb();
if ( !authDbErrors.isEmpty() )
{
for ( const auto &err : authDbErrors.messageList( ) )
{
errors.append( err );
}
}
return errors;
}

bool Qgs2To3Migration::requiresMigration()
@@ -242,6 +261,50 @@ QgsError Qgs2To3Migration::migrateSettings()
return error;
}

QgsError Qgs2To3Migration::migrateAuthDb()
{
QgsError error;
QString oldHome = QStringLiteral( "%1/.qgis2" ).arg( QDir::homePath() );
QString oldAuthDbFilePath = QStringLiteral( "%1/qgis-auth.db" ).arg( oldHome );
// Try to retrieve the current profile folder (I didn't find an QgsApplication API for it)
QDir settingsDir = QFileInfo( QgsSettings().fileName() ).absoluteDir();
settingsDir.cdUp();
QString newAuthDbFilePath = QStringLiteral( "%1/qgis-auth.db" ).arg( settingsDir.absolutePath() );
// Do not overwrite!
if ( QFile( newAuthDbFilePath ).exists( ) )
{
QString msg = QString( "Could not copy old auth DB to %1: file already exists!" ).arg( newAuthDbFilePath );
QgsDebugMsg( msg );
error.append( msg );

}
else
{
QgsDebugMsg( QString( "OLD AUTH DB FILE %1" ).arg( oldAuthDbFilePath ) );
QFile oldDbFile( oldAuthDbFilePath );
if ( oldDbFile.exists( ) )
{
if ( oldDbFile.copy( newAuthDbFilePath ) )
{
QgsDebugMsg( QStringLiteral( "Old auth DB successfully copied to %1" ).arg( newAuthDbFilePath ) );
}
else
{
QString msg = QString( "Could not copy auth DB %1 to %2" ).arg( oldAuthDbFilePath, newAuthDbFilePath );
QgsDebugMsg( msg );
error.append( msg );
}
}
else
{
QString msg = QString( "Could not copy auth DB %1 to %2: old DB does not exists!" ).arg( oldAuthDbFilePath, newAuthDbFilePath );
QgsDebugMsg( msg );
error.append( msg );
}
}
return error;
}

QList<QPair<QString, QString> > Qgs2To3Migration::walk( QString group, QString newkey )
{
mOldSettings->beginGroup( group );
@@ -58,6 +58,7 @@ class Qgs2To3Migration : public QgsVersionMigration
private:
QgsError migrateStyles();
QgsError migrateSettings();
QgsError migrateAuthDb();

QList<QPair<QString, QString>> walk( QString group, QString newkey );
QPair<QString, QString> transformKey( QString fullOldKey, QString newKeyPart );

0 comments on commit 7e69936

Please sign in to comment.
You can’t perform that action at this time.