PDA

View Full Version : Issues creating multiple threads with Thread_FirstPost


Nimlh?g
07-16-2006, 12:19 PM
I'm working on a script, which requires multiple threads to be posted in a newly created forum.

In order to do that, I've created a little function which takes some basic info like forumid, userid, title and post content, and creates a Thread_FirstPost datamanager instance and then saves the post.

This works like a charm .. only .. it'll post the first post, and then nothing. Once I call the function once, it simply won't do anything anymore after that.

What am I doing wrong here?

Function:

// we'll be needing these :)
require_once(DIR .'/includes/class_dm.php');
require_once(DIR .'/includes/class_dm_threadpost.php');
function postThread( &$vbulletin, $forumid, $userid, $title, $text, $open=1, $sticky=0, $iconid=1, $allowsmilie=1 )
{


$visible = '1'; // we want the post to be visible

// need a datamanager to post a new thread
$newThread =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');

$foruminfo = verify_id('forum', $forumid, 0, 1); // post in this forum
$newThread->set('forumid', $forumid); // set the forumid
$newThread->set('userid', $userid); // post as this user
$newThread->set('pagetext', $text); // post this post
$newThread->set('title', $title); // post with this title
$newThread->set('allowsmilie', $allowsmilie); // allow smilies, or not
$newThread->set('visible', $visible); // make the post visible
$newThread->set( 'open', $open ); // locked/unlocked
$newThread->set( 'sticky', $sticky ); // sticky/unsticky
$newThread->set( 'iconid', $iconid ); // post icon
$newThread->set_info('forum', $foruminfo); // set the forum information
$newThread->save(); // save the post
unset( $newThread, $pagetext );
}


Any suggestions?

Code Monkey
07-16-2006, 01:19 PM
Any suggestions?

Just a couple. Not sure if it's related to the problem or not.

You should have


$foruminfo = fetch_foruminfo($forumid);


not


$foruminfo = verify_id('forum', $forumid, 0, 1);


Also you should have


$threadinfo = array();
$newThread->set_info('thread', $threadinfo);

Nimlh?g
07-16-2006, 03:49 PM
If I get the foruminfo that way, I get the following errors:

Fatal error: Existing data passed is not an array
Called set_existing in /www/testvb/includes/class_dm_threadpost.php on line 584
Called post_save_each_post in /www/testvb/includes/class_dm_threadpost.php on line 1536
Called post_save_each in /www/testvb/includes/class_dm_threadpost.php on line 1470
Called save in /www/newincludes/useful.php on line 28
Called postThread in /www/testvb/admincp/featuredcrap.php on line 145
in /includes/class_dm.php on line 235


I did a little bit of digging, and I'm getting the impression that this has something to do with the forumcache.

If I fetch the forum info, like so:

$foruminfo = fetch_foruminfo( $forumid, FALSE );
// instead of
$foruminfo = verify_id('forum', $forumid );


then that error goes away, but the problem remains .. the second thread is not being posted :(

I'm thinking that perhaps vB expects the forumcache to be updated between two thread-postings or something?

As a last resort I can always use a simple redirect to post the second thread, which I'm guessing would work, but I'd rather get this to work if at all possible.

Code Monkey
07-16-2006, 04:39 PM
I know what it is. Are you posting in rapid succesion and thereby violating the default time interval between posts?

Just after your sets and before you save put this. It's what I do in Articlebot.


$newThread->registry->options['floodchecktime'] = 0;


Also, I believe you should also have the $newThread->pre_save() bit in there as that runs many functions needed for a thread.

Paul M
07-16-2006, 05:46 PM
Re the above;

Instead of altering the floodcheck setting you should really add this ;

$newThread->set_info('skip_floodcheck', true);

AFAIK, presave isn't a requirement (and indeed, is not always used in vb source files).

Code Monkey
07-17-2006, 01:36 AM
Re the above;

Instead of altering the floodcheck setting you should really add this ;

I will when 3.6 is released since that is when it begins it's availabilty. ;) Thanks for the scouting report.

However, in the 3.5 series you need to do it the way I stated.

$newThread->registry->options['floodchecktime'] = 0;
AFAIK, presave isn't a requirement (and indeed, is not always used in vb source files).

Also, the new setting for floodcheck is checked in pre_save_post() which is called by pre_save(). So, you will need to call the pre_save function in order to use that setting as far as I can see so far.

Even so, the inline docs for pre_save_post suggest it will is not likely called for threads, mostly posts. I'll have to test it when I update Articlebot for 3.6.

Paul M
07-17-2006, 02:08 PM
Thanks for the scouting report.What does that mean ?

Also, the new setting for floodcheck is checked in pre_save_post() which is called by pre_save(). So, you will need to call the pre_save function in order to use that setting as far as I can see so far.The reported post > new thread code does not seem to call presave, but does use that floodcheck setting.

Code Monkey
07-18-2006, 12:53 AM
What does that mean ?

That means you found a new undocumented feature in 3.6 so I'm writing it down.

The reported post > new thread code does not seem to call presave, but does use that floodcheck setting.

Well, the only place I can find it referenced in the 3.6 files regarding threads and posts is in class_dm_threadpost.php in pre_save_post(). If you find it anywhere else, please let me know. It's not in any of the $validfields settings that I have found.

Paul M
07-18-2006, 03:18 AM
Had another look.

If presave() has not been called then save() calls it for you.

FleXy
04-13-2007, 10:37 PM
But how with this class (or another class_dm*) I can edit existing post? Please help!
example will be realy helpful