Skip to content
Permalink
Browse files

add option to save qgis project file locally when saving to postgres …

…failed
  • Loading branch information
PeterPetrik committed Sep 13, 2018
1 parent d1ae9b0 commit f1358a4b1a07f7dcc4db3944991c5b61ad11c6da
Showing with 24 additions and 10 deletions.
  1. +15 −5 src/app/qgisapp.cpp
  2. +9 −5 src/providers/postgres/qgspostgresprojectstorage.cpp
@@ -14096,11 +14096,21 @@ void QgisApp::populateProjectStorageMenu( QMenu *menu, bool saving )
}
else
{
QMessageBox::critical( this,
tr( "Unable to save project %1" ).arg( uri ),
QgsProject::instance()->error(),
QMessageBox::Ok,
Qt::NoButton );
QMessageBox msgbox;

msgbox.setWindowTitle( tr( "Unable to save project %1" ).arg( uri ) );
msgbox.setText( QgsProject::instance()->error() );
msgbox.setIcon( QMessageBox::Icon::Critical );
msgbox.addButton( QMessageBox::Cancel );
msgbox.addButton( QMessageBox::Save );
msgbox.setButtonText( QMessageBox::Save, tr( "Save as local file" ) );
msgbox.setDefaultButton( QMessageBox::Cancel );
msgbox.exec();

if ( msgbox.result() == QMessageBox::Save )
{
fileSaveAs();
}
}
}
} );
@@ -24,7 +24,6 @@
#include <QJsonObject>
#include <QUrl>


static bool _parseMetadataDocument( const QJsonDocument &doc, QgsProjectStorage::Metadata &metadata )
{
if ( !doc.isObject() )
@@ -162,7 +161,7 @@ bool QgsPostgresProjectStorage::writeProject( const QString &uri, QIODevice *dev
QgsPostgresResult res( conn->PQexec( sql ) );
if ( res.PQresultStatus() != PGRES_COMMAND_OK )
{
QString errCause = QObject::tr( "Unable to save project. It's not possible to create the destination table on the database. Maybe this is due to table permissions (user=%1). Please contact your database admin" ).arg( projectUri.connInfo.username() );
QString errCause = QObject::tr( "Unable to save project. It's not possible to create the destination table on the database. Maybe this is due to database permissions (user=%1). Please contact your database admin" ).arg( projectUri.connInfo.username() );
context.pushMessage( errCause, Qgis::Critical );
QgsPostgresConnPool::instance()->releaseConnection( conn );
return false;
@@ -188,11 +187,16 @@ bool QgsPostgresProjectStorage::writeProject( const QString &uri, QIODevice *dev
sql += "') ON CONFLICT (name) DO UPDATE SET content = EXCLUDED.content, metadata = EXCLUDED.metadata;";

QgsPostgresResult res( conn->PQexec( sql ) );
bool ok = res.PQresultStatus() == PGRES_COMMAND_OK;
if ( res.PQresultStatus() != PGRES_COMMAND_OK )
{
QString errCause = QObject::tr( "Unable to insert or update project (project=%1) in the destination table on the database. Maybe this is due to table permissions (user=%2). Please contact your database admin" ).arg( projectUri.projectName, projectUri.connInfo.username() );
context.pushMessage( errCause, Qgis::Critical );
QgsPostgresConnPool::instance()->releaseConnection( conn );
return false;
}

QgsPostgresConnPool::instance()->releaseConnection( conn );

return ok;
return true;
}


0 comments on commit f1358a4

Please sign in to comment.
You can’t perform that action at this time.