keep original message date insert

This commit is contained in:
2021-08-30 21:31:30 +02:00
parent 1b02d26fe0
commit 26b39c81db
2 changed files with 18 additions and 11 deletions

View File

@@ -0,0 +1,2 @@
ALTER TABLE messages ADD posted_on TIMESTAMP DEFAULT 0 AFTER battery_state;
UPDATE messages SET posted_on = led, led = led;

View File

@@ -93,23 +93,27 @@ class Feed extends PhpObject {
return array_shift($asFeeds); return array_shift($asFeeds);
} }
public function getMessages($asActivePeriod = array()) { public function getMessages($asConstraints=array()) {
$asInfo = array( $asInfo = array(
'select' => array('id_message', 'ref_msg_id', 'type', 'latitude', 'longitude', 'site_time', 'timezone', 'unix_time'), 'select' => array(Db::getId(self::MSG_TABLE), 'ref_msg_id', 'type', 'latitude', 'longitude', 'site_time', 'timezone', 'unix_time'),
'from' => self::MSG_TABLE, 'from' => self::MSG_TABLE,
'constraint'=> array(Db::getId(self::FEED_TABLE) => $this->getFeedId()), 'join' => array(self::FEED_TABLE => Db::getId(self::FEED_TABLE)),
'constOpe' => array(Db::getId(self::FEED_TABLE) => "="), 'constraint'=> array(Db::getId(self::FEED_TABLE, true) => $this->getFeedId()),
'constOpe' => array(Db::getId(self::FEED_TABLE, true) => "="),
'orderBy' => array('site_time'=>'ASC') 'orderBy' => array('site_time'=>'ASC')
); );
if(!empty($asActivePeriod)) { if(!empty($asConstraints)) $asInfo = array_merge($asInfo, $asConstraints);
$asInfo['constraint']['site_time'] = $asActivePeriod;
$asInfo['constOpe']['site_time'] = "BETWEEN";
}
return $this->oDb->selectRows($asInfo); return $this->oDb->selectRows($asInfo);
} }
public function getLastMessageId($asConstraints=array()) {
$asMessages = $this->getMessages($asConstraints);
return end($asMessages)[Db::getId(self::MSG_TABLE)];
}
public function checkUpdateFeed($sProjectMode) { public function checkUpdateFeed($sProjectMode) {
$bNewMsg = false; $bNewMsg = false;
@@ -128,7 +132,7 @@ class Feed extends PhpObject {
private function updateFeed() { private function updateFeed() {
$bNewMsg = false; $bNewMsg = false;
$asData = $this->retrieveFeed(); $asData = $this->retrieveFeed();
$sLastUpdate = date(Db::TIMESTAMP_FORMAT); $sNow = date(Db::TIMESTAMP_FORMAT);
if(!isset($asData['response']['errors']) || empty($asData['response']['errors'])) { if(!isset($asData['response']['errors']) || empty($asData['response']['errors'])) {
$asMsgs = $asData['response']['feedMessageResponse']['messages']; $asMsgs = $asData['response']['feedMessageResponse']['messages'];
$asFeed = $asData['response']['feedMessageResponse']['feed']; $asFeed = $asData['response']['feedMessageResponse']['feed'];
@@ -155,7 +159,7 @@ class Feed extends PhpObject {
'name' => $asFeed['name'], 'name' => $asFeed['name'],
'description' => $asFeed['description'], 'description' => $asFeed['description'],
'status' => $asFeed['status'], 'status' => $asFeed['status'],
'last_update' => $sLastUpdate 'last_update' => $sNow
); );
$iFeedId = $this->oDb->insertUpdateRow(self::FEED_TABLE, $asFeedInfo, array('ref_feed_id')); $iFeedId = $this->oDb->insertUpdateRow(self::FEED_TABLE, $asFeedInfo, array('ref_feed_id'));
@@ -177,6 +181,7 @@ class Feed extends PhpObject {
$iMsgId = $this->oDb->selectId(self::MSG_TABLE, array('ref_msg_id'=>$asMsg['ref_msg_id'])); $iMsgId = $this->oDb->selectId(self::MSG_TABLE, array('ref_msg_id'=>$asMsg['ref_msg_id']));
if(!$iMsgId) { if(!$iMsgId) {
$asMsg['posted_on'] = $sNow;
$this->oDb->insertRow(self::MSG_TABLE, $asMsg); $this->oDb->insertRow(self::MSG_TABLE, $asMsg);
$bNewMsg = true; $bNewMsg = true;
} }
@@ -184,7 +189,7 @@ class Feed extends PhpObject {
} }
} }
} }
else $this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), array('last_update'=>$sLastUpdate)); else $this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), array('last_update'=>$sNow));
return $bNewMsg; return $bNewMsg;
} }