Bulk loading threads with thread fields
Anil Gidwani Offline
Junior Member
**
Posts: 3
Joined: Jul 2013
Post: #1
Bulk loading threads with thread fields
I'm working on a plugin for bulk loading data into a forum that allows XThreads.

So far, I've got the package to read a CSV file and upload the threads into the forum with the thread subject and body. This was done by the following code, which invokes the posthandler for ordinary threads, $posthandler->validate_thread:

$new_thread = array(
"fid" => 21,
"subject" => $finalSubject,
"icon" => ' ',
"uid" => '1',
"username" => $mybb->user['username'], /* Screened for Super Admin */
"message" => $finalBody,
"ipaddress" => '127.0.0.1',
"posthash" => ''
);

$posthandler->set_data($new_thread);
$valid_thread = $posthandler->validate_thread();

My question is:  Is there a corresponding posthandler->validate_thread for XThreads?   I was unable to find one.

How do I modify the above code so that an XThread with thread field data is created instead of an ordinary thread?
Should "xthreads_input_posthandler_insert" be called instead?
(This post was last modified: 07-24-2013 06:33 PM by Anil Gidwani.)
07-24-2013 04:17 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Bulk loading threads with thread fields
XThreads runs off the MyBB posthandler validation, so you don't need to do anything special there.

You probably do have to set your XThreads values into the $mybb->input array though because there's not really an easy way for a plugin to modify the array that gets sent into the posthandler.

It would probably look something like:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 $new_thread = array(
"fid" => 21,
"subject" => $finalSubject,
"icon" => ' ',
"uid" => '1',
"username" => $mybb->user['username'], /* Screened for Super Admin */
"message" => $finalBody,
"ipaddress" => '127.0.0.1',
"posthash" => ''
);

is_array($mybb->input) or $mybb->input = array();
$mybb->input['xthreads_myfield'] = 'value'; // sets value for the custom thread field named "myfield"

$posthandler->set_data($new_thread);
$valid_thread = $posthandler->validate_thread();


My Blog
07-25-2013 12:05 PM
Find all posts by this user Quote this message in a reply
Anil Gidwani Offline
Junior Member
**
Posts: 3
Joined: Jul 2013
Post: #3
RE: Bulk loading threads with thread fields
> $mybb->input['xthreads_myfield'] = 'value'; // sets value for the custom thread field named "myfield"

Is there any way I can loop through all xthreads_myfields and set the value in this array? In other words, can I use xthreads metadata to set up a generic loop to set values for each custom thread field?  Something like

for (i=0 ; i<= xthreads_numfields; i++)
    $mybb->input[xthreads_myfield[i]] = 'value_read_from_csv_file [i]'
  
Otherwise, the plug in will require extensive modifications by each user of the plugin.
07-25-2013 08:37 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: Bulk loading threads with thread fields
(07-25-2013 08:37 PM)Anil Gidwani Wrote:  Otherwise, the plug in will require extensive modifications by each user of the plugin.
I think this will be required anyway since you don't exactly know what fields a user has.

You probably should be using the CSV header for determining field names, as there's no guarantee what order you'll receive the fields from both the CSV or the database.

But if you're still adamant on your solution, you can read the threadfields cache (see the MyBB cache object) for a list of thread fields.  Note that this contains all thread fields across all forums.

My Blog
07-27-2013 11:37 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: