News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Inserting posts using createPost

Started by kai920, December 13, 2009, 03:29:13 AM

Previous topic - Next topic

kai920

#20
Quote from: Arantor on December 14, 2009, 03:18:57 AM
And, no, but you *can* use the query it uses to nicely fill up your log-read tables.

Can you give me a hint on which query I should start looking at inside the markRead() function in Subs-Board.php?

Arantor

* Arantor sees if he can find some time to check the source.

But it'll be a db_insert / db_query(INSERT INTO) type of query (version dependent) filling up log_mark_read (I think that's what it's called, anyhow)

kai920

Thanks, that would be most appreciated.

I hadn't even looked at that table yet, I thought all along it would be log_topics, oops.


OT: is there a post that explains SMF's database tables/columns?

Arantor

There's two - log_mark_read for marking an entire board as read (but not individual messages) and log_topics, for individual topics.

No, there isn't, really should be one.

kai920

Quote from: Arantor on December 15, 2009, 05:15:07 AM
There's two - log_mark_read for marking an entire board as read (but not individual messages) and log_topics, for individual topics.


I see, then I probably do want log_topics then. Does this work on a topic level, or individual posts as well?


I want to mark an entire topic read, including any replies (if they exist).


Quote
No, there isn't, really should be one.


Agreed! Maybe you could kickstart something... :)

Arantor

log_topics works on a per topic/per message deal, specifically it tracks the last message you saw in a thread. Meaning you need to set it to the same as the id_msg for the last message in that topic (i.e. the same as topics.id_last_msg)

I've thought about documenting the schema but for 2.0 it's still under renovation in some ways...

kai920

Quote from: Arantor on December 15, 2009, 11:55:08 AM
log_topics works on a per topic/per message deal, specifically it tracks the last message you saw in a thread. Meaning you need to set it to the same as the id_msg for the last message in that topic (i.e. the same as topics.id_last_msg)
OK, so when I'm inserting replies I will need to know the last msg id and mark that as read? And all the posts before it will automagically be marked as read?  ???
(if there are no replies, the last msg id is the same as the first msg id?)


QuoteI've thought about documenting the schema but for 2.0 it's still under renovation in some ways...
True, didn't think of that.

Arantor

Quote from: kai920 on December 15, 2009, 10:46:17 PM
OK, so when I'm inserting replies I will need to know the last msg id and mark that as read? And all the posts before it will automagically be marked as read?  ???

Or if you use createPost, set $topicOptions['mark_as_read'] to true before sending it in. But otherwise, yes.

Quote
(if there are no replies, the last msg id is the same as the first msg id?)

Yes.

Quote
QuoteI've thought about documenting the schema but for 2.0 it's still under renovation in some ways...
True, didn't think of that.

It does raise other issues. PMs for example, we don't ever discuss how to access them on here. The mentality is that admins can access the content when it is supposed to be private, so we never cover how to access it.

That's kind of why I haven't documented the schema at all, not that I've had a great deal of time for it anyhow.

kai920

Quote from: Arantor on December 16, 2009, 04:33:45 AM
Quote from: kai920 on December 15, 2009, 10:46:17 PM
OK, so when I'm inserting replies I will need to know the last msg id and mark that as read? And all the posts before it will automagically be marked as read?  ???

Or if you use createPost, set $topicOptions['mark_as_read'] to true before sending it in. But otherwise, yes.



Right, but that only marks as read for the author of the post as I understand... I want to mark the posts I insert using createPost to be marked read for everyone in my forum. I don't want 400 or how ever many unread posts to 'suddenly' appear out of nowhere, especially if they're from 2005  ;D

Arantor

Ah, in which case, yes, you will need to insert a row per topic per user. I'm pretty sure you can actually safely use any suitably large number though, not explicitly the last message id (will experiment with this in a minute for something else actually)

kai920

Let me know what you find out - thanks.

Not sure what you mean by using any suitably large number?

Arantor

The general id is that it contains the id of the last message.

I'm thinking if you put a very large number - much larger than the id_msgs you're adding - it'll be treated as read. For example, 99999999 is a suitably large number.

kai920

Quote from: Arantor on December 15, 2009, 05:15:07 AM
There's two - log_mark_read for marking an entire board as read (but not individual messages) and log_topics, for individual topics.

I still don't get the difference between log_mark_read and log_topics... can you explain? for example around line 129 in Subs-Boards.php, it seems to my untrained eye that they are doing the same thing, but I don't understand why both tables need to have the same data?

   // Otherwise mark the board as read.
   else
   {
      $markRead = array();
      foreach ($boards as $board)
         $markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);


      // Update log_mark_read and log_boards.
      $smcFunc['db_insert']('replace',
         '{db_prefix}log_mark_read',
         array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'),
         $markRead,
         array('id_board', 'id_member')
      );


      $smcFunc['db_insert']('replace',
         '{db_prefix}log_boards',
         array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'),
         $markRead,
         array('id_board', 'id_member')
      );
   }



For the posts and replies I insert into SMF, do I need to fiddle with both tables? (recall that I am trying to mark the entire topic - including any replies - to be "read" for all members of my forum)

Arantor

You need to fiddle with both.

log_mark_read controls things being visible on the main board index and whether the board has been read for that user, log_topics whether the individual topic has been read.

Both need to be updated, though log_mark_read can be done after the rest, since you only set one value per member per board.

kai920

OK, gotcha (I think) ;)

Two questions:

1. What goes in the id_msg column of log_mark_read?

2. My existing forum has an extra column called logTime. Is this a holdover from SMF1.x, or inserted by a mod? A clean 2.0RC2 install seems to have only 3 columns: id_member, id_board, and id_msg.

Arantor

1. $modSettings['maxMsgId'] - the last message id in the forum usually.

2. It's definitely a holdover or from a mod. No 2.0 field has upper case characters.

kai920

OK, so I'm working on log_topics first. I only need 1 row per topicId inside log_topics right?

ie. if my topic is id 10, and it has msgIds 100, 101, 102... I'd only need a row that had topic id = 10 and msg id = 102. (I don't need 10,101  and 10,100 )


I'd need to check if the topic id already exists in log_topics, and if it does, update it with the higher msg id...?

Arantor

Log topics needs one row per user per topic, but yeah.

Just use db_insert 'replace' to do it; that will either update or add row as necessary - the same style of query is in Display.php when it is marked read.

kai920

Oh, nice. I totally didn't know this... I was doing something way too cumbersome then?


QuoteA. query db to see if topic exists


B. if db_affected_rows == 0, then
do db_insert "INSERT"
else
do db_insert "REPLACE"



It sounds like I can get rid of step A, and just do a db_insert 'replace' directly?

kai920

OK, thanks to you, I believe I've got log_topics sorted.  :)

Quote from: Arantor on December 17, 2009, 07:08:12 AM
Both need to be updated, though log_mark_read can be done after the rest, since you only set one value per member per board.

If $modSettings['maxMsgID'] goes into the log_mark_read board, that will mark the board as read, even if there are existing messages unread, correct?

What I mean is: say the user has unread posts in board id #1 - the board's icon on the MessageIndex will have unread posts. If I insert 1000 topics/replies and increase the id_msg for the user in log_mark_read, will it

a) show on the MessageIndex that he has no unread posts (icon = no new posts); but
b) after entering the board, still see "new" icons besides the existing topics that he has not read?

PS. I just noticed another table... what is log_boards for? Again it looks similar to log_mark_read  ??? 

Advertisement: