Hi,

I've just converted from phpbb to drupal. However, all nodes are shown as unread... is there any way to mark all nodes as read for all users?
What do I have to set/emtpy in phpmyadmin in order to get all nodes and comments to be marked as read?

Comments

itsnotme’s picture

There is no action in Drupal that allows a collective set to read.

Set to read means that in the history table, the timestamp per node revision and user is set to the current date. So if the past node revisions are unimportant to you, you could just change the timestamp for all entries in the history table.

I also coded such an action lately, see http://drupal.org/node/674682 (make sure to delete the behavior line which turned out to be wrong, but the rest is fine). You can use that action together with Views Bulk Operation then.

HTH.

NeoID’s picture

I have no revisions and my history table is empty, so basically I look for a way to rebuild it for each user (as far as I understand how it works).
Is using that snippet the best way of rebuilding it? If yes, is it just to make a module out of it and enable it or how to I use it?

Another problem I have is that is I make a new user, he/she sees all nodes as new too... :/

NeoID’s picture

I guess I have to use something like this, but then I have some troubles with how I should pass through all users and node ID's through that function...

function set_to_read_noderead_action(&$node) {
global $user;

if ($user->uid) {
  
   $sql = 'delete from {history} ' .
      "where nid='" . $node->nid . "' ".   
      "and uid='" . $user->uid . "'";

     db_query($sql);

   $sql = 'insert into {history} (nid,uid,timestamp) ' .
      "values ('" . $node->nid . "', '" . $user->uid . "', unix_timestamp()) ";

     db_query($sql);
    
  }    

NeoID’s picture

Ok... now I have made a script that populates the {history} table with each uid and all nid on my site together with a fixed timestamp. Even though this table now has about 13 million rows... it works for all users that I've added to that history table.

However...if I add a new user, Drupal doesn't look and think "Oh, the user was created 20.april, then all nodes before that date must be read", but lists all nodes as unread... that means I have to run my script for each user that registeres... is that really true? Does Drupal really not scale?

brad mering’s picture

Drupal scales very well. There are a couple of solutions to your problem. If you really want to add records for each user, the easiest way would be to create a custom module and implement the hook_user. The downside to this is that as your site grows, this will become programmaticly intensive. You don't want it to take forever to register because the system is adding thousands of lines to the history table.

A better solution would might be to declare the NODE_NEW_LIMIT. This sets a limit on how old nodes can be, and still have the new flag set. All the nodes posted before the declared date will be marked as old for all users, regardless of whether they have been read by this user. By default the system is set to one month ago. This will make all posts in the last month show up as New until a user reads it. In my settings folder I put in this line.

define('NODE_NEW_LIMIT', time() - 7*24*60*60);

This sets the time limit to be only the last week. You can set this to any date you want, either an absolute date (try strtotime("April 11 2010") ) or a relative date. Any node created before this date will be marked as old. This seems the most useful solution, since new nodes should be new, regardless of when the user registered. It would be weird if a node that was posted 5 minutes ago was marked as old just because I register on your site.

If you absolutely need the all nodes before the user registration date to be marked as old, you probably could use the Flags, Views and Rules modules to create this effect. Those modules are insanely powerful.

NeoID’s picture

You'r a genius brad mering, I love you!
I've been reading several pages back and fourth without finding anything about this... I've been looking into theme_read() and a couple of other code, but nothing did the trick.
I can't believe why this isn't in the default settings.php (commented out) as this is such an important setting, especially when converting from another CMS or just in general.

I think it's hopeless to register at ubercart or drupal and see hundreds of new posts right after I've registered.
Again, I don't know how to thank you!

volongoto’s picture

Hi,

I have the exact same problem (migrated from phpBB to Drupal and everyting is unread). I've read through this thread but I cannot say I'm following you guys.

NeoID, did you make up a module out of the code you wrote? If not could you please little bit elaborate on how to apply the patch?

Thanks in advance.

NeoID’s picture

Hi, I'm still playing around with it, but I for now I'm just using brad mering's solution... :)

volongoto’s picture

Thanks for the response.

This may sound silly, but: how and where do I define the NODE_NEW_LIMIT?

Cheers

NeoID’s picture

Just put the line in your settings.php :)

volongoto’s picture

Thanks :)

NeoID’s picture

Hm.. for some reason it doesn't work for me anymore... oO
Ported another site and I have several thousands unread...any clues?

royerd’s picture

Great solution. Boy was this hard to find. I was thinking I'd have to do a bunch of stuff in the database. I don't want to run Adv. Forum. Perfect solution here.