Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 10-13-2012, 06:23 PM
teamshultz teamshultz is offline
 
Join Date: Dec 2009
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 10-13-2012, 06:56 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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).
Reply With Quote
  #3  
Old 10-26-2012, 12:23 AM
teamshultz teamshultz is offline
 
Join Date: Dec 2009
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 10-26-2012, 12:42 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 10-26-2012, 01:05 AM
teamshultz teamshultz is offline
 
Join Date: Dec 2009
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #6  
Old 10-26-2012, 01:19 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm...try adding this:

Code:
$userinfo = fetch_userinfo($userid);
$tdm->set_info('user', $userinfo);
Reply With Quote
  #7  
Old 10-26-2012, 01:24 AM
teamshultz teamshultz is offline
 
Join Date: Dec 2009
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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();
Reply With Quote
  #8  
Old 10-26-2012, 01:44 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 10-26-2012, 01:52 AM
teamshultz teamshultz is offline
 
Join Date: Dec 2009
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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);
Reply With Quote
  #10  
Old 12-16-2012, 08:05 PM
meshkruaj's Avatar
meshkruaj meshkruaj is offline
 
Join Date: Dec 2012
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:24 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04859 seconds
  • Memory Usage 2,237KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete