Skip to content

Commit

Permalink
add option to save qgis project file locally when saving to postgres …
Browse files Browse the repository at this point in the history
…failed
  • Loading branch information
PeterPetrik committed Sep 13, 2018
1 parent d1ae9b0 commit f1358a4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
20 changes: 15 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -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();
}
}
}
} );
Expand Down
14 changes: 9 additions & 5 deletions src/providers/postgres/qgspostgresprojectstorage.cpp
Expand Up @@ -24,7 +24,6 @@
#include <QJsonObject>
#include <QUrl>


static bool _parseMetadataDocument( const QJsonDocument &doc, QgsProjectStorage::Metadata &metadata )
{
if ( !doc.isObject() )
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}


Expand Down

0 comments on commit f1358a4

Please sign in to comment.