Fix no messages in feed warnings
This commit is contained in:
80
inc/feed.php
80
inc/feed.php
@@ -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'];
|
||||||
|
$asFeed = $asData['response']['feedMessageResponse']['feed'];
|
||||||
|
|
||||||
if(!empty($asMsgs))
|
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'));
|
|
||||||
|
|
||||||
//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)
|
|
||||||
{
|
{
|
||||||
$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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user