Skip to content

Commit

Permalink
Merge pull request #5546 from elpaso/auth_migrate
Browse files Browse the repository at this point in the history
[auth][bugfix] Auth DB migrate
  • Loading branch information
elpaso committed Nov 7, 2017
2 parents c000cb8 + b57ec46 commit 7c9cd49
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
7 changes: 7 additions & 0 deletions python/core/qgserror.sip
Expand Up @@ -123,6 +123,13 @@ class QgsError
Clear error messages
%End

QList<QgsErrorMessage> messageList() const;
%Docstring
messageList return the list of current error messages
:return: current list of error messages
:rtype: list of QgsErrorMessage
%End

};

/************************************************************************
Expand Down
72 changes: 68 additions & 4 deletions src/app/qgsversionmigration.cpp
Expand Up @@ -23,6 +23,7 @@
#include "qgsstyle.h"
#include "qgssymbollayerutils.h"
#include "qgsreadwritecontext.h"
#include "qgsuserprofilemanager.h"

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

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

bool Qgs2To3Migration::requiresMigration()
Expand Down Expand Up @@ -242,6 +264,48 @@ 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 = QStringLiteral( "Could not copy old auth DB to %1: file already exists!" ).arg( newAuthDbFilePath );
QgsDebugMsg( msg );
error.append( msg );
}
else
{
QFile oldDbFile( oldAuthDbFilePath );
if ( oldDbFile.exists( ) )
{
if ( oldDbFile.copy( newAuthDbFilePath ) )
{
QgsDebugMsg( QStringLiteral( "Old auth DB successfully copied to %1" ).arg( newAuthDbFilePath ) );
}
else
{
QString msg = QStringLiteral( "Could not copy auth DB %1 to %2" ).arg( oldAuthDbFilePath, newAuthDbFilePath );
QgsDebugMsg( msg );
error.append( msg );
}
}
else
{
QString msg = QStringLiteral( "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 );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsversionmigration.h
Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgserror.h
Expand Up @@ -128,6 +128,12 @@ class CORE_EXPORT QgsError
//! Clear error messages
void clear() { mMessageList.clear(); }

/**
* \brief messageList return the list of current error messages
* \return current list of error messages
*/
QList<QgsErrorMessage> messageList() const { return mMessageList; }

private:
//! List of messages
QList<QgsErrorMessage> mMessageList;
Expand Down

0 comments on commit 7c9cd49

Please sign in to comment.