PDA

View Full Version : Copy a thread with Datamanager


teamshultz
10-13-2012, 06:23 PM
Is it possible to copy an existing thread to another forum without moving it using the datamanager? I know how to change the values of a thread but I'm clueless as to how to just make an exact copy elsewhere. Any help is appreciated.

kh99
10-13-2012, 06:56 PM
I think you'd have to query the database for the thread record and all post records, then use the datamanager(s) to add the thread and posts just like it was a new thread, using data from your queries. (If I remember correctly it's a 'Thread_FirstPost' datamanager for the thread and first post combined, and 'Post' datamanagers for each post after that).

teamshultz
10-26-2012, 12:23 AM
I'm using build_thread_counters and build_forum_counters to get all that information up to date. Do you know how to update the posting user's post count? It doesn't get increased with a manual post add.

kh99
10-26-2012, 12:42 AM
If you used the datamanager to save the posts then everything should be taken care of (including updating counts). If you didn't use the dm then you might want to look in includes/class_dm_threadpost.php and see what happens when posts are saved (I think you want functionfunction post_save_each_post() which starts around line 502).

ETA: there's probably a function called in the admincp code that recalculates the count for all users, so I suppose that's another option although that's a lot of work to do if you have a big forum.

teamshultz
10-26-2012, 01:05 AM
Thanks for the response.

I'm using the post datamanager to add the post. Here's my code:


$tdm =& datamanager_init('Post', $vbulletin, ERRTYPE_ARRAY, 'threadpost');

$tdm->set('userid', $userid);
$tdm->set('pagetext', $text);
$tdm->set('allowsmilie', 1);
$tdm->set('visible', 1);
$tdm->set('threadid', $threadid);
$tdm->set('dateline', $date);
require_once(DIR . '/includes/functions_databuild.php');
$tdm->save();

build_thread_counters($threadid);
build_forum_counters(19);


It's definitely not updating the post count. I made some normal posts from that user and watched his post count increase. Then I made some posts from that user using this snippet of code and his post count stayed the same. His post count decreased after deleting the posts. So, as I'm testing, his post count is dropping :/

Does it look like something's missing in the code I'm using?

kh99
10-26-2012, 01:19 AM
Hmm...try adding this:

$userinfo = fetch_userinfo($userid);
$tdm->set_info('user', $userinfo);

teamshultz
10-26-2012, 01:24 AM
Still a no go, using the following:

$tdm =& datamanager_init('Post', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$userinfo = fetch_userinfo($userid);
$tdm->set_info('user', $userinfo);
$tdm->set('userid', $userid);
$tdm->set('pagetext', $text);
$tdm->set('allowsmilie', 1);
$tdm->set('visible', 1);
$tdm->set('threadid', $threadid);
$tdm->set('dateline', $date);
$tdm->save();

kh99
10-26-2012, 01:44 AM
OK, try adding this:

Once at the start:
$threadinfo = verify_id('thread', $threadid, 0, 1);
$foruminfo = fetch_foruminfo($threadinfo['forumid']);


Then for each post:
$tdm->set_info('forum', $foruminfo);
$tdm->set_info('thread', $threadinfo);


BTW, I'm looking in includes/functions_newpost.php at function build_new_post() as well as class_dm_threadpost.php.

teamshultz
10-26-2012, 01:52 AM
You, sir, are a gentleman and a scholar. This worked beautifully:


$tdm =& datamanager_init('Post', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$threadinfo = verify_id('thread', $threadid, 0, 1);
$foruminfo = fetch_foruminfo($threadinfo['forumid']);
$userinfo = fetch_userinfo($userid);
$tdm->set_info('user', $userinfo);
$tdm->set_info('forum', $foruminfo);
$tdm->set_info('thread', $threadinfo);
$tdm->set('userid', $userid);
$tdm->set('pagetext', $text);
$tdm->set('allowsmilie', 1);
$tdm->set('visible', 1);
$tdm->set('threadid', $threadid);
$tdm->set('dateline', $date);
$tdm->save();

require_once(DIR . '/includes/functions_databuild.php');
build_thread_counters($threadid);
build_forum_counters(19);

meshkruaj
12-16-2012, 08:05 PM
great ,but how do we also add tags to a thread using the datamanager method
i tried with

do_set('taglist','tag1,tag2')

and it shows the tags under the post but when clicked it says invalid tags .
seems some "rebuild/reindex" problem