Jawsh
Active member
I have a session activity table.
user_id, activity_message, activity_heartbeat (to simplify things).
If you send a message, this gets inserted.
1, 1424255677, null
If you heartbeat a second after, this should be the result:
1, 1424255677, 1424255678
But I'm having an immense amount of trouble figuring out how to do this without writing a bunch of custom queries.
In my mind, this should work:
But, it doesn't. It works once, then subsequent updates throws duplicate PK errors. Even my work's custom framework has a way to deal with updating or inserting but DataWriting with XenForo appears oddly insufficient despite its many positives.
What should I be doing for this?
user_id, activity_message, activity_heartbeat (to simplify things).
If you send a message, this gets inserted.
1, 1424255677, null
If you heartbeat a second after, this should be the result:
1, 1424255677, 1424255678
But I'm having an immense amount of trouble figuring out how to do this without writing a bunch of custom queries.
In my mind, this should work:
Code:
// Commit the activity to database.
// Fetch writer.
$writer = $this->_getDataWriter( );
// Set user ID.
$writer->set( 'user_id', $user_id );
// Set each field to the specified time.
foreach( (array) $activities as $activity ) {
$writer->set( $activity, is_null( $time ) ? XenForo_Application::$time : (int) $time );
}
// Commit and return.
return $writer->save();
But, it doesn't. It works once, then subsequent updates throws duplicate PK errors. Even my work's custom framework has a way to deal with updating or inserting but DataWriting with XenForo appears oddly insufficient despite its many positives.
What should I be doing for this?