Improve error handling in gpx import
This commit is contained in:
parent
a26bf2e61e
commit
42475a5851
@ -82,23 +82,31 @@ if ($gpx === false) {
|
|||||||
}
|
}
|
||||||
uUtils::exitWithError($message);
|
uUtils::exitWithError($message);
|
||||||
}
|
}
|
||||||
|
else if ($gpx->getName() != "gpx") {
|
||||||
|
uUtils::exitWithError($lang["iparsefailure"]);
|
||||||
|
}
|
||||||
else if (empty($gpx->trk)) {
|
else if (empty($gpx->trk)) {
|
||||||
uUtils::exitWithError($lang["idatafailure"]);
|
uUtils::exitWithError($lang["idatafailure"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$trackCnt = 0;
|
$trackCnt = 0;
|
||||||
foreach ($gpx->trk as $trk) {
|
foreach ($gpx->trk as $trk) {
|
||||||
$trackName = empty($trk->name) ? $gpxName : $trk->name->__toString();
|
$trackName = empty($trk->name) ? $gpxName : (string) $trk->name;
|
||||||
$metaName = empty($gpx->metadata->name) ? NULL : $gpx->metadata->name->__toString();
|
$metaName = empty($gpx->metadata->name) ? NULL : (string) $gpx->metadata->name;
|
||||||
$trackId = uTrack::add($auth->user->id, $trackName, $metaName);
|
$trackId = uTrack::add($auth->user->id, $trackName, $metaName);
|
||||||
if ($trackId === false) {
|
if ($trackId === false) {
|
||||||
uUtils::exitWithError($lang["servererror"]);
|
uUtils::exitWithError($lang["servererror"]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$track = new uTrack($trackId);
|
$track = new uTrack($trackId);
|
||||||
|
$posCnt = 0;
|
||||||
|
|
||||||
foreach($trk->trkseg as $segment) {
|
foreach($trk->trkseg as $segment) {
|
||||||
foreach($segment->trkpt as $point) {
|
foreach($segment->trkpt as $point) {
|
||||||
|
if (!isset($point["lat"]) || !isset($point["lon"])) {
|
||||||
|
$track->delete();
|
||||||
|
uUtils::exitWithError($lang["iparsefailure"]);
|
||||||
|
}
|
||||||
$time = isset($point->time) ? strtotime($point->time) : 0;
|
$time = isset($point->time) ? strtotime($point->time) : 0;
|
||||||
$altitude = isset($point->ele) ? (double) $point->ele : NULL;
|
$altitude = isset($point->ele) ? (double) $point->ele : NULL;
|
||||||
$speed = NULL;
|
$speed = NULL;
|
||||||
@ -120,12 +128,17 @@ foreach ($gpx->trk as $trk) {
|
|||||||
$track->delete();
|
$track->delete();
|
||||||
uUtils::exitWithError($lang["servererror"]);
|
uUtils::exitWithError($lang["servererror"]);
|
||||||
}
|
}
|
||||||
|
$posCnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$trackCnt++;
|
if ($posCnt) {
|
||||||
|
$trackCnt++;
|
||||||
|
} else {
|
||||||
|
$track->delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return track id and tracks count
|
// return last track id and tracks count
|
||||||
uUtils::exitWithSuccess([ "trackid" => $trackId, "trackcnt" => $trackCnt ]);
|
uUtils::exitWithSuccess([ "trackid" => $trackId, "trackcnt" => $trackCnt ]);
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
x
Reference in New Issue
Block a user