The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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. |
#2
|
||||
|
||||
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. |
#3
|
||||
|
||||
Hmm, that has set all their joind dates to 1970 including those that have never posted!
|
#4
|
||||
|
||||
Fortuantly did a site backup so am backup again
Might do it offline next time |
#5
|
||||
|
||||
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]'"); } } |
#6
|
||||
|
||||
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'"); } } ?> 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 |
#7
|
||||
|
||||
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.. |
#8
|
||||
|
||||
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 |
#9
|
||||
|
||||
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. |
#10
|
||||
|
||||
There was a few issues with members who had never posted before, but in general the script ran great. Thanks alot for your help!
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|