issue #628 save_user_coords#629
Conversation
88a83ba to
2d3306a
Compare
091137a to
ad8b421
Compare
cccc1cd to
4a5f2f4
Compare
4a5f2f4 to
b4cb1a9
Compare
e8d3b16 to
0462c38
Compare
0462c38 to
e24323f
Compare
|
If you want a feedback from c:geo side, please open an issue there. |
e24323f to
5194518
Compare
Use a simple '' instead of Db::escape_string("") for the empty
description value in the INSERT statement.
b8d1c60 to
60a163a
Compare
| else # oc.pl branch | ||
| { | ||
| $rs = Db::query(" | ||
| select max(id) as id | ||
| from cache_mod_cords | ||
| where | ||
| cache_id = '".Db::escape_string($cache_id)."' | ||
| and user_id = '".Db::escape_string($user_id)."' | ||
| "); | ||
| $id = null; | ||
| if($row = Db::fetch_assoc($rs)) { | ||
| $id = $row['id']; | ||
| } | ||
| if ($id == null) { | ||
| Db::query(" | ||
| insert into cache_mod_cords ( | ||
| cache_id, user_id, latitude, longitude | ||
| ) values ( | ||
| '".Db::escape_string($cache_id)."', | ||
| '".Db::escape_string($user_id)."', | ||
| '".Db::escape_string($latitude)."', | ||
| '".Db::escape_string($longitude)."' | ||
| ) | ||
| "); | ||
| } else { | ||
| Db::query(" | ||
| update cache_mod_cords | ||
| set latitude = '".Db::escape_string($latitude)."', | ||
| longitude = '".Db::escape_string($longitude)."' | ||
| where | ||
| id = '".Db::escape_string($id)."' | ||
| "); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
OCPL cache_mod_cords table does not contain an id column.
create table cache_mod_cords
(
cache_id int not null,
user_id int not null,
date timestamp default current_timestamp() not null,
longitude double not null,
latitude double not null,
primary key (cache_id, user_id)
)
it should look something like this:
else # oc.pl branch
{
Db::query("
INSERT INTO cache_mod_cords (
cache_id,
user_id,
latitude,
longitude,
date
) VALUES (
'".Db::escape_string($cache_id)."',
'".Db::escape_string($user_id)."',
'".Db::escape_string($latitude)."',
'".Db::escape_string($longitude)."',
NOW()
)
ON DUPLICATE KEY UPDATE
latitude = VALUES(latitude),
longitude = VALUES(longitude),
date = NOW()
");
}
Additionally, in OCPL only some cache types support user coordinates:
https://github.com/opencaching/opencaching-pl/blob/30ae3a4681c6840fe5aad454ccdb50fdb1340603/src/Controllers/ViewCacheController.php#L646-L648
There was a problem hiding this comment.
I have commited your suggested else path.
With respect go the cache types that support user coordinates: in OCDE all do. I don't know how to access ocpl source code so pls send me the list of cache types that do support it then I will add the filtering.
cache_mod_cords has a composite PK (cache_id, user_id) with no id column, so the previous select max(id) would fail at runtime.
stefopl
left a comment
There was a problem hiding this comment.
The documentation should also be updated to include these changes.
| 'services/caches/geocache', | ||
| new OkapiInternalRequest($request->consumer, $request->token, array( | ||
| 'cache_code' => $cache_code, | ||
| 'fields' => 'internal_id' |
There was a problem hiding this comment.
| 'fields' => 'internal_id' | |
| 'fields' => 'internal_id|type' |
| )) | ||
| ); | ||
| $cache_id = $geocache['internal_id']; | ||
|
|
There was a problem hiding this comment.
| self::validate_cache_type($geocache['type']); | |
| ); | ||
| return Okapi::formatted_response($request, $result); | ||
| } | ||
|
|
There was a problem hiding this comment.
| private static function validate_cache_type($cache_type) | |
| { | |
| if (Settings::get('OC_BRANCH') != 'oc.pl') { | |
| return; | |
| } | |
| $allowed_types = array( | |
| 'Other', | |
| 'Quiz', | |
| 'Multi', | |
| ); | |
| if (!in_array($cache_type, $allowed_types, true)) { | |
| throw new InvalidParam( | |
| 'cache_code', | |
| "User coordinates are not supported for cache type '$cache_type'." | |
| ); | |
| } | |
| } |
OCPL only supports user coordinates for Multi, Quiz, and Other cache types (per ViewCacheController). Fetch the type field alongside internal_id and reject unsupported types with HTTP 400. Also document the OCPL restriction in docs.xml.
|
Thanks @stefopl — all suggestions applied in d27f91d:
(Personally I think OCPL should support user coordinates for all cache types, but that's a separate discussion — scoping it to the platform constraint for now.) |
This is about adding a new service endpoint. The platforms (opencaching.xx) provide the capabilities to maintain a personal cache notes field for each cache. In addition with this there is also a capability to store user provided coordinates for instance the coordinates that are the result of solving a puzzle.
The OKAPI provides a service to retrieve the personal caches notes and also the user_coords. It also provides a service to update the personal cache notes but not the user coords.
I have implemented a new service to fill this gap. First I thought about extending the already existing service
:: services/caches/save_personal_notes
however, to make sure that this doesn't create any adverse side effects for existing client applications I decided to implement a new service:
:: services/caches/save_user_coords.