vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Issues creating multiple threads with Thread_FirstPost (https://vborg.vbsupport.ru/showthread.php?t=121330)

Nimlh?g 07-16-2006 11:19 AM

Issues creating multiple threads with Thread_FirstPost
 
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:
PHP Code:

// 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=)
{


      
$visible '1';    // we want the post to be visible
      
      // need a datamanager to post a new thread
    
$newThread =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');        
    
    
$foruminfo verify_id('forum'$forumid01);    // 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 12:19 PM

Quote:

Originally Posted by Nimlh?g
Any suggestions?

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

You should have

PHP Code:

$foruminfo fetch_foruminfo($forumid); 

not

PHP Code:

$foruminfo verify_id('forum'$forumid01); 

Also you should have

PHP Code:

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


Nimlh?g 07-16-2006 02:49 PM

If I get the foruminfo that way, I get the following errors:
Quote:

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:
PHP Code:

$foruminfo fetch_foruminfo$forumidFALSE );
// 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 03: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.

PHP Code:

$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 04:46 PM

Re the above;

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

PHP Code:

$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 12:36 AM

Quote:

Originally Posted by Paul M
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.

PHP Code:

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

Quote:

Originally Posted by Paul M
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 01:08 PM

Quote:

Originally Posted by JumpD
Thanks for the scouting report.

What does that mean ?

Quote:

Originally Posted by JumpD
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-17-2006 11:53 PM

Quote:

Originally Posted by Paul M
What does that mean ?

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

Quote:

Originally Posted by Paul M
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 02:18 AM

Had another look.

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

FleXy 04-13-2007 09:37 PM

But how with this class (or another class_dm*) I can edit existing post? Please help!
example will be realy helpful


All times are GMT. The time now is 03:42 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01575 seconds
  • Memory Usage 1,770KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_php_printable
  • (8)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete