From 961b1581d18ec2f427e3e20c05782cc06447660f Mon Sep 17 00:00:00 2001 From: franzz Date: Thu, 27 Jun 2019 20:17:24 +0200 Subject: [PATCH] Fix no messages in feed warnings --- inc/feed.php | 80 +++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/inc/feed.php b/inc/feed.php index 2eec650..43c903b 100644 --- a/inc/feed.php +++ b/inc/feed.php @@ -66,49 +66,53 @@ class Feed extends PhpObject { private function updateFeed() { $asData = $this->retrieveFeed(); - $asMsgs = $asData['response']['feedMessageResponse']['messages']; - $asFeed = $asData['response']['feedMessageResponse']['feed']; - - if(!empty($asMsgs)) - { - //Update Spot Info from the first message - $asFirstMsg = array_values($asMsgs)[0]; - $asSpotInfo = array( - 'ref_spot_id' => $asFirstMsg['messengerId'], - 'name' => $asFirstMsg['messengerName'], - 'model' => $asFirstMsg['modelId'] - ); - $iSpotId = $this->oDb->insertUpdateRow(self::SPOT_TABLE, $asSpotInfo, array('ref_spot_id')); + $sLastUpdate = date(Db::TIMESTAMP_FORMAT); + if(!isset($asData['response']['errors']) || empty($asData['response']['errors'])) { + $asMsgs = $asData['response']['feedMessageResponse']['messages']; + $asFeed = $asData['response']['feedMessageResponse']['feed']; - //Update Feed Info and last update date - $asFeedInfo = array( - 'ref_feed_id' => $asFeed['id'], - Db::getId(self::SPOT_TABLE) => $iSpotId, - 'name' => $asFeed['name'], - 'description' => $asFeed['description'], - 'status' => $asFeed['status'], - 'last_update' => date(Db::TIMESTAMP_FORMAT) - ); - $iFeedId = $this->oDb->insertUpdateRow(self::FEED_TABLE, $asFeedInfo, array('ref_feed_id')); - - //Update Messages - foreach($asMsgs as $asMsg) + if(!empty($asMsgs)) { - $asMsg = array( - 'ref_msg_id' => $asMsg['id'], - Db::getId(self::FEED_TABLE) => $iFeedId, - 'type' => $asMsg['messageType'], - 'latitude' => $asMsg['latitude'], - 'longitude' => $asMsg['longitude'], - 'iso_time' => $asMsg['dateTime'], //ISO 8601 time (backup) - 'site_time' => date(Db::TIMESTAMP_FORMAT, $asMsg['unixTime']), //Conversion to Site Time (see Settings::TIMEZONE) - 'unix_time' => $asMsg['unixTime'], //UNIX Time (backup) - 'content' => $asMsg['messageContent'], - 'battery_state' => $asMsg['batteryState'] + //Update Spot Info from the first message + $asFirstMsg = array_values($asMsgs)[0]; + $asSpotInfo = array( + 'ref_spot_id' => $asFirstMsg['messengerId'], + 'name' => $asFirstMsg['messengerName'], + 'model' => $asFirstMsg['modelId'] ); - $this->oDb->insertUpdateRow(self::MSG_TABLE, $asMsg, array('ref_msg_id')); + $iSpotId = $this->oDb->insertUpdateRow(self::SPOT_TABLE, $asSpotInfo, array('ref_spot_id')); + + //Update Feed Info and last update date + $asFeedInfo = array( + 'ref_feed_id' => $asFeed['id'], + Db::getId(self::SPOT_TABLE) => $iSpotId, + 'name' => $asFeed['name'], + 'description' => $asFeed['description'], + 'status' => $asFeed['status'], + 'last_update' => $sLastUpdate + ); + $iFeedId = $this->oDb->insertUpdateRow(self::FEED_TABLE, $asFeedInfo, array('ref_feed_id')); + + //Update Messages + foreach($asMsgs as $asMsg) + { + $asMsg = array( + 'ref_msg_id' => $asMsg['id'], + Db::getId(self::FEED_TABLE) => $iFeedId, + 'type' => $asMsg['messageType'], + 'latitude' => $asMsg['latitude'], + 'longitude' => $asMsg['longitude'], + 'iso_time' => $asMsg['dateTime'], //ISO 8601 time (backup) + 'site_time' => date(Db::TIMESTAMP_FORMAT, $asMsg['unixTime']), //Conversion to Site Time (see Settings::TIMEZONE) + 'unix_time' => $asMsg['unixTime'], //UNIX Time (backup) + 'content' => $asMsg['messageContent'], + 'battery_state' => $asMsg['batteryState'] + ); + $this->oDb->insertUpdateRow(self::MSG_TABLE, $asMsg, array('ref_msg_id')); + } } } + else $this->oDb->updateRow(self::FEED_TABLE, $this->iFeedId, array('last_update'=>$sLastUpdate)); } private function retrieveFeed() {