Skip to content

Commit e5253f8

Browse files
committedMay 29, 2016
Add a warning on QGIS server when the versions don't corresponds
QGIS server and project file.
1 parent 1b06324 commit e5253f8

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
@@ -587,7 +587,7 @@ static void _getTitle( QDomDocument const &doc, QString &title )
587587
588588
@returns the version string or an empty string if none found
589589
*/
590-
static QgsProjectVersion _getVersion( QDomDocument const &doc )
590+
QgsProjectVersion getVersion( QDomDocument const &doc )
591591
{
592592
QDomNodeList nl = doc.elementsByTagName( "qgis" );
593593

@@ -602,7 +602,7 @@ static QgsProjectVersion _getVersion( QDomDocument const &doc )
602602
QDomElement qgisElement = qgisNode.toElement(); // qgis node should be element
603603
QgsProjectVersion projectVersion( qgisElement.attribute( "version" ) );
604604
return projectVersion;
605-
} // _getVersion
605+
} // getVersion
606606

607607

608608

@@ -857,7 +857,7 @@ bool QgsProject::read()
857857
QgsDebugMsg( "Project title: " + imp_->title );
858858

859859
// get project version string, if any
860-
QgsProjectVersion fileVersion = _getVersion( *doc );
860+
QgsProjectVersion fileVersion = getVersion( *doc );
861861
QgsProjectVersion thisVersion( QGis::QGIS_VERSION );
862862

863863
if ( thisVersion > fileVersion )

‎src/core/qgsproject.h

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

512512
};
513513

514+
CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc );
515+
514516
#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.