Skip to content
Permalink
Browse files

Merge pull request #5546 from elpaso/auth_migrate

[auth][bugfix] Auth DB migrate
  • Loading branch information
elpaso committed Nov 7, 2017
2 parents c000cb8 + b57ec46 commit 7c9cd491bdf624316a411f81b502949b044acf1e
Showing with 82 additions and 4 deletions.
  1. +7 −0 python/core/qgserror.sip
  2. +68 −4 src/app/qgsversionmigration.cpp
  3. +1 −0 src/app/qgsversionmigration.h
  4. +6 −0 src/core/qgserror.h
@@ -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

};

/************************************************************************
@@ -23,6 +23,7 @@
#include "qgsstyle.h"
#include "qgssymbollayerutils.h"
#include "qgsreadwritecontext.h"
#include "qgsuserprofilemanager.h"

#include <QFile>
#include <QTextStream>
@@ -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()
@@ -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 );
@@ -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 );
@@ -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;

0 comments on commit 7c9cd49

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