vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Copy a thread with Datamanager (https://vborg.vbsupport.ru/showthread.php?t=289033)

teamshultz 10-13-2012 06:23 PM

Copy a thread with Datamanager
 
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:

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:

Code:

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


teamshultz 10-26-2012 01:24 AM

Still a no go, using the following:

Code:

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

$threadinfo = verify_id('thread', $threadid, 0, 1);
$foruminfo = fetch_foruminfo($threadinfo['forumid']);


Then for each post:
Code:

$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:

Code:

   
    $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


All times are GMT. The time now is 02:30 PM.

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.02141 seconds
  • Memory Usage 1,732KB
  • 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
  • (6)bbcode_code_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