PDA

View Full Version : How to get $threadid after posting a new thread?


koon85
03-24-2009, 04:32 PM
I create a new thread using vB_DataManager_Thread_FirstPost, after that, I want to use vB_DataManager_Post to create a new post immediately in that thread. But I failed. Because I can't get the ID of the new thread created by vB_DataManager_Thread_FirstPost.

Here is the code to create a new thread:
<?php
// Create a new thread
require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_threadpost.php');
require_once('./includes/functions_databuild.php'); // required for "build_forum_counters"

$threadsdm = new vB_DataManager_Thread_FirstPost($vbulletin, ERRTYPE_STANDARD);
$forumid = '4';
$userid = '202';
$title = 'Test New Thread';
$pagetext = 'This works... Whoodavdvdavadvdaavavddavvad Hoo!!';
$allow_smilie = '1';
$visible = '1';

$foruminfo = fetch_foruminfo($forumid);
$threadsdm->set_info('forum', $foruminfo);
$threadsdm->set('forumid', $foruminfo['forumid']);
$threadsdm->set('forumid', $forumid);
$threadsdm->set('userid', $userid);
$threadsdm->set('title', $title);
$threadsdm->set('pagetext', $pagetext);
$threadsdm->set('allowsmilie', $allow_smilie);
$threadsdm->set('visible', $visible);
$threadsdm->save();
unset($threadsdm);
build_forum_counters($forumid);
?>

Here is the code to create a new post:

<?php
// Create a new thread
require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_threadpost.php');
require_once('./includes/functions_databuild.php'); // required for "build_forum_counters"

$postdm = new vB_DataManager_Post($vbulletin, ERRTYPE_STANDARD);
$timenow = TIMENOW ;
$threadinfo = fetch_threadinfo($threadid);
$foruminfo = fetch_foruminfo($forumid);
$threadid = '2421';
$userid = '202';
$wiadomosc = 'dbbvgdbxb dga shsf dzbfbd';

$postdm->set_info('forum', $foruminfo);
$postdm->set_info('thread', $threadinfo);
$postdm->set('threadid', $threadid);
$postdm->set('title', $symid);
$postdm->set('userid', $userid);
$postdm->set('pagetext', $wiadomosc);
$postdm->set('allowsmilie', 1);
$postdm->set('visible', 1);
$postdm->set('dateline', $timenow);
$postdm->save();

unset($postdm);
build_forum_counters($forumid);
?>

How to combine the two to the only one script? The problem is that, I can't get the $threadid from the new thread after it was posted and pass it to the second, I have try using
$threadid = $threaddm->save();
But it still not work! I have error:
Fatal error: Call to a member function save() on a non-object in C:\wamp\www\forum3\test1.php on line 27
Here is the code:
<?php
// Create a new thread
require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_threadpost.php');
require_once('./includes/functions_databuild.php'); // required for "build_forum_counters"

$threadsdm = new vB_DataManager_Thread_FirstPost($vbulletin, ERRTYPE_STANDARD);
$forumid = '4';
$userid = '202';
$title = 'Test New Thread';
$pagetext = 'This works... Whoodavdvdavadvdaavavddavvad Hoo!!';
$allow_smilie = '1';
$visible = '1';

$foruminfo = fetch_foruminfo($forumid);
$threadsdm->set_info('forum', $foruminfo);
$threadsdm->set('forumid', $foruminfo['forumid']);
$threadsdm->set('forumid', $forumid);
$threadsdm->set('userid', $userid);
$threadsdm->set('title', $title);
$threadsdm->set('pagetext', $pagetext);
$threadsdm->set('allowsmilie', $allow_smilie);
$threadsdm->set('visible', $visible);
$threadsdm->save();

$threadid = $threaddm->save(); //line 27
$postdm = new vB_DataManager_Post($vbulletin, ERRTYPE_STANDARD);
$timenow = TIMENOW ;
$threadinfo = fetch_threadinfo($threadid);
$foruminfo = fetch_foruminfo($forumid);
//$threadid = '693';
$userid = '202';
$wiadomosc = 'dbbvgdbxb dga shsf dzbfbd';

$postdm->set_info('forum', $foruminfo);
$postdm->set_info('thread', $threadinfo);
$postdm->set('threadid', $threadid);
$postdm->set('title', $symid);
$postdm->set('userid', $userid);
$postdm->set('pagetext', $wiadomosc);
$postdm->set('allowsmilie', 1);
$postdm->set('visible', 1);
$postdm->set('dateline', $timenow);
$postdm->save();

unset($threadsdm);
unset($postdm);
build_forum_counters($forumid);
?>

Any ideas will be appreciate very much, thanks!

Dismounted
03-25-2009, 08:46 AM
You are instantiating the class as $threadsdm, and then saving it by calling a method from $threaddm (see the difference? ;)). Also, you should only be running save() (for the thread) once (get rid of one of them).