View Full Version : Update Post/Thread Count with DataManager
maximux1
07-10-2006, 01:13 AM
I've got a mod where I am inserting new threads. I am able to create the new threads in the forumid of choice, however I can't figure out how to update the thread counts and 'last thread posted' in the forum I am creating threads in.
Although the thread is created, if you visit the forum index the last thread posted is not updated. I'm sure there is a function I have overlooked to do this.
I can post further information if needed.
Thanks
Code Monkey
07-10-2006, 02:32 AM
build_forum_counters($foruminfo['forumid']);
maximux1
07-10-2006, 03:07 AM
build_forum_counters($foruminfo['forumid']);
Thank you for your prompt & direct answer to my query.
Unfortunately, I have continued problems that I would like to request your assistance with.
Here is the code snippet I am using to build the datamanager object;
$threaddm = new vB_DataManager_Thread_FirstPost($vbulletin, ERRTYPE_STANDARD);
$forumid = 2;
$postuserid = $userid;
$userid = $userid;
$pagetext = $article;
$allowsmilie = '1';
$visible = '1';
$threaddm->do_set('forumid', $forumid);
$threaddm->do_set('postuserid', $postuserid);
$threaddm->do_set('userid', $userid);
$threaddm->do_set('username', $username);
$threaddm->do_set('pagetext', $pagetext);
$threaddm->do_set('title', $title);
$threaddm->do_set('allowsmilie', $allowsmilie);
$threaddm->do_set('visible', $visible);
$done = $threaddm->save();
build_forum_counters($foruminfo["$forumid"]);
When I run this routine the post IS created, however the counters are not updated and the following error is presented;
Fatal error: Existing data passed is not an array
Called set_existing in /home/betamar/public_html/420/includes/functions_databuild.php on line 160
Called build_forum_counters in /home/betamar/public_html/420/post.php on line 76
in /includes/class_dm.php on line 235
I believe the problem lies with the way I have assigned $forumid, however I also dont seem to have a '$foruminfo" array that I probably should be working with.
If anyone could provide some assistance or a pointer I would greatly appreciate it.
Thanks again, JumpD.
Max
After posting and looking at the code on a new background I've made some changes and now have the build_forum_counters() function working correctly.
Here is the functioning rewrite of the code snipped above;
$threaddm = new vB_DataManager_Thread_FirstPost($vbulletin, ERRTYPE_STANDARD);
$foruminfo['forumid'] = '2';
$forumid = $foruminfo['forumid'];
$postuserid = $userid;
$userid = $userid;
$pagetext = $article;
$allowsmilie = '1';
$visible = '1';
$threaddm->do_set('forumid', $forumid);
$threaddm->do_set('postuserid', $postuserid);
$threaddm->do_set('userid', $userid);
$threaddm->do_set('username', $username);
$threaddm->do_set('pagetext', $pagetext);
$threaddm->do_set('title', $title);
$threaddm->do_set('allowsmilie', $allowsmilie);
$threaddm->do_set('visible', $visible);
$done = $threaddm->save();
build_forum_counters($foruminfo['forumid']);
I've got some further problems with the way I have set the userid/username causing the uri linking to be incorrect. I'll post if I can get a functioning object.
As always, any assistance is greatly appreciated.
Max
Code Monkey
07-10-2006, 03:29 AM
Try this
$foruminfo = array();
$foruminfo['forumid'] = $forumid;
build_forum_counters($foruminfo['forumid']);
EDIT: After reading your edit.
Why create all those variables in memory? Just do this
$threaddm = new vB_DataManager_Thread_FirstPost($vbulletin, ERRTYPE_STANDARD);
$foruminfo['forumid'] = '2';
$threaddm->do_set('forumid', $foruminfo['forumid']);
$threaddm->do_set('postuserid', $userid);
$threaddm->do_set('userid', $userid);
$threaddm->do_set('username', $username);
$threaddm->do_set('pagetext', $article;
$threaddm->do_set('title', $title);
$threaddm->do_set('allowsmilie', '1');
$threaddm->do_set('visible', '1');
$done = $threaddm->save();
build_forum_counters($foruminfo['forumid']);
maximux1
07-10-2006, 03:32 PM
Thanks a lot JumpD - I really appreciate your assistance.
I've got everything working properly now with the exception of just one thing that I cant seem to find a function for.
I need something like, update_post_count() where the post count of the user is incrimented. As it is now, I dont believe it is doing anything. Post Count simply shows 0 even though the userid does have a few posts on it.
Something that would also be of service to me is if you have a link to a list of all vB functions - if such a beast exists. I've been through nearly all the programming articles at this point, and they are what has gotten me this far, however I still missing some information. I'll be going through the functions files to see if I can turn it up.
Any help is apprecaited!
Thanks
CyberRanger
07-10-2006, 05:24 PM
I need something like, update_post_count() where the post count of the user is incrimented. As it is now, I dont believe it is doing anything. Post Count simply shows 0 even though the userid does have a few posts on it. This isn't a neat function, but it will get it done!
// update post count for user
$posts = $vbulletin->db->query_first("
SELECT posts
FROM " . TABLE_PREFIX . "user
WHERE userid = ".$postuserid."
");
$newpostcount = $posts['posts'] + 1;
$vbulletin->db->free_result($posts);
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET posts = ".$newpostcount."
WHERE userid = ".$postuserid."
");
Edit: sorry ... you probably already knew that. That's not using the datamanager now is it.
maximux1
07-10-2006, 08:20 PM
Thanks buddy, that'll do the trick for now!
I appreciate your help!
Code Monkey
07-11-2006, 01:59 AM
Thanks a lot JumpD - I really appreciate your assistance.
I've got everything working properly now with the exception of just one thing that I cant seem to find a function for.
I need something like, update_post_count() where the post count of the user is incrimented. As it is now, I dont believe it is doing anything. Post Count simply shows 0 even though the userid does have a few posts on it.
Something that would also be of service to me is if you have a link to a list of all vB functions - if such a beast exists. I've been through nearly all the programming articles at this point, and they are what has gotten me this far, however I still missing some information. I'll be going through the functions files to see if I can turn it up.
Any help is apprecaited!
Thanks
It should be updating your post counts. It does for me.
Anyway, you asked for a link to all functions. Here it is.
http://members.vbulletin.com/api/
maximux1
07-11-2006, 02:02 AM
Wow - I can't believe I havent seen that yet.
Thanks for pointing out the link.
Code Monkey
07-11-2006, 02:03 AM
I just realized your doing that a bit different then I do when it comes to inisializing the datamanager. I believe your are doing that wrong. You are accessing the threadpost class directly which might be why you are not geting post count updates.
Use this instead.
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
Also, when starting a new thread you should not be passing the forum id, you shoud be passing the foruminfo array.
$forumid = 2; //Or however you are ariving at that.
$foruminfo = fetch_foruminfo($forumid);
And then in your datamanager instance use setinfo not set, as follows.
$threaddm->set_info('forum', $foruminfo);
$threaddm->set_info('thread', $threadinfo);
maximux1
07-11-2006, 02:19 AM
That didn't seem to do the trick, JumpD.
Here is my current script. Applying the change as I think it should be applied does not produce any errors, however at also does not create the thread/post.
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
// $threaddm = new vB_DataManager_Thread_FirstPost($vbulletin, ERRTYPE_STANDARD); replaced with the above line.
$foruminfo['forumid'] = '2';
$forumid = $foruminfo['forumid'];
$postuserid = $userid;
$userid = $userid;
$pagetext = $article;
$allowsmilie = '1';
$visible = '1';
$threaddm->do_set('forumid', $forumid);
$threaddm->do_set('postuserid', $postuserid);
$threaddm->do_set('userid', $userid);
$threaddm->do_set('username', $username);
$threaddm->do_set('pagetext', $pagetext);
$threaddm->do_set('title', $title);
$threaddm->do_set('allowsmilie', $allowsmilie);
$threaddm->do_set('visible', $visible);
$done = $threaddm->save();
build_forum_counters($foruminfo['forumid']);
build_user_statistics();
Any suggestions? Thanks a lot, I really appreciate your continued assistance.
:EDIT:
Im looking at your suggestions now, I will post an update in a few minutes.
Thank you!
Im definately going to have to play with this for a bit.
You've been a big help - I'll post if I get closer.
Code Monkey
07-11-2006, 02:51 AM
This is how you should do it and what works for me every time.
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$foruminfo['forumid'] = '2';
$foruminfo = fetch_foruminfo($foruminfo['forumid']);
$threadinfo = array();
$forumid = $foruminfo['forumid'];
$postuserid = $userid;
$userid = $userid;
$pagetext = $article;
$allowsmilie = '1';
$visible = '1';
$threaddm->set_info('forum', $foruminfo);
$threaddm->set_info('thread', $threadinfo);
$threaddm->setr('forumid', $forumid);
$threaddm->setr('userid', $userid);
$threaddm->setr('pagetext', $pagetext);
$threaddm->setr('title', $title);
$threaddm->set('allowsmilie', $allowsmilie);
$threaddm->set('visible', $visible);
$threaddm->pre_save();
if(count($threaddm->errors) < 1)
{
$threadid = $threaddm->save();
unset($threaddm);
build_thread_counters($threaddm);
}
build_forum_counters($foruminfo['forumid']);
EDIT: Removed the postuserid bit you had. That's not needed for a thread.
EDIT2: I also just relized you are using do_set(). You are not supposed to call that directly.
maximux1
07-11-2006, 07:29 PM
That did the trick perfectly, my friend.
I've learned a lot from you guys and I thank you for you taking the time to assist me in understanding how to use the vB construct.
Thanks again!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.