Skip to content

Commit

Permalink
Do not remove broken WMS layers if during packaging
Browse files Browse the repository at this point in the history
Sometimes online WMS layers are not accessible because of multiple reasons:
- temporary network/server error
- firewall
- network access
- etc

Just ignore these layers on the server side and don't remove them.
  • Loading branch information
suricactus committed Mar 28, 2024
1 parent 5ed1f87 commit 4de12a1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 14 additions & 1 deletion libqfieldsync/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class PackagePreventionReason(Enum):
INVALID = 1
UNSUPPORTED_DATASOURCE = 2
LOCALIZED_PATH = 3
INVALID_REMOTE_RASTER_LAYER = 4

REASONS_TO_REMOVE_LAYER = (
PackagePreventionReason.INVALID,
Expand Down Expand Up @@ -882,6 +883,13 @@ def is_localized_path(self) -> bool:

return path.startswith("localized:")

@property
def is_remote_raster_layer(self) -> bool:
if self.layer.dataProvider() and self.layer.dataProvider().name() == "wms":
return True

return False

@property
def package_prevention_reasons(
self,
Expand All @@ -895,6 +903,11 @@ def package_prevention_reasons(
# do not package the layers within localized paths (stored outside project dir and shared among multiple projects)
if self.is_localized_path:
reasons.append(LayerSource.PackagePreventionReason.LOCALIZED_PATH)
# sometimes the remote layers are inaccessible from the current network, but we should spare them from removal
elif not self.layer.isValid() and self.is_remote_raster_layer:
reasons.append(
LayerSource.PackagePreventionReason.INVALID_REMOTE_RASTER_LAYER
)
# remove invalid layers from the packaged project
# NOTE localized layers will be always invalid on QFieldCloud
elif not self.layer.isValid():
Expand Down Expand Up @@ -1082,7 +1095,7 @@ def convert_to_gpkg(self, target_path):
options = QgsVectorFileWriter.SaveVectorOptions()
options.fileEncoding = "UTF-8"
options.driverName = "GPKG"
(error, returned_dest_file) = QgsVectorFileWriter.writeAsVectorFormatV2(
(error, returned_dest_file) = QgsVectorFileWriter.writeAsVectorFormatV3(
source_layer, dest_file, QgsCoordinateTransformContext(), options
)
if error != QgsVectorFileWriter.NoError:
Expand Down
9 changes: 9 additions & 0 deletions libqfieldsync/project_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,15 @@ def check_layer_package_prevention(

if reason == LayerSource.PackagePreventionReason.INVALID:
reason_msgs.append(self.tr("The layer is invalid!"))
elif (
reason
== LayerSource.PackagePreventionReason.INVALID_REMOTE_RASTER_LAYER
):
reason_msgs.append(
self.tr(
"The raster layer data source is not accessible from the current network!"
)
)
elif (
reason == LayerSource.PackagePreventionReason.UNSUPPORTED_DATASOURCE
):
Expand Down

0 comments on commit 4de12a1

Please sign in to comment.