########################################################################################## GPXIN-32: Fatal error for Route only files when speed etc not suppressed ########################################################################################## Issue Type: Bug ----------------------------------------------------------------------------------------- Issue Information ==================== Priority: Critical Status: Closed Resolution: Fixed (2017-07-04 10:11:03) Project: PHP GPXIngest (GPXIN) Reported By: btasker Assigned To: btasker Affected Versions: - 1.02 - 1.03 Targeted for fix in version: - 1.03 Time Estimate: 0 minutes Time Logged: 0 minutes ----------------------------------------------------------------------------------------- Issue Description ================== Github #19 reports that in order to successfully import a specific file, the user had to suppress a number of elements -- BEGIN SNIPPET -- $gpx->suppress('speed'); $gpx->suppress('elevation'); $gpx->suppress('location'); $gpx->suppress('date'); -- END SNIPPET -- It's odd that speed (in particular) needed to be suppressed, as GPXIN-16 was supposed to implement auto-detection. However, the user's GPX file uses a route (support added in GPX-27) so it may be related to that. Running a quick test, failure to do so doesn't just generate NOTICE level errors, but also results in a fatal: -- BEGIN SNIPPET -- Fatal error: Cannot access empty property in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 573 -- END SNIPPET -- ----------------------------------------------------------------------------------------- Attachments ============ - gpx-ingest-pb.zip ----------------------------------------------------------------------------------------- Issue Relations ================ - Caused by GPXIN-27: Route Support - Github #19 (https://github.com/bentasker/PHP-GPX-Ingest/issues/19) ----------------------------------------------------------------------------------------- Activity ========== ----------------------------------------------------------------------------------------- 2017-07-03 09:32:28 btasker ----------------------------------------------------------------------------------------- In #19 the user has provided an example of the changes they made to fix the notices: -- BEGIN SNIPPET -- if (!$this->suppresselevation){ if (isset($this->journey->journeys)) { $this->journey->journeys->$jkey->segments->$segkey->stats->elevation = new \stdClass(); $this->journey->journeys->$jkey->segments->$segkey->stats->elevation->max = max($this->jeles); $this->journey->journeys->$jkey->segments->$segkey->stats->elevation->min = min($this->jeles); $this->journey->journeys->$jkey->segments->$segkey->stats->elevation->avgChange = round(array_sum($this->jeledevs)/count($this->jeledevs),2); } } if (!$this->suppresslocation){ $this->journey->stats->distanceTravelled = array_sum($this->jdist); // See GPXIN-6 if (!empty($this->journeylats)) { // Update the Lat/Lon bounds. See GPXIN-26 $this->journey->stats->bounds->Lat->min = min($this->journeylats); $this->journey->stats->bounds->Lat->max = max($this->journeylats); } if (!empty($this->journeylons)) { $this->journey->stats->bounds->Lon->min = min($this->journeylons); $this->journey->stats->bounds->Lon->max = max($this->journeylons); } } -- END SNIPPET -- (They added the isset and empty checks) So, looking at that, it's not that speed etc isn't getting suppressed (though elevation and location may not be) but that that section makes the assumption that there'll be a track present. In the given example GPX file, this isn't the case and there's only a route. ----------------------------------------------------------------------------------------- 2017-07-03 09:32:53 ----------------------------------------------------------------------------------------- btasker added 'gpx-ingest-pb.zip' to Attachments ----------------------------------------------------------------------------------------- 2017-07-03 09:39:29 btasker ----------------------------------------------------------------------------------------- OK, so the full list of warning's etc without any of that suppressed (and without the user's suggested changes) is -- BEGIN SNIPPET -- PHP Warning: min(): Array must contain at least one element in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 543 Warning: min(): Array must contain at least one element in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 543 PHP Warning: max(): Array must contain at least one element in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 544 Warning: max(): Array must contain at least one element in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 544 PHP Warning: max(): Array must contain at least one element in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 548 Warning: max(): Array must contain at least one element in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 548 PHP Warning: min(): Array must contain at least one element in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 549 Warning: min(): Array must contain at least one element in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 549 PHP Warning: max(): Array must contain at least one element in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 550 Warning: max(): Array must contain at least one element in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 550 PHP Warning: Division by zero in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 551 Warning: Division by zero in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 551 PHP Notice: Undefined variable: jkey in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 573 Notice: Undefined variable: jkey in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 573 PHP Fatal error: Cannot access empty property in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 573 Fatal error: Cannot access empty property in /home/ben/Documents/src.old/PHP-GPX-Ingest/src/GPXIngest/GPXIngest.php on line 573 -- END SNIPPET -- Looks like there's more than a little bit of tidying to do. ----------------------------------------------------------------------------------------- 2017-07-03 09:40:09 ----------------------------------------------------------------------------------------- btasker changed priority from '[issuelistpty 3]Major[/issuelistpty]' to '[issuelistpty 2]Critical[/issuelistpty]' ----------------------------------------------------------------------------------------- 2017-07-03 09:40:33 btasker ----------------------------------------------------------------------------------------- Making bug title more relevant, and bumping priority up to critical as this causes a break in processing. ----------------------------------------------------------------------------------------- 2017-07-03 09:48:28 btasker ----------------------------------------------------------------------------------------- OK, so the GPXIN-16 auto-suppression isn't firing, because it only fires if a track is present -- BEGIN SNIPPET -- foreach ($trkseg->trkpt as $trkpt){ // Initialise some variables $key = "trackpt$x"; $ptspeed = (int)filter_var($trkpt->desc, FILTER_SANITIZE_NUMBER_INT); $speed_string = (string) $trkpt->desc; // If speed is not available (and we're not calculating anything which can be used) suppress speed // Will need updating in GPXIN-20 if (!$trkpt->desc && !$this->expisenabled('calcDistance')){ $this->suppress('speed'); // Prevent warnings if speed is not available - See GPXIN-16 } -- END SNIPPET -- However, the statements causing the issue, will fire either way. They don't currently process _any_ data from routes though, so the simplest initial fix would be to move them out to a new method and have that check first whether any tracks have been processed ----------------------------------------------------------------------------------------- 2017-07-03 10:17:30 git ----------------------------------------------------------------------------------------- -- BEGIN QUOTE -- Repo: PHP-GPX-Ingest Commit: 371916e05b05bffc1bddeb564d183ef622ee5e01 Author: B Tasker