mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Merge pull request #5546 from elpaso/auth_migrate
[auth][bugfix] Auth DB migrate
This commit is contained in:
commit
7c9cd491bd
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user