Skip to content

Commit

Permalink
Build mobile project - Fix the datasource checking between the projec…
Browse files Browse the repository at this point in the history
…t layers & the central connection config
  • Loading branch information
mdouchin committed May 17, 2021
1 parent a518934 commit 06cbdd3
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lizsync/processing/algorithms/build_mobile_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from qgis.core import (
Qgis,
QgsDataSourceUri,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterString,
Expand Down Expand Up @@ -191,7 +192,7 @@ def checkParameterValues(self, parameters, context):

return super(BuildMobileProject, self).checkParameterValues(parameters, context)

def replacePostgresqlDatasource(self, connection_name_central, datasource):
def replacePostgresqlDatasource(self, connection_name_central, datasource, layername):
# Get uri from connection names
status_central, uri_central, error_message_central = getUriFromConnectionName(
connection_name_central,
Expand All @@ -202,8 +203,22 @@ def replacePostgresqlDatasource(self, connection_name_central, datasource):
return False, m

# Check if layer datasource and connection datasource have common data
if not uri_central.connectionInfo() in datasource:
uri_datasource = QgsDataSourceUri(datasource)
match_error = []
if uri_datasource.service() != uri_central.service():
match_error.append('\n service ({} != {})'.format(uri_datasource.service(), uri_central.service()))
if uri_datasource.host() != uri_central.host():
match_error.append('\n host ({} != {})'.format(uri_datasource.host(), uri_central.host()))
if uri_datasource.port() != uri_central.port():
match_error.append('\n port ({} != {})'.format(uri_datasource.port(), uri_central.port()))
if uri_datasource.database() != uri_central.database():
match_error.append('\n database ({} != {})'.format(uri_datasource.database(), uri_central.database()))
if uri_datasource.username() != uri_central.username():
match_error.append('\n username ({} != {})'.format(uri_datasource.username(), uri_central.username()))
if match_error:
m = tr('Central database and layer connection parameters do not match')
m += '.\n' + tr('Layer') + ' "{}":'.format(layername)
m += ', '.join(match_error)
return False, m

# Build central and clone datasource components to search & replace
Expand Down Expand Up @@ -311,7 +326,8 @@ def processAlgorithm(self, parameters, context, feedback):
# Replace datasource by field localhost datasource
new_source, msg = self.replacePostgresqlDatasource(
connection_name_central,
datasource
datasource,
layername
)
if not new_source:
raise QgsProcessingException(msg)
Expand Down

0 comments on commit 06cbdd3

Please sign in to comment.