Fix no messages in feed warnings

This commit is contained in:
2019-06-27 20:17:24 +02:00
parent 9f2dcc2e7c
commit 8fa03b2b56

View File

@@ -66,49 +66,53 @@ class Feed extends PhpObject {
private function updateFeed() { private function updateFeed() {
$asData = $this->retrieveFeed(); $asData = $this->retrieveFeed();
$asMsgs = $asData['response']['feedMessageResponse']['messages']; $sLastUpdate = date(Db::TIMESTAMP_FORMAT);
$asFeed = $asData['response']['feedMessageResponse']['feed']; if(!isset($asData['response']['errors']) || empty($asData['response']['errors'])) {
$asMsgs = $asData['response']['feedMessageResponse']['messages'];
if(!empty($asMsgs)) $asFeed = $asData['response']['feedMessageResponse']['feed'];
{
//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'));
//Update Feed Info and last update date if(!empty($asMsgs))
$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)
{ {
$asMsg = array( //Update Spot Info from the first message
'ref_msg_id' => $asMsg['id'], $asFirstMsg = array_values($asMsgs)[0];
Db::getId(self::FEED_TABLE) => $iFeedId, $asSpotInfo = array(
'type' => $asMsg['messageType'], 'ref_spot_id' => $asFirstMsg['messengerId'],
'latitude' => $asMsg['latitude'], 'name' => $asFirstMsg['messengerName'],
'longitude' => $asMsg['longitude'], 'model' => $asFirstMsg['modelId']
'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')); $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() { private function retrieveFeed() {