From 86948e7b93beff89db5bb6bf6202353fe54e6660 Mon Sep 17 00:00:00 2001 From: jo Date: Thu, 27 Jan 2022 11:42:14 +0100 Subject: [PATCH] fix(legacy): add more null check in api live info --- .../application/controllers/ApiController.php | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/legacy/application/controllers/ApiController.php b/legacy/application/controllers/ApiController.php index ce9fdb51f..27744ae34 100644 --- a/legacy/application/controllers/ApiController.php +++ b/legacy/application/controllers/ApiController.php @@ -303,24 +303,43 @@ class ApiController extends Zend_Controller_Action $result = Application_Model_Schedule::GetPlayOrderRangeOld($limit); } + if (!isset($result)) { + $this->returnJsonOrJsonp($request, []); + } + $stationUrl = Application_Common_HTTPHelper::getStationUrl(); - if (($result['previous']['type'] != 'livestream') && isset($result['previous']['metadata'])) { - $previousID = $result['previous']['metadata']['id']; - $get_prev_artwork_url = $stationUrl . 'api/track?id=' . $previousID . '&return=artwork'; - $result['previous']['metadata']['artwork_url'] = $get_prev_artwork_url; + if (isset($result['previous'])) { + if ( + (isset($result['previous']['type']) && $result['previous']['type'] != 'livestream') + && isset($result['previous']['metadata']) + ) { + $previousID = $result['previous']['metadata']['id']; + $get_prev_artwork_url = $stationUrl . 'api/track?id=' . $previousID . '&return=artwork'; + $result['previous']['metadata']['artwork_url'] = $get_prev_artwork_url; + } } - if (($result['current']['type'] != 'livestream') && isset($result['current']['metadata'])) { - $currID = $result['current']['metadata']['id']; - $get_curr_artwork_url = $stationUrl . 'api/track?id=' . $currID . '&return=artwork'; - $result['current']['metadata']['artwork_url'] = $get_curr_artwork_url; + if (isset($result['current'])) { + if ( + (isset($result['current']['type']) & $result['current']['type'] != 'livestream') + && isset($result['current']['metadata']) + ) { + $currID = $result['current']['metadata']['id']; + $get_curr_artwork_url = $stationUrl . 'api/track?id=' . $currID . '&return=artwork'; + $result['current']['metadata']['artwork_url'] = $get_curr_artwork_url; + } } - if (($result['next']['type'] != 'livestream') && isset($result['next']['metadata'])) { - $nextID = $result['next']['metadata']['id']; - $get_next_artwork_url = $stationUrl . 'api/track?id=' . $nextID . '&return=artwork'; - $result['next']['metadata']['artwork_url'] = $get_next_artwork_url; + if (isset($result['next'])) { + if ( + (isset($result['next']['type']) && $result['next']['type'] != 'livestream') + && isset($result['next']['metadata']) + ) { + $nextID = $result['next']['metadata']['id']; + $get_next_artwork_url = $stationUrl . 'api/track?id=' . $nextID . '&return=artwork'; + $result['next']['metadata']['artwork_url'] = $get_next_artwork_url; + } } // apply user-defined timezone, or default to station