Skip to content

Commit 056a6be

Browse files
committedJun 6, 2016
Merge pull request #3127 from sbrunner/add-version-warning
Add a warning on QGIS server when the versions don't corresponds
2 parents f279183 + e5253f8 commit 056a6be

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed
 

‎src/core/qgsproject.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ static void _getTitle( QDomDocument const &doc, QString &title )
591591
592592
@returns the version string or an empty string if none found
593593
*/
594-
static QgsProjectVersion _getVersion( QDomDocument const &doc )
594+
QgsProjectVersion getVersion( QDomDocument const &doc )
595595
{
596596
QDomNodeList nl = doc.elementsByTagName( "qgis" );
597597

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

611611

612612

@@ -861,7 +861,7 @@ bool QgsProject::read()
861861
QgsDebugMsg( "Project title: " + imp_->title );
862862

863863
// get project version string, if any
864-
QgsProjectVersion fileVersion = _getVersion( *doc );
864+
QgsProjectVersion fileVersion = getVersion( *doc );
865865
QgsProjectVersion thisVersion( QGis::QGIS_VERSION );
866866

867867
if ( thisVersion > fileVersion )

‎src/core/qgsproject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,4 +530,6 @@ class CORE_EXPORT QgsProjectBadLayerDefaultHandler : public QgsProjectBadLayerHa
530530

531531
};
532532

533+
CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc );
534+
533535
#endif

‎src/core/qgsprojectversion.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ bool QgsProjectVersion::operator==( const QgsProjectVersion &other ) const
6262
( mSub == other.mSub ) );
6363
}
6464

65+
/** Boolean equal operator
66+
*/
67+
bool QgsProjectVersion::operator!=( const QgsProjectVersion &other ) const
68+
{
69+
return (( mMajor != other.mMajor ) ||
70+
( mMinor != other.mMinor ) ||
71+
( mSub != other.mSub ) );
72+
}
73+
6574
/** Boolean >= operator
6675
*/
6776
bool QgsProjectVersion::operator>=( const QgsProjectVersion &other ) const

‎src/core/qgsprojectversion.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class CORE_EXPORT QgsProjectVersion
4949
*/
5050
bool operator==( const QgsProjectVersion &other ) const;
5151

52+
/** Boolean equal operator
53+
*/
54+
bool operator!=( const QgsProjectVersion &other ) const;
55+
5256
/** Boolean >= operator
5357
*/
5458
bool operator>=( const QgsProjectVersion &other ) const;

‎src/server/qgsconfigcache.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qgswmsprojectparser.h"
2424
#include "qgssldconfigparser.h"
2525
#include "qgsaccesscontrol.h"
26+
#include "qgsproject.h"
2627

2728
#include <QFile>
2829

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

4849
QgsServerProjectParser* QgsConfigCache::serverConfiguration( const QString& filePath )
4950
{
51+
QgsMessageLog::logMessage(
52+
QString( "Open the project file '%1'." )
53+
.arg( filePath ),
54+
"Server", QgsMessageLog::INFO
55+
);
56+
5057
QDomDocument* doc = xmlDocument( filePath );
5158
if ( !doc )
5259
{
5360
return nullptr;
5461
}
62+
63+
QgsProjectVersion fileVersion = getVersion( *doc );
64+
QgsProjectVersion thisVersion( QGis::QGIS_VERSION );
65+
66+
if ( thisVersion != fileVersion )
67+
{
68+
QgsMessageLog::logMessage(
69+
QString(
70+
"\n========================================================================="
71+
"\n= WARNING: This project file was saved by an defferent version of QGIS. ="
72+
"\n========================================================================="
73+
), "Server", QgsMessageLog::WARNING
74+
);
75+
}
76+
QgsMessageLog::logMessage(
77+
QString( "QGIS server version %1, project version %2" )
78+
.arg( thisVersion.text() )
79+
.arg( fileVersion.text() ),
80+
"Server", QgsMessageLog::INFO
81+
);
5582
return new QgsServerProjectParser( doc, filePath );
5683
}
5784

0 commit comments

Comments
 (0)
Please sign in to comment.