Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoGoCarto
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pixel Humain
GoGoCarto
Commits
8df3b2e6
Commit
8df3b2e6
authored
4 years ago
by
Adrien Pavie
Browse files
Options
Downloads
Patches
Plain Diff
Update OSM feature version after OSM push
parent
a7cf524c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Services/ElementSynchronizationService.php
+34
-8
34 additions, 8 deletions
src/Services/ElementSynchronizationService.php
with
34 additions
and
8 deletions
src/Services/ElementSynchronizationService.php
+
34
−
8
View file @
8df3b2e6
...
...
@@ -41,7 +41,8 @@ class ElementSynchronizationService
'verbose'
=>
true
]);
$osmFeature
=
$this
->
elementToOsm
(
$contribution
->
getElement
());
$element
=
$contribution
->
getElement
();
$osmFeature
=
$this
->
elementToOsm
(
$element
);
// Get URL of current map
$url
=
$this
->
urlService
->
generateUrl
();
...
...
@@ -53,7 +54,7 @@ class ElementSynchronizationService
// Process contribution
// New feature
if
(
$preparedData
[
'action'
]
==
'add'
)
{
if
(
$
preparedData
[
'data'
][
'osm:type'
]
==
'node'
)
{
if
(
$
element
->
getProperty
(
'osm:type'
)
==
'node'
)
{
$toAdd
=
$osm
->
createNode
(
$osmFeature
[
'center'
][
'latitude'
],
$osmFeature
[
'center'
][
'longitude'
],
$osmFeature
[
'tags'
]);
}
}
...
...
@@ -61,7 +62,7 @@ class ElementSynchronizationService
else
if
(
$preparedData
[
'action'
]
==
'edit'
)
{
$existingFeature
=
null
;
switch
(
$
preparedData
[
'data'
][
'osm:type'
]
)
{
switch
(
$
element
->
getProperty
(
'osm:type'
)
)
{
case
'node'
:
$existingFeature
=
$osm
->
getNode
(
$osmFeature
[
'osmId'
]);
break
;
...
...
@@ -87,7 +88,7 @@ class ElementSynchronizationService
}
// If node coordinates are edited, check if it is detached
if
(
$
preparedData
[
'data'
][
'osm:type'
]
==
'node'
&&
(
!
$existingFeature
->
getWays
()
->
valid
()
||
$existingFeature
->
getWays
()
->
count
()
==
0
))
{
if
(
$
element
->
getProperty
(
'osm:type'
)
==
'node'
&&
(
!
$existingFeature
->
getWays
()
->
valid
()
||
$existingFeature
->
getWays
()
->
count
()
==
0
))
{
if
(
$osmFeature
[
'center'
][
'latitude'
]
!=
$existingFeature
->
getLat
())
{
$existingFeature
->
setLat
(
$osmFeature
[
'center'
][
'latitude'
]);
}
...
...
@@ -130,10 +131,35 @@ class ElementSynchronizationService
$changeset
->
add
(
$toAdd
);
// Close changeset
if
(
$changeset
->
commit
())
{
try
{
$changeset
->
commit
();
// Update version in case of feature edit
if
(
$preparedData
[
'action'
]
==
'edit'
)
{
$toUpdateInDb
=
null
;
switch
(
$element
->
getProperty
(
'osm:type'
))
{
case
'node'
:
$toUpdateInDb
=
$osm
->
getNode
(
$osmFeature
[
'osmId'
]);
break
;
case
'way'
:
$toUpdateInDb
=
$osm
->
getWay
(
$osmFeature
[
'osmId'
]);
break
;
case
'relation'
:
$toUpdateInDb
=
$osm
->
getRelation
(
$osmFeature
[
'osmId'
]);
break
;
}
if
(
$toUpdateInDb
)
{
$element
->
setCustomProperty
(
'osm:version'
,
$toUpdateInDb
->
getVersion
());
$element
->
setCustomProperty
(
'osm:timestamp'
,
strval
(
$toUpdateInDb
->
getAttributes
()
->
timestamp
));
$this
->
dm
->
persist
(
$element
);
$this
->
dm
->
flush
();
}
}
return
$promise
->
resolve
(
new
Response
(
200
,
[],
null
,
'1.1'
,
'Success'
));
}
else
{
catch
(
Exception
$e
)
{
$message
=
'Error when sending changeset'
;
$log
=
new
GoGoLog
(
GoGoLogLevel
::
Error
,
'Error during OSM sync : '
.
$message
);
$this
->
dm
->
persist
(
$log
);
...
...
@@ -152,7 +178,7 @@ class ElementSynchronizationService
}
}
catch
(
Exception
$e
)
{
return
$promise
->
resolve
(
new
Response
(
2
00
,
[],
null
,
'1.1'
,
$e
->
getMessage
()));
return
$promise
->
resolve
(
new
Response
(
5
00
,
[],
null
,
'1.1'
,
$e
->
getMessage
()));
}
});
...
...
@@ -249,7 +275,7 @@ class ElementSynchronizationService
private
function
allowOsmUpload
(
$contribution
,
$preparedData
)
{
return
$contribution
->
hasBeenAccepted
()
&&
$preparedData
[
'action'
]
!=
'delete'
&&
(
$preparedData
[
'action'
]
==
'edit'
||
(
$preparedData
[
'action'
]
==
'add'
&&
$
preparedData
[
'data'
][
'osm:type'
]
==
'node'
));
&&
(
$preparedData
[
'action'
]
==
'edit'
||
(
$preparedData
[
'action'
]
==
'add'
&&
$
contribution
->
getElement
()
->
getProperty
(
'osm:type'
)
==
'node'
));
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment