Skip to content

Commit

Permalink
Merge pull request #3127 from sbrunner/add-version-warning
Browse files Browse the repository at this point in the history
Add a warning on QGIS server when the versions don't corresponds
  • Loading branch information
mhugent committed Jun 6, 2016
2 parents f279183 + e5253f8 commit 056a6be
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ static void _getTitle( QDomDocument const &doc, QString &title )
@returns the version string or an empty string if none found
*/
static QgsProjectVersion _getVersion( QDomDocument const &doc )
QgsProjectVersion getVersion( QDomDocument const &doc )
{
QDomNodeList nl = doc.elementsByTagName( "qgis" );

Expand All @@ -606,7 +606,7 @@ static QgsProjectVersion _getVersion( QDomDocument const &doc )
QDomElement qgisElement = qgisNode.toElement(); // qgis node should be element
QgsProjectVersion projectVersion( qgisElement.attribute( "version" ) );
return projectVersion;
} // _getVersion
} // getVersion



Expand Down Expand Up @@ -861,7 +861,7 @@ bool QgsProject::read()
QgsDebugMsg( "Project title: " + imp_->title );

// get project version string, if any
QgsProjectVersion fileVersion = _getVersion( *doc );
QgsProjectVersion fileVersion = getVersion( *doc );
QgsProjectVersion thisVersion( QGis::QGIS_VERSION );

if ( thisVersion > fileVersion )
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,6 @@ class CORE_EXPORT QgsProjectBadLayerDefaultHandler : public QgsProjectBadLayerHa

};

CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc );

#endif
9 changes: 9 additions & 0 deletions src/core/qgsprojectversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ bool QgsProjectVersion::operator==( const QgsProjectVersion &other ) const
( mSub == other.mSub ) );
}

/** Boolean equal operator
*/
bool QgsProjectVersion::operator!=( const QgsProjectVersion &other ) const
{
return (( mMajor != other.mMajor ) ||
( mMinor != other.mMinor ) ||
( mSub != other.mSub ) );
}

/** Boolean >= operator
*/
bool QgsProjectVersion::operator>=( const QgsProjectVersion &other ) const
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsprojectversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class CORE_EXPORT QgsProjectVersion
*/
bool operator==( const QgsProjectVersion &other ) const;

/** Boolean equal operator
*/
bool operator!=( const QgsProjectVersion &other ) const;

/** Boolean >= operator
*/
bool operator>=( const QgsProjectVersion &other ) const;
Expand Down
27 changes: 27 additions & 0 deletions src/server/qgsconfigcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgswmsprojectparser.h"
#include "qgssldconfigparser.h"
#include "qgsaccesscontrol.h"
#include "qgsproject.h"

#include <QFile>

Expand All @@ -47,11 +48,37 @@ QgsConfigCache::~QgsConfigCache()

QgsServerProjectParser* QgsConfigCache::serverConfiguration( const QString& filePath )
{
QgsMessageLog::logMessage(
QString( "Open the project file '%1'." )
.arg( filePath ),
"Server", QgsMessageLog::INFO
);

QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return nullptr;
}

QgsProjectVersion fileVersion = getVersion( *doc );
QgsProjectVersion thisVersion( QGis::QGIS_VERSION );

if ( thisVersion != fileVersion )
{
QgsMessageLog::logMessage(
QString(
"\n========================================================================="
"\n= WARNING: This project file was saved by an defferent version of QGIS. ="
"\n========================================================================="
), "Server", QgsMessageLog::WARNING
);
}
QgsMessageLog::logMessage(
QString( "QGIS server version %1, project version %2" )
.arg( thisVersion.text() )
.arg( fileVersion.text() ),
"Server", QgsMessageLog::INFO
);
return new QgsServerProjectParser( doc, filePath );
}

Expand Down

0 comments on commit 056a6be

Please sign in to comment.