vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Custom user fields (https://vborg.vbsupport.ru/showthread.php?t=70224)

hkvic 10-05-2004 02:23 PM

Custom user fields
 
First off - sorry if cross posting is frowned on, but was advised to post this here after posting in the community forums...Anyway original post was:

I have just purchased VB after being with ikonboard for quite a while. I am going to be importing my old ikonboard 3.11 Mysql database which contains approx 2000 users and around 70,000 posts.

This database has been hacked over a period of time with custom additions. The main one that concerns me is that I have added 7 custom rows in the ib_member_profiles table which contain first and last member names, dates and other data.

My question is: is there any way to adapt the impex files so that I can import this additional data? If not, then I guess I'll have to enter all the details again by hand.

Any help or advice would be appreciated.

PS. wish I'd made this move years ago - I wouldn't be going through all this now.

Xenon 10-05-2004 04:00 PM

it shouldn't be such a problem to manipulate the impex to import those things as well.

As it is a very custom request, you might have to post a service request, but AFAICS it shouldn't be very hard, just a few more lines :)

hkvic 10-05-2004 05:11 PM

Many thanks for that. Should I leave this here a while to see if there are any other responses or should I post a service request straight away?

I've only joined recently and am not really up to speed on the protocols here yet.

Colin F 10-05-2004 05:18 PM

You're free to post a service request. Be aware though, that service requests are payed requests, so only post if you're willing to compensate the coder willing to help you. Also, have a look at the following thread before picking a coder: https://vborg.vbsupport.ru/showthread.php?t=69734

Unfortunatelly, I don't know impex well enough to help you.

Good luck though :)

hkvic 10-05-2004 05:50 PM

Cheers. I'll give it some serious consideration.

Jerry 10-06-2004 09:58 AM

Two things we are going to be interested in here to get this done are :

The files ;

impex/systems/ikon_mysql/000.php The API module for the data source
impex/systems/ikon_mysql/004.php The import user module

The commands ;

add_custom_field()
add_custom_value()


Checking we are getting the data

First we need know that ImpEx is bring the data in when it imports users.

The extra fields are in the member_profiles table (ignoring the table prefix for this example).

Checking 000.php and finding get_ikon_mysql_user_details() we can see that we select * from the member_profiles (with a join on the calendar for some more info). So anything that is in the member_profiles table will be returned to module 004 when importing users.

If this wasn't the case and the fields were some where else, we'd have to alter this function to add the details to the array for that user id (have a look at EVE to see what I mean there).


Preparing vBulletin for the data

So now we know that the extra fields we are interested in are being passed to module 004, import user.

To prepare the target database so that it knows about the custom fields and what to do with them, we have to tell it about it, this is where we use :

$this->add_custom_field()

We place this inside the init() function of the class, this is the first function that is called once, the one that asks for paths, counts per page, does all the set up, cleans up from any previous import, etc. Lines 55 to 77 in ikon_mysql/004.php.

This takes 5 arguments and looks like this :

Code:

// Add all the custom fields we want to import
$tdt = $sessionobject->get_session_var('targetdatabasetype');
$ttp = $sessionobject->get_session_var('targettableprefix');

$this->add_custom_field($Db_target, $tdt, $ttp, 'age','user age');
$this->add_custom_field($Db_target, $tdt, $ttp, 'gender','user gender');
.....

As with an ImpEx function the first 3 arguments as the database object, the database type and the table prefix. I've used the short name variable $tdt and $ttp, so it fits on a line and is more readable.

Line 177 of ImpExDatabase.php for add_custom_field(). It adds the fields and coloums to profilefield and userfield.


Importing it

No now we know its coming in, and that we have set up the database to accept the data, we have to actually import it with each user by adding it to the user object just before its imported.

On lines 142-219 we are adding all the data, calling the parsing functions, building dates into unix timestamps etc. This is where we are filling up a user object with all its data before calling import_user() on it.

Lines 204-206 are doing some add_default_value() so well add our new lines after that :

$try->add_custom_value(varname, value);

So for us it is :

Code:

$try->add_custom_value('age', $user_details['AGE']);
$try->add_custom_value('gender', $user_details['GENDER']);

Note, we are using $try and not $this . $try is the user object and that is what we are adding the data to. You can see on line 123 and 142 that its a user object.

The first argument is the varname that we created up in the init section same as the 4th argument to the add_custom_field() function.

The second argument is the actual data for that user, as we have already checked the 000.php and the get_ikon_mysql_user_details() function we know the data is being returned, and for each pass in this loop the $user_details[] array will have all the data in there we need, we just have to put the correct column name in at the right place. Though we might have to trim or addslasshes depending on what the data might be, examples of that are all over the code in the import user module.

And that is it really.

Summary
000, make sure you are getting the data in get_ikon_mysql_user_details()

004->init(), add the correct filed to the database with add_custom_field()

004->resume(), actual import the data when importing the user add_custom_value()

Jerry 10-06-2004 09:42 PM

1 Attachment(s)
So for instance if the extra fields where :

MEMBER_FNAME
MEMBER_LNAME
MEMBER_START
MEMBER_END
MEMBER_YEAR
MEMBER_STATE
MEMBER_HOUSE

The code would be :

Code:

// Add all the custom fields we want to import
$tdt = $sessionobject->get_session_var('targetdatabasetype');
$ttp = $sessionobject->get_session_var('targettableprefix');

$this->add_custom_field($Db_target, $tdt, $ttp, 'fname','First Name');
$this->add_custom_field($Db_target, $tdt, $ttp, 'lname','Last Name');
$this->add_custom_field($Db_target, $tdt, $ttp, 'start','Start');
$this->add_custom_field($Db_target, $tdt, $ttp, 'end','End');
$this->add_custom_field($Db_target, $tdt, $ttp, 'year','Year');
$this->add_custom_field($Db_target, $tdt, $ttp, 'state','State');
$this->add_custom_field($Db_target, $tdt, $ttp, 'house','House');

and

Code:

$try->add_custom_value('fname', $user_details['MEMBER_FNAME']);
$try->add_custom_value('lname', $user_details['MEMBER_LNAME']);
$try->add_custom_value('start', $user_details['MEMBER_START']);
$try->add_custom_value('end', $user_details['MEMBER_END']);
$try->add_custom_value('year', $user_details['MEMBER_YEAR']);
$try->add_custom_value('state', $user_details['MEMBER_STATE']);
$try->add_custom_value('house', $user_details['MEMBER_HOUSE']);


As shown in the attached file braced by :

Code:

// *******************
// The custom stuff
// *******************


hkvic 10-07-2004 07:39 AM

Excellent, many thanks.

I've only been with VB for a couple of days and am amazed at the superb support offered.

XXP 03-14-2007 11:38 PM

Quote:

Originally Posted by Jerry (Post 559513)
The commands ;

add_custom_field()
add_custom_value()

. . .

Summary
000, make sure you are getting the data in get_ikon_mysql_user_details()

004->init(), add the correct filed to the database with add_custom_field()

004->resume(), actual import the data when importing the user add_custom_value()

In the ImpExData.php module it says for function add_custom_value that the first argument, called "$key", is "the name of value being set".

What "name" is that? Is that any valid field name?

Also, if you don't mind, does the "set_value" function work for any valid existing (i.e., defined) vB field in the vbfields.php file?

Thanks.

Marco van Herwaarden 03-15-2007 06:40 AM

This thread is more then 2 years old. I suggest you post your question in the ImpEx forum on vb.com.


All times are GMT. The time now is 01:46 AM.

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.01392 seconds
  • Memory Usage 1,755KB
  • 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
  • (5)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete