Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show migration dialogue #2791

Merged
merged 8 commits into from
Nov 10, 2023
5 changes: 5 additions & 0 deletions app/inputhelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ QString InputHelp::whatsNewPostLink() const
return inputWeb + "/blog/introducing-workspaces-simplified-collaboration" + utmTagOther;
}

QString InputHelp::migrationGuides() const
{
return helpRoot + "/dev/ce-migration/" + utmTagHelp;
}

bool InputHelp::submitReportPending() const
{
return mSubmitReportPending;
Expand Down
2 changes: 2 additions & 0 deletions app/inputhelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class InputHelp: public QObject
Q_PROPERTY( QString merginTermsLink READ merginTermsLink NOTIFY linkChanged )
Q_PROPERTY( QString projectLoadingErrorHelpLink READ projectLoadingErrorHelpLink NOTIFY linkChanged )
Q_PROPERTY( QString whatsNewPostLink READ whatsNewPostLink NOTIFY linkChanged )
Q_PROPERTY( QString migrationGuides READ migrationGuides CONSTANT )

//! When adding new link, make sure you also create unit test for it in TestLinks

Expand Down Expand Up @@ -73,6 +74,7 @@ class InputHelp: public QObject
QString merginTermsLink() const;
QString projectLoadingErrorHelpLink() const;
QString whatsNewPostLink() const;
QString migrationGuides() const;

bool submitReportPending() const;
/**
Expand Down
18 changes: 18 additions & 0 deletions app/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,20 @@ ApplicationWindow {
}
}

MessageDialog {
id: migrationDialog

onAccepted: migrationDialog.close()
text: qsTr("Your server will soon be out of date \n\n Please contact your server administrator to upgrade your server to the latest version. Subsequent releases of our mobile app may not be compatible with your current server version.")
iiLubos marked this conversation as resolved.
Show resolved Hide resolved
buttons: MessageDialog.Close | MessageDialog.Help
onButtonClicked: function(clickedButton) {
if (clickedButton === MessageDialog.Help) {
Qt.openUrlExternally(__inputHelp.migrationGuides)
}
close()
}
}

FormsStackManager {
id: formsStackManager

Expand Down Expand Up @@ -773,6 +787,10 @@ ApplicationWindow {
map.mapSettings.extentChanged()
}
}

function onMigrationRequested() {
migrationDialog.open()
}
}

Connections {
Expand Down
56 changes: 50 additions & 6 deletions core/merginapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1347,13 +1347,13 @@ void MerginApi::checkMerginVersion( QString apiVersion, bool serverSupportsSubsc
{
int major = -1;
int minor = -1;
QRegularExpression re;
re.setPattern( QStringLiteral( "(?<major>\\d+)[.](?<minor>\\d+)" ) );
QRegularExpressionMatch match = re.match( apiVersion );
if ( match.hasMatch() )

bool validVersion = parseVersion( apiVersion, major, minor );

if ( !validVersion )
{
major = match.captured( "major" ).toInt();
minor = match.captured( "minor" ).toInt();
setApiVersionStatus( MerginApiStatus::NOT_FOUND );
return;
}

if ( ( MERGIN_API_VERSION_MAJOR == major && MERGIN_API_VERSION_MINOR <= minor ) || ( MERGIN_API_VERSION_MAJOR < major ) )
Expand Down Expand Up @@ -1474,6 +1474,21 @@ ProjectDiff MerginApi::localProjectChanges( const QString &projectDir )
return compareProjectFiles( projectMetadata.files, projectMetadata.files, localFiles, projectDir, config.isValid, config );
}

bool MerginApi::parseVersion( const QString &version, int &major, int &minor )
{
QRegularExpression re;
re.setPattern( QStringLiteral( "(?<major>\\d+)[.](?<minor>\\d+)" ) );
QRegularExpressionMatch match = re.match( version );
if ( match.hasMatch() )
{
major = match.captured( "major" ).toInt();
minor = match.captured( "minor" ).toInt();
return true;
}

return false;
PeterPetrik marked this conversation as resolved.
Show resolved Hide resolved
}

QString MerginApi::getTempProjectDir( const QString &projectFullName )
{
return mDataDir + "/" + TEMP_FOLDER + projectFullName;
Expand Down Expand Up @@ -3343,17 +3358,45 @@ void MerginApi::getServerConfigReplyFinished()
if ( doc.isObject() )
{
QString serverType = doc.object().value( QStringLiteral( "server_type" ) ).toString();
QString apiVersion = doc.object().value( QStringLiteral( "version" ) ).toString();
int major = -1;
int minor = -1;
bool validVersion = parseVersion( apiVersion, major, minor );

if ( !validVersion )
{
CoreUtils::log( QStringLiteral( "Server version" ), QStringLiteral( "Cannot parse server version" ) );
}

if ( serverType == QStringLiteral( "ee" ) )
{
setServerType( MerginServerType::EE );
if ( validVersion )
{
CoreUtils::log( QStringLiteral( "Server version:" ), QStringLiteral( "%1.%2 EE" ).arg( major ).arg( minor ) );
}
}
else if ( serverType == QStringLiteral( "ce" ) )
{
setServerType( MerginServerType::CE );
if ( validVersion )
{
CoreUtils::log( QStringLiteral( "Server version:" ), QStringLiteral( "%1.%2 EE" ).arg( major ).arg( minor ) );
}
}
else if ( serverType == QStringLiteral( "saas" ) )
{
setServerType( MerginServerType::SAAS );
if ( validVersion )
{
CoreUtils::log( QStringLiteral( "Server version:" ), QStringLiteral( "%1.%2 EE" ).arg( major ).arg( minor ) );
}
}

// will be dropped support for old servers (mostly CE servers without workspaces)
if ( ( MINIMUM_SERVER_VERSION_MAJOR == major && MINIMUM_SERVER_VERSION_MINOR > minor ) || ( MINIMUM_SERVER_VERSION_MAJOR > major ) )
{
emit migrationRequested();
}
}
}
Expand All @@ -3363,6 +3406,7 @@ void MerginApi::getServerConfigReplyFinished()
if ( statusCode == 404 ) // legacy (old) server
{
setServerType( MerginServerType::OLD );
emit migrationRequested();
}
else
{
Expand Down
12 changes: 12 additions & 0 deletions core/merginapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ class MerginApi: public QObject

static const int MERGIN_API_VERSION_MAJOR = 2020;
static const int MERGIN_API_VERSION_MINOR = 4;
static const int MINIMUM_SERVER_VERSION_MAJOR = 2023;
static const int MINIMUM_SERVER_VERSION_MINOR = 2;
static const QString sMetadataFile;
static const QString sMetadataFolder;
static const QString sMerginConfigFile;
Expand All @@ -387,6 +389,15 @@ class MerginApi: public QObject

static ProjectDiff localProjectChanges( const QString &projectDir );

/**
* Parse major and minor version number from version string
* \param version full server version string
* \param major parsed major number
* \param minor parsed minor number
* @return true when parsing was successful
*/
static bool parseVersion( const QString &version, int &major, int &minor );

/**
* Finds project in merginProjects list according its full name.
* \param projectPath Full path to project's folder
Expand Down Expand Up @@ -567,6 +578,7 @@ class MerginApi: public QObject

void storageLimitReached( qreal uploadSize );
void projectLimitReached( int maxProjects, const QString &message );
void migrationRequested();
void notify( const QString &message );
void authRequested();
void authChanged();
Expand Down