I've been doing some hand fiddling with the Drupal comments file recently and have needed to rebuild the statistics and the tread field in the comments table. Where there are many scripts I've found to rebuild comment_statistics, there's little out there on rebuilding the comment thread field (which at first looks like a little black magic). I've built a script which walks all nodes and rebuilds both. (Parts of the script are mine, parts are lifted out of comments.module parts are bits of code I've found on drupal.org). I figured I'd post the code for it here (it's also the baseline for some code I'm going to post later in the week).
To be honest, I've lost track which lines are owned by which programmer, but all of it is either from the comments module or code I pulled from the drupal forum (If I find that post I'll credit it here). I'll also post the code over on drupal.org.
Sean Reiser, 40, is a developer, technologist, and amateur photographer. Sean has spent the past 20 years as a programmer, system architect and development manager. He is a life long New York resident.
Sean currently serves as the President and Chief Geek Officer of Repair Sense, Inc.. Please go to that site with any professional inquiries.
Sean can be found using a number of social networks. These are the ones he's most active on:
Thanks for this snippet - it might be really helpful to a lot of people. I'm painstakingly porting a database over from scoop, and I need to rebuild the threading. This might do it.
Can you post something about how you deploy this code? Where would you put it to run? How does it know about Drupal's internals?
If you have the development module installed you should be able to just do a copy / paste and hit execute from the "Run PHP Code" page. Alternatively, you could put it in a function in your template file and fire it off using Drush.
Awesome. Thanks!
Just a quick follow-up: the code worked perfectly with no modifications. Paste and run. It traversed an import of 40,000 comments and didn't even hiccup.
Thanks! You saved me many braincells.