vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Restore Original 'join date' for members (https://vborg.vbsupport.ru/showthread.php?t=73460)

Electronic Punk 12-29-2004 11:40 AM

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.

rake 12-29-2004 09:26 PM

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.

Electronic Punk 12-29-2004 11:41 PM

Hmm, that has set all their joind dates to 1970 including those that have never posted!

Electronic Punk 12-29-2004 11:53 PM

Fortuantly did a site backup so am backup again :)
Might do it offline next time :)

rake 12-30-2004 01:21 PM

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]'");
}

}

Electronic Punk 12-30-2004 01:58 PM

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 :)

rake 12-30-2004 02:25 PM

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..

Electronic Punk 12-30-2004 02:39 PM

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 :)

rake 12-30-2004 02:49 PM

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.

Electronic Punk 12-30-2004 07:54 PM

There was a few issues with members who had never posted before, but in general the script ran great. Thanks alot for your help! :)

rake 12-31-2004 06:20 AM

hey, i'm glad i was able to help. :)


All times are GMT. The time now is 10:13 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.01876 seconds
  • Memory Usage 1,736KB
  • 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
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (11)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete