PDA

View Full Version : check my evil plan: avatars


bulbasnore
03-26-2007, 04:49 AM
So, hypothetically, let's say its April 1.


select userid,avatarid from user order by userid; (then save that as a file)
back up the customavatar table
update user set avatarid = 1337; (now everyone has the same avatar)
*time passes: morning and evening, one day*
use the list of avatarids from step 1 to update the avatarid field as per the value of each user (now everyone has the same avatarid value as they started with)
restore the customavatar table (now those who have the rights to customavatar upload have the original avatar)


Is there any maintenance I need to do after this?
Is there something I'm not accounting for in vBulletin that will prevent me from putting everything back as it was?
Any indexes or whatever to rebuild?

Thanks... I promise not to reveal anyone who helps me to my users! And, of course, you bear no responsibility if I blow the whole thing up!

WetWired
03-26-2007, 07:27 PM
I'd say just to it with template edits. Edit the modifyavatar template to be in a huge <if condition="0"></if>, then edit the MEMBERINFO, postbit, and postbit_legacy templates, doing the same to the normal avatar code and inserting an img tag with your replacement avatar. You may also want to edit the memberlist template, if you have avatars shown in the memberlist.

Styles are easily backed up and restored, too.

bulbasnore
03-27-2007, 12:37 AM
WetWired, that's interesting! Thanks for detailing the templates to edit if I go that route!

Its possible I may change the avatars to something random numbers in a range, too, instead of all the same.

bulbasnore
04-02-2007, 02:16 PM
WARNING: you could lose your whole board mucking with SQL and this procedure could more easily corrupt your data, so if you don't have enough experience or you don't have a backup, run for your life! (or use WetWired's cool trick above).

BTW, this will PROBABLY ONLY WORK if you store your custom avatars in your database!

Our board doesn't have much activity with custom avatars, only staff are allowed to have them, except for certain days when we open them up to regular members. For April Fools, we got a new set of Avatars and I wanted to randomly assign them to everyone. The problem is that if someone does have a custom avatar and then starts switching standard avatars after the random avatars are set, they will wipe out their custom avatar, so, you need a backup.

With that in mind, here's what I did:

In phpmyadmin:

1) Under OPERATIONS copy the customavatar table to customavatar070331
2) Under SQL:
SELECT userid,avatarid,avatarrevision FROM user
3) Use the export button on that result page.
3a) Select the SQL export (default)
3b) turn off (uncheck) Structure
3c) turn on (check) Data & for export type select UPDATE
3d) check zip (or some other compression you like)
3e) hit GO to download the file

OPEN the downloaded file and make sure its valid and shows the update statements that include all 3 fields.

To review, at this point, you've 1) backed up the customavatar table and 2) exported the avatarid/revision data from the user table by userid.

Now here's the fun part, where you randomize everyone's Avatars!

But first you'll test it on your avatar!!! In this case, I used userid 1997, put your test user's userid in place of that.

This statement let's you pick avatars by avatarid, where x is the lowest ID you want to use and z = (highest +1) - the lowest.

update user set `avatarid` = FLOOR( x + ( RAND( ) * z ) ) where userid = 1997;

To use avatars 1 to 100:

update user set `avatarid` = FLOOR( 1 + ( RAND( ) * 100 ) ) where userid = 1997;

To use avatars 819 to 1463:

update user set `avatarid` = FLOOR( 819 + ( RAND( ) *644 ) ) where userid = 1997;

After you check that it works right on your userid, just remove the 'where' clause at the end.

So, now your little prank is over, how do you put it back?

In phpmyadmin:
1) Select the user table, & use the INSERT function to upload the uncompressed SQL export. This will update all the avatar info to the way it was when you exported it.
2) Select the customavatar table:
2a) Under OPERATIONS rename it to customavatars070402
3) Select the customavatar070331 table:
3a) Under OPERATIONS rename it to customavatars

Done!