Skip to content

Commit

Permalink
Merged master into release
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Mar 25, 2024
2 parents b57015d + 2a88347 commit f4c3c57
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 7 deletions.
18 changes: 18 additions & 0 deletions docker-app/qfieldcloud/core/migrations/0075_auto_20240323_1419.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.25 on 2024-03-23 13:19

import migrate_sql.operations
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("core", "0074_auto_20240314_1805"),
]

operations = [
migrate_sql.operations.AlterSQL(
name="core_delta_geom_trigger_func",
sql="\n CREATE OR REPLACE FUNCTION core_delta_geom_trigger_func()\n RETURNS trigger\n AS\n $$\n DECLARE\n delta_srid int;\n old_geom_wkt text;\n new_geom_wkt text;\n BEGIN\n SELECT CASE\n WHEN jsonb_extract_path_text(NEW.content, 'localLayerCrs') ~ '^EPSG:\\d{1,10}$'\n THEN\n REGEXP_REPLACE(jsonb_extract_path_text(NEW.content, 'localLayerCrs'), '\\D*', '', 'g')::int\n ELSE\n NULL\n END INTO delta_srid;\n\n old_geom_wkt := NULLIF( TRIM( jsonb_extract_path_text(NEW.content, 'old', 'geometry') ), '');\n new_geom_wkt := NULLIF( TRIM( jsonb_extract_path_text(NEW.content, 'new', 'geometry') ), '');\n\n IF delta_srid IS NOT NULL\n AND EXISTS(\n SELECT *\n FROM spatial_ref_sys\n WHERE auth_name = 'EPSG'\n AND auth_srid = delta_srid\n )\n THEN\n NEW.old_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( old_geom_wkt, 'nan', '0' ) ) ), delta_srid ), 4326 );\n NEW.new_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( new_geom_wkt, 'nan', '0' ) ) ), delta_srid ), 4326 );\n ELSE\n NEW.old_geom := NULL;\n NEW.new_geom := NULL;\n END IF;\n\n IF ST_GeometryType(NEW.old_geom) IN ('ST_CircularString', 'ST_CompoundCurve', 'ST_CurvePolygon', 'ST_MultiCurve', 'ST_MultiSurface')\n THEN\n NEW.old_geom := ST_CurveToLine(NEW.old_geom);\n END IF;\n\n IF ST_GeometryType(NEW.new_geom) IN ('ST_CircularString', 'ST_CompoundCurve', 'ST_CurvePolygon', 'ST_MultiCurve', 'ST_MultiSurface')\n THEN\n NEW.new_geom := ST_CurveToLine(NEW.new_geom);\n END IF;\n\n RETURN NEW;\n END;\n $$\n LANGUAGE PLPGSQL\n ",
reverse_sql="\n CREATE OR REPLACE FUNCTION core_delta_geom_trigger_func()\n RETURNS trigger\n AS\n $$\n DECLARE\n srid int;\n BEGIN\n SELECT CASE\n WHEN jsonb_extract_path_text(NEW.content, 'localLayerCrs') ~ '^EPSG:\\d{1,10}$'\n THEN\n REGEXP_REPLACE(jsonb_extract_path_text(NEW.content, 'localLayerCrs'), '\\D*', '', 'g')::int\n ELSE\n NULL\n END INTO srid;\n NEW.old_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( jsonb_extract_path_text(NEW.content, 'old', 'geometry'), 'nan', '0' ) ) ), srid ), 4326 );\n NEW.new_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( jsonb_extract_path_text(NEW.content, 'new', 'geometry'), 'nan', '0' ) ) ), srid ), 4326 );\n\n IF ST_GeometryType(NEW.old_geom) IN ('ST_CircularString', 'ST_CompoundCurve', 'ST_CurvePolygon', 'ST_MultiCurve', 'ST_MultiSurface')\n THEN\n NEW.old_geom := ST_CurveToLine(NEW.old_geom);\n END IF;\n\n IF ST_GeometryType(NEW.new_geom) IN ('ST_CircularString', 'ST_CompoundCurve', 'ST_CurvePolygon', 'ST_MultiCurve', 'ST_MultiSurface')\n THEN\n NEW.new_geom := ST_CurveToLine(NEW.new_geom);\n END IF;\n\n RETURN NEW;\n END;\n $$\n LANGUAGE PLPGSQL\n ",
),
]
9 changes: 7 additions & 2 deletions docker-app/qfieldcloud/core/sql_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@
$$
DECLARE
delta_srid int;
old_geom_wkt text;
new_geom_wkt text;
BEGIN
SELECT CASE
WHEN jsonb_extract_path_text(NEW.content, 'localLayerCrs') ~ '^EPSG:\d{1,10}$'
Expand All @@ -188,6 +190,9 @@
NULL
END INTO delta_srid;
old_geom_wkt := NULLIF( TRIM( jsonb_extract_path_text(NEW.content, 'old', 'geometry') ), '');
new_geom_wkt := NULLIF( TRIM( jsonb_extract_path_text(NEW.content, 'new', 'geometry') ), '');
IF delta_srid IS NOT NULL
AND EXISTS(
SELECT *
Expand All @@ -196,8 +201,8 @@
AND auth_srid = delta_srid
)
THEN
NEW.old_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( jsonb_extract_path_text(NEW.content, 'old', 'geometry'), 'nan', '0' ) ) ), delta_srid ), 4326 );
NEW.new_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( jsonb_extract_path_text(NEW.content, 'new', 'geometry'), 'nan', '0' ) ) ), delta_srid ), 4326 );
NEW.old_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( old_geom_wkt, 'nan', '0' ) ) ), delta_srid ), 4326 );
NEW.new_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( new_geom_wkt, 'nan', '0' ) ) ), delta_srid ), 4326 );
ELSE
NEW.old_geom := NULL;
NEW.new_geom := NULL;
Expand Down
23 changes: 23 additions & 0 deletions docker-app/qfieldcloud/core/tests/test_delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,29 @@ def test_non_spatial_delta(self):
b'fid,col1\n"1",qux\n"2",newfeature\n',
)

def test_non_spatial_geom_empty_str_delta(self):
self.client.credentials(HTTP_AUTHORIZATION="Token " + self.token1.key)
project = self.upload_project_files(self.project1)

# Push a deltafile
self.upload_and_check_deltas(
project=project,
delta_filename="nonspatial_geom_empty_str.json",
token=self.token1.key,
final_values=[
[
"1270b97d-6a28-49cc-83f3-b827ec574fee",
"STATUS_APPLIED",
self.user1.username,
],
],
)

self.assertEqual(
self.get_file_contents(project, "nonspatial.csv"),
b'fid,col1\n"1",foo\n"2",newfeature\n',
)

def test_special_data_types(self):
self.client.credentials(HTTP_AUTHORIZATION="Token " + self.token1.key)
project = self.upload_project_files(self.project1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"deltas": [
{
"uuid": "1270b97d-6a28-49cc-83f3-b827ec574fee",
"clientId": "cd517e24-a520-4021-8850-e5af70e3a612",
"exportId": "f70c7286-fcec-4dbe-85b5-63d4735dac47",
"localPk": "1",
"sourcePk": "1",
"localLayerId": "nonspatial_5b9be5d0_6faa_4c14_825d_7889615c842c",
"sourceLayerId": "nonspatial_5b9be5d0_6faa_4c14_825d_7889615c842c",
"method": "patch",
"new": {
"geometry": "",
"attributes": {
"col1": "foo"
}
},
"old": {
"geometry": null,
"attributes": {
"col1": "bar"
}
}
}
],
"files": [],
"id": "2c98410f-e1b2-45e6-9026-97898bfee730",
"project": "e02d02cc-af1b-414c-a14c-e2ed5dfee52f",
"version": "1.0"
}
3 changes: 2 additions & 1 deletion docker-qgis/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ RUN apt update \
git

# Set QGIS version as in the debian repos
ARG QGIS_VERSION=1:3.34.2+36jammy
# Choose your version from here: https://debian.qgis.org/debian/dists/jammy/main/binary-amd64/Packages
ARG QGIS_VERSION=1:3.36.1+36jammy

# Install QGIS dependencies
RUN apt update \
Expand Down
5 changes: 1 addition & 4 deletions docker-qgis/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
layers_data_to_string,
open_qgis_project,
)
from qgis.core import QgsCoordinateTransform, QgsProject, QgsRectangle, QgsVectorLayer
from qgis.core import QgsCoordinateTransform, QgsProject, QgsRectangle

PGSERVICE_FILE_CONTENTS = os.environ.get("PGSERVICE_FILE_CONTENTS")

Expand Down Expand Up @@ -51,9 +51,6 @@ def _call_libqfieldsync_packager(
else:
vl_extent = QgsRectangle()
for layer in layers.values():
if isinstance(layer, QgsVectorLayer):
continue

layer_extent = layer.extent()

if layer_extent.isNull() or not layer_extent.isFinite():
Expand Down

0 comments on commit f4c3c57

Please sign in to comment.