Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-12-2011, 08:59 AM
zero-two zero-two is offline
 
Join Date: Mar 2011
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default hook for password / email update

Hi everyone.
I want an external db to be syncronized with the vb forum one.
i already managed to have the registration hook working so that every new user confirmed is actually backupped in my other db.
Now i want to keep this data syncronizedm especially the password and the salt fields.

i hooked an update script to profile_updatepassword_complete and the script is correctly called. but
PHP Code:
$userinfo['username'], $userinfo['userid'
are empty! where i can find the info i just updated so i can keep them syncronized?

thanks for your help!
Reply With Quote
  #2  
Old 03-12-2011, 04:55 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Go look at the hook. It's in profile.php. If you look it up, you will see what the correct variable names are for what you want.
Reply With Quote
  #3  
Old 03-12-2011, 06:01 PM
zero-two zero-two is offline
 
Join Date: Mar 2011
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i'm new to vbulletin and the hook system, hope i'm not doing mess :P.
i'm not sure but may be perhaps $userdata?
if i use that i get

Quote:
Fatal error: Cannot use object of type vB_DataManager_User as array in /var/www/forum/hook.php on line 32
where hook.php is the script that sent the data to the other mysql db.
on that line i just say $udata[u_id]=$userinfo['userid']; where userinfo is just the passed array that contains userdata and udata is the new array wich need to be written.

perhaps this is a problem related in used reserved names like userdata , userinfo?

thanks for your assistance, much appreciated
Reply With Quote
  #4  
Old 03-12-2011, 06:04 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Did you look up the file I asked you to and find the hook? Right above it, they define $username and $userid. Please look in the code and you will see what I mean.
Reply With Quote
  #5  
Old 03-13-2011, 08:51 AM
zero-two zero-two is offline
 
Join Date: Mar 2011
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i had a look at profile.php.

but

$username is empty
$password is empty.
$userid is empty
$userinfo have other stuff into it.
$userdata is empty

i can't fetch any data at all...i can't know what user is performing the email/password update!


---------------MY SOLUTION
Thanks for your help,i still need to learn Vbulletin, is an amazing software.

i found a more elegant solution for my problem to sync data between those two db.
I post it here for everyone that need the same backup system...

this may not be fit for everyone,but in my case i wanted the website to be autonomous from the server, so i need data redundancy and i need to save on a secondary db login access plus more data related to the website. this way i still can use all website custom functions (such as login, commenting email profiling etc) while , for example, forum is under mainteinance, shut down, defaced, or even absent al all.
This allows also to change the board in the future still being able to have data saved virtually everywhere.
Also a quick and dirty backup of access data table only can be done much faster and stored or sent via rsync on the backup server much more frequently since it's smaller than the Vb user table.

for creating a user:

hook a function in "register_activate_process" then fetch user data and insert custom fields OR use an insert trigger.
(the hook is better since it will create the data once the user is verified, ence able to login effectlively from website or forum)

to keep data syncronized just go to your phpmyadmin panel or similar, and drop the SQL code while your forum DB is selected:

PHP Code:
CREATE TRIGGER update_trigger AFTER UPDATE ON forum.t_user
FOR EACH ROW
UPDATE db_site
.t_users SET u_username = NEW.username u_password = NEW.password u_salt = NEW.salt WHERE u_id = NEW.userid
and the following to auto delete deleted users

PHP Code:
CREATE TRIGGER delete BEFORE DELETE ON forum.t_user
FOR EACH ROW
DELETE from db_site
.t_users WHERE u_id OLD.userid
to show active triggers just do a SHOW TRIGGERS.
if you want to remove a trigger just do a DROP TRIGGER triggername

Obviusly in the update trigger you will also need to specify if the user is active,so he can eventually login or not.
you may perhaps do more stuff, like sync across multiple websites.

PHP Code:
CREATE TRIGGER update_trigger AFTER UPDATE ON forum.t_user
FOR EACH ROW
UPDATE db_site
.t_users SET u_username = NEW.username u_password = NEW.password u_salt = NEW.salt WHERE u_id = NEW.userid;
UPDATE db_site1.t_users SET u_username = NEW.username u_password = NEW.password u_salt = NEW.salt WHERE u_id = NEW.userid;
UPDATE db_site2.t_users SET u_username = NEW.username u_password = NEW.password u_salt = NEW.salt WHERE u_id = NEW.userid

Very important: In my case, since i did not needed data to be manipulated, this is, imho, the best option.
if you need data manipulation you will still need to use the hooks.
For example i did not used the insert trigger because i wanted to process user data.

hope it helps.

Cya
Reply With Quote
Reply


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 05:45 PM.


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.23872 seconds
  • Memory Usage 2,210KB
  • 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
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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