Skip to content
Permalink
Browse files

Misc project storage fixes from Nyall's testing

- fix a crash when opening a project from unavailable connection
- make some messages in postgresql project storage translatable
- show the reason why a project was not read/written in storage if there is a message available
- push a message when reading a project that does not exist in postgresql storage
  • Loading branch information
wonder-sk committed Apr 10, 2018
1 parent 37295ec commit 4a885e6e9cc1e3767bac5ea73cb7c59496c34b34
Showing with 33 additions and 5 deletions.
  1. +10 −2 src/core/qgsproject.cpp
  2. +23 −3 src/providers/postgres/qgspostgresprojectstorage.cpp
@@ -880,7 +880,11 @@ bool QgsProject::read()
QgsReadWriteContext context;
if ( !storage->readProject( filename, &inDevice, context ) )
{
setError( tr( "Unable to open %1" ).arg( filename ) );
QString err = tr( "Unable to open %1" ).arg( filename );
QList<QgsReadWriteContext::ReadWriteMessage> messages = context.takeMessages();
if ( !messages.isEmpty() )
err += QStringLiteral( "\n\n" ) + messages.last().message();
setError( err );
return false;
}

@@ -1461,7 +1465,11 @@ bool QgsProject::write()
QgsReadWriteContext context;
if ( !storage->writeProject( mFile.fileName(), &tmpZipFile, context ) )
{
setError( tr( "Unable to save project to storage %1" ).arg( mFile.fileName() ) );
QString err = tr( "Unable to save project to storage %1" ).arg( mFile.fileName() );
QList<QgsReadWriteContext::ReadWriteMessage> messages = context.takeMessages();
if ( !messages.isEmpty() )
err += QStringLiteral( "\n\n" ) + messages.last().message();
setError( err );
return false;
}

@@ -52,6 +52,8 @@ QStringList QgsPostgresProjectStorage::listProjects( const QString &uri )
return lst;

QgsPostgresConn *conn = QgsPostgresConnPool::instance()->acquireConnection( projectUri.connInfo.connectionInfo( false ) );
if ( !conn )
return lst;

if ( _projectsTableExists( *conn, projectUri.schemaName ) )
{
@@ -79,15 +81,20 @@ bool QgsPostgresProjectStorage::readProject( const QString &uri, QIODevice *devi
QgsPostgresProjectUri projectUri = decodeUri( uri );
if ( !projectUri.valid )
{
context.pushMessage( "Invalid URI for PostgreSQL provider: " + uri, Qgis::Critical );
context.pushMessage( QObject::tr( "Invalid URI for PostgreSQL provider: " ) + uri, Qgis::Critical );
return false;
}

QgsPostgresConn *conn = QgsPostgresConnPool::instance()->acquireConnection( projectUri.connInfo.connectionInfo( false ) );
if ( !conn )
{
context.pushMessage( QObject::tr( "Could not connect to the database: " ) + projectUri.connInfo.connectionInfo( false ), Qgis::Critical );
return false;
}

if ( !_projectsTableExists( *conn, projectUri.schemaName ) )
{
context.pushMessage( "Table qgis_projects does not exist or it is not accessible.", Qgis::Critical );
context.pushMessage( QObject::tr( "Table qgis_projects does not exist or it is not accessible." ), Qgis::Critical );
QgsPostgresConnPool::instance()->releaseConnection( conn );
return false;
}
@@ -106,6 +113,10 @@ bool QgsPostgresProjectStorage::readProject( const QString &uri, QIODevice *devi
device->seek( 0 );
ok = true;
}
else
{
context.pushMessage( QObject::tr( "The project '%1' does not exist in schema '%2'." ).arg( projectUri.projectName, projectUri.schemaName ), Qgis::Critical );
}
}

QgsPostgresConnPool::instance()->releaseConnection( conn );
@@ -119,11 +130,16 @@ bool QgsPostgresProjectStorage::writeProject( const QString &uri, QIODevice *dev
QgsPostgresProjectUri projectUri = decodeUri( uri );
if ( !projectUri.valid )
{
context.pushMessage( "Invalid URI for PostgreSQL provider: " + uri, Qgis::Critical );
context.pushMessage( QObject::tr( "Invalid URI for PostgreSQL provider: " ) + uri, Qgis::Critical );
return false;
}

QgsPostgresConn *conn = QgsPostgresConnPool::instance()->acquireConnection( projectUri.connInfo.connectionInfo( false ) );
if ( !conn )
{
context.pushMessage( QObject::tr( "Could not connect to the database: " ) + projectUri.connInfo.connectionInfo( false ), Qgis::Critical );
return false;
}

if ( !_projectsTableExists( *conn, projectUri.schemaName ) )
{
@@ -173,6 +189,8 @@ bool QgsPostgresProjectStorage::removeProject( const QString &uri )
return false;

QgsPostgresConn *conn = QgsPostgresConnPool::instance()->acquireConnection( projectUri.connInfo.connectionInfo( false ) );
if ( !conn )
return false;

bool removed = false;
if ( _projectsTableExists( *conn, projectUri.schemaName ) )
@@ -195,6 +213,8 @@ bool QgsPostgresProjectStorage::readProjectStorageMetadata( const QString &uri,
return false;

QgsPostgresConn *conn = QgsPostgresConnPool::instance()->acquireConnection( projectUri.connInfo.connectionInfo( false ) );
if ( !conn )
return false;

bool ok = false;
QString sql( QStringLiteral( "SELECT metadata FROM %1.qgis_projects WHERE name = %2" ).arg( QgsPostgresConn::quotedIdentifier( projectUri.schemaName ), QgsPostgresConn::quotedValue( projectUri.projectName ) ) );

0 comments on commit 4a885e6

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