Current time: 07-30-2014, 03:04 AM Hello There, Guest! (LoginRegister)


Post Reply 
Rebuild and Recount
03-25-2011, 07:29 AM
Post: #1
Rebuild and Recount
Hello, I've been developing a small script to work with my boards and have come across a small issue. Basically my script grabs items from multiple rss feeds and posts them to my forums. My script successfully creates the thread, then the post, and everything is formatted and looks great. The only issue I am having is with the post count/thread count of the forum I'm posting to. What I want to know is the easiest way to rebuild the stats without going to the admincp and recounting manually. As you can imagine taking items from an rss feed means I'll have threads/posts added on an hourly basis... sometimes 50-150 at a time. I would like the stats to update as each thread/post is added but at the same time I don't want to strain the board/server. I know there must be a way to do it since after you post something through mybb it automatically updates the stats. anyone have any ideas?
Find all posts by this user
Quote this message in a reply
03-25-2011, 11:15 AM
Post: #2
RE: Rebuild and Recount
How are you posting it? You should use the post class (inc/datahandlers/post.php). Look through newreply or newthread.php to see how it works and it should do it automatically. If you really need to recount it take a look at admin/modules/tools/recount_rebuild.php

Visit this user's website Find all posts by this user
Quote this message in a reply
03-25-2011, 11:26 AM
Post: #3
RE: Rebuild and Recount
You should use the PostDataHandler rather than inserting it in the database.

Code:
$postHandler = new postDataHandler();
if($postHandler->validate_post($post))
{
    $postHandler->insert_post($post);
}

Look at the code in newthread.php or newpost.php to see what that $post array looks like.

My latest plugins: Extra Forum Permissions | Facebook Meta Tags | Auto Unapprove Reported Posts
[Image: sig.png]
Find all posts by this user
Quote this message in a reply
03-25-2011, 01:41 PM (This post was last modified: 03-25-2011 03:02 PM by Onloac.)
Post: #4
RE: Rebuild and Recount
Thanks guys! I'd rather do it through mybb then straight to the database anyways... just didnt know where to start. I'll have a look around and let you know if I can get something working. Thanks again!
Alright. I've looked around a bit and still don't really know whats going on. But I'm still searching through the code trying to figure out whats what. Right now my script doesn't have to be logged into the forums in order to post the feed items... if I was to use the post handlers I would have to rewrite everything so it logs into the forums wouldn't I?
Find all posts by this user
Quote this message in a reply
03-25-2011, 04:08 PM (This post was last modified: 03-25-2011 04:09 PM by Aries-Belgium.)
Post: #5
RE: Rebuild and Recount
(03-25-2011 01:41 PM)Onloac Wrote:  if I was to use the post handlers I would have to rewrite everything so it logs into the forums wouldn't I?

Not necessarily. You can use the post handler outside of MyBB by including global.php into your project. I created a little example for you:
PHP Code:
<?php

define
('IN_MYBB'true);

define('MYBB_ROOT'realpath("1602")."/");
include 
"./1602/global.php"// needs to be a relative path to the global.php file

// include the post handler
require_once MYBB_ROOT."inc/datahandlers/post.php";

// our new thread in an array
$uid 1;
$username "Admin";
$thread = array(
    
"fid" => 12,
    
"prefix" => 0,
    
"subject" => "Our new thread",
    
"icon" => 0,
    
"uid" => $uid,
    
"username" => $username,
    
"dateline" => TIME_NOW,
    
"message" => "Our new message",
    
"ipaddress" => get_ip(),
    
"posthash" => md5($uid.random_str())
);

// create the PostDataHandler
$posthandler = new PostDataHandler("insert");
$posthandler->action "thread";
$posthandler->set_data($thread);

// validate the thread
if($posthandler->validate_thread())
{
    
// insert it into the database
    
$posthandler->insert_thread();
}
else
{
    
print_r($posthandler->get_friendly_errors());


The above will insert a thread into forum with fid 12 and with user id 1 (usually the Admin) but you can create a thread with any user. Of course you need to change the paths of the includes to make it work on your site. All the counters that need to be updated will be updated.

My latest plugins: Extra Forum Permissions | Facebook Meta Tags | Auto Unapprove Reported Posts
[Image: sig.png]
Find all posts by this user
Quote this message in a reply
03-25-2011, 04:22 PM (This post was last modified: 03-25-2011 05:16 PM by Onloac.)
Post: #6
RE: Rebuild and Recount
Thanks... I think that might be just what I need! I'll play around with it and let you know!
@Aries-Belgium: You are the man! With that bit of code I was able to do exactly what I wanted!!! Thanks!!! One more quick question! I use addslashes cause the array won't accept quotes, how can I escape the quotes without having the slashes appear within the post?
Find all posts by this user
Quote this message in a reply
03-26-2011, 08:38 PM (This post was last modified: 03-26-2011 09:21 PM by Matt..)
Post: #7
RE: Rebuild and Recount
You can just put raw data into the array for the datahandler, the datahandler sorts out the escaping for you.

Can you still feel the butterflies?

Free never tasted like pudding.
Visit this user's website Find all posts by this user
Quote this message in a reply
03-26-2011, 09:19 PM
Post: #8
RE: Rebuild and Recount
Awesome! I swear MyBB never stops amazing me! Thanks for all your help guys everything works PERFECT now!
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | MyBB | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication