Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 12-29-2004, 11:40 AM
Electronic Punk's Avatar
Electronic Punk Electronic Punk is offline
 
Join Date: Dec 2001
Location: StoneHenge
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Restore Original 'join date' for members

Earlier this year my site suffered a serious database problem and we had no real backup solution in effect (oops) and we made the decision to start the forums from scratch with vbulletin3 in order to get the site up again as fast as possible - a very painful decision.

We basically lost all vb2 tables past subscription, alphabetically, so we started from scratch and things started getting back to normal with old users signing backup.

We also started work attempting to get the vbulletin2 database functional again and eventually we got it to such a stage where we could repair the database so that the forums could be viewed.

Unfortunatly the users table was also lost so alot of information such as email address, password could not be regenerated.

It did mean we were able to restore the old posts back into the new vbulletin3 forum using the Jelsoft import tool and effetively all the old users post counts were restored.

All the old posts were left into one forum (we had to regenerate the threads table) but we didn't know which forum id the threads were in so they were all moved back into one big forum composed of around 35,000 threads.

This was a few months ago and now only 7000 threads now need to be moved before all the old data is back in the main forums (sadly old users are guests, but I guess we have to live with that and I can restore them if a new user lets us know that he was here before and I can work around it)

What I would like to be able to do, to get a users join date back as close as possible to when they joined is to base it from their first post.

I am not too hot as SQL so don't really know how to do this, but alot of user think it is important.

I can only think of a few things like if the user has never posted on the new forums then their join date shouldn't be adjusted. But some join dates could be adjusted by over 2 years and it would be great if there was a way of doing it.
Cheers.
Reply With Quote
  #2  
Old 12-29-2004, 09:26 PM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

let's see....

$users = $DB_site->query("SELECT userid,joindate FROM user");
while($user = $DB_site->fetch_array($users))
{
$post = $DB_site->query_first("SELECT * FROM post WHERE userid='$user[userid]' ORDER BY dateline ASC LIMIT 1");

if($post['dateline'] < $user['joindate'])
{
$DB_site->query("UPDATE user SET joindate='$post[dateline]' WHERE userid='$user[userid]'");
}

}

first we loop through the user table, then we find the users first post. if the post is older than joindate we update the user table. simple enough. some of the field names might be off, since i wrote it without looking at the database structure but it should work.
Reply With Quote
  #3  
Old 12-29-2004, 11:41 PM
Electronic Punk's Avatar
Electronic Punk Electronic Punk is offline
 
Join Date: Dec 2001
Location: StoneHenge
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm, that has set all their joind dates to 1970 including those that have never posted!
Reply With Quote
  #4  
Old 12-29-2004, 11:53 PM
Electronic Punk's Avatar
Electronic Punk Electronic Punk is offline
 
Join Date: Dec 2001
Location: StoneHenge
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Fortuantly did a site backup so am backup again
Might do it offline next time
Reply With Quote
  #5  
Old 12-30-2004, 01:21 PM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

sorry about that. i didn't test the code and i also had one of the fields wrong (mentioned that in the post above).

try this but test it first.

$users = $DB_site->query("SELECT userid,joindate FROM user");
while($user = $DB_site->fetch_array($users))
{
$post = $DB_site->query_first("SELECT * FROM post WHERE postuserid='$user[userid]' ORDER BY dateline ASC LIMIT 1");

if($post['dateline'] < $user['joindate'])
{
$DB_site->query("UPDATE user SET joindate='$post[dateline]' WHERE userid='$user[userid]'");
}

}
Reply With Quote
  #6  
Old 12-30-2004, 01:58 PM
Electronic Punk's Avatar
Electronic Punk Electronic Punk is offline
 
Join Date: Dec 2001
Location: StoneHenge
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Actually inserting it into a php script so I can run it every now and then as more old users return 9(tho I reckon that could also be done manually as it willb e fairly infrequently)

Code:
<?php
mysql_connect("localhost", "username", "password");
mysql_select_db("osnn");

$users = mysql_query("SELECT userid,joindate FROM user");
while($user = mysql_fetch_array($users))
{
$post = mysql_query("SELECT * FROM post WHERE post.userid='90' ORDER BY dateline ASC LIMIT 1");

if($post['dateline'] < $user['joindate'])
{
mysql_query("UPDATE user SET joindate='$post[dateline]' WHERE userid='90'");
}
}

?>
http://forum.osnn.net/member.php?u=90
Geffy is my test user.
His join date in the database is now 0 so shows the earliest possible date.

I really appreciate your help so far! I can't write SQL commands, but can kinda read them and as far as I can tell looks right, but I don't know
Reply With Quote
  #7  
Old 12-30-2004, 02:25 PM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you'd need to update his join date to be larger than the dateline of his first post for this to work, since the if statement checks for that.

mysql_query("UPDATE user SET joindate='".time()."' WHERE userid='90'");

then the other code..
Reply With Quote
  #8  
Old 12-30-2004, 02:39 PM
Electronic Punk's Avatar
Electronic Punk Electronic Punk is offline
 
Join Date: Dec 2001
Location: StoneHenge
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I tried adding it to the script, same thing happens.

I manually changed his join date to december 1st 2004 ran the script and it went back to 1970.

I ran the SQL commands manually and they worked, but got lots of users to do
Reply With Quote
  #9  
Old 12-30-2004, 02:49 PM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

here's where your error is:

$post = mysql_query("SELECT * FROM post WHERE post.userid='90' ORDER BY dateline ASC LIMIT 1");

compared to what i wrote...

$post = $DB_site->query_first("SELECT * FROM post WHERE postuserid='$user[userid]' ORDER BY dateline ASC LIMIT 1");

note the "query_first"... you'll need to use an additional mysql_fetch_array there to fetch the first (and only) row. after that it'll probably work.
Reply With Quote
  #10  
Old 12-30-2004, 07:54 PM
Electronic Punk's Avatar
Electronic Punk Electronic Punk is offline
 
Join Date: Dec 2001
Location: StoneHenge
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There was a few issues with members who had never posted before, but in general the script ran great. Thanks alot for your help!
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 07:21 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.04437 seconds
  • Memory Usage 2,256KB
  • 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
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete