diff options
author | Henry Sudhof <kellanved@phpbb.com> | 2007-04-30 10:46:17 +0000 |
---|---|---|
committer | Henry Sudhof <kellanved@phpbb.com> | 2007-04-30 10:46:17 +0000 |
commit | 42251d008c06ad0f475f116643c6583fc9a4eda7 (patch) | |
tree | 0380ef1d4f7224c96612a8951988a59f33c6074e /phpBB/develop/adjust_avatars.php | |
parent | dc747b8d994b6f5d07182196ed9deed7959a7317 (diff) | |
download | forums-42251d008c06ad0f475f116643c6583fc9a4eda7.tar forums-42251d008c06ad0f475f116643c6583fc9a4eda7.tar.gz forums-42251d008c06ad0f475f116643c6583fc9a4eda7.tar.bz2 forums-42251d008c06ad0f475f116643c6583fc9a4eda7.tar.xz forums-42251d008c06ad0f475f116643c6583fc9a4eda7.zip |
Prepare to be yelled at and brace for the tide of bug reports: I had hoped we would not have to do this, but it seems that we have to.
-Route all avatar downloads through download.php - adrien
-Change the way inline attachments are delivered
-Fixes a few (unreported) bugs, notably avatar upload during group generation
-#10079
git-svn-id: file:///svn/phpbb/trunk@7429 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/develop/adjust_avatars.php')
-rwxr-xr-x | phpBB/develop/adjust_avatars.php | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/phpBB/develop/adjust_avatars.php b/phpBB/develop/adjust_avatars.php new file mode 100755 index 0000000000..87514166ff --- /dev/null +++ b/phpBB/develop/adjust_avatars.php @@ -0,0 +1,142 @@ +<?php +/** +* Corrects avatar filenames to match the new avatar delivery method. +* +* You should make a backup from your users table and the avatar directory in case something goes wrong +*/ +die("Please read the first lines of this script for instructions on how to enable it"); + +set_time_limit(0); + +define('IN_PHPBB', true); +$phpbb_root_path = './../'; +$phpEx = substr(strrchr(__FILE__, '.'), 1); +include($phpbb_root_path . 'common.'.$phpEx); + +// Start session management +$user->session_begin(); +$auth->acl($user->data); +$user->setup(); + +$echos = 0; + +if (!isset($config['avatar_salt'])) +{ + $cache->purge(); + if (!isset($config['avatar_salt'])) + { + die('database not up to date'); + } + die('database not up to date'); +} + +// let's start with the users using a group_avatar. +$sql = 'SELECT group_id, group_avatar + FROM ' . GROUPS_TABLE . + ' WHERE group_avatar_type = ' . AVATAR_UPLOAD; + +// We'll skip these, so remember them +$group_avatars = array(); + +echo '<br /> Updating groups' . "\n"; + +$result = $db->sql_query($sql); + +while ($row = $db->sql_fetchrow($result)) +{ + + $new_avatar_name = adjust_avatar($row['group_avatar'], 'g' . $row['group_id']); + $group_avatars[] = $new_avatar_name; + + // failure is probably due to the avatar name already being adjusted + if ($new_avatar_name !== false) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_avatar = '$new_avatar_name' + WHERE user_avatar = '{$row['group_avatar']}' + AND user_avatar_type = " . AVATAR_UPLOAD; + $db->sql_query($sql); + + $sql = 'UPDATE ' . GROUPS_TABLE . " + SET group_avatar = '$new_avatar_name' + WHERE group_id = {$row['group_id']}"; + $db->sql_query($sql); + } + else + { + echo '<br /> Failed updating group ' . $row['group_id'] . "\n"; + } + + if ($echos > 200) + { + echo '<br />' . "\n"; + $echos = 0; + } + + echo '.'; + $echos++; + + flush(); +} +$db->sql_freeresult($result); + +$sql = 'SELECT user_id, username, user_avatar, user_avatar_type + FROM ' . USERS_TABLE . ' + WHERE user_avatar_type = ' . AVATAR_UPLOAD . ' + AND ' . $db->sql_in_set('user_avatar', $group_avatars, true); + +$result = $db->sql_query($sql); + +echo '<br /> Updating users' . "\n"; + +while ($row = $db->sql_fetchrow($result)) +{ + + $new_avatar_name = adjust_avatar($row['user_avatar'], $row['user_id']); + + // failure is probably due to the avatar name already being adjusted + if ($new_avatar_name !== false) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_avatar = '$new_avatar_name' + WHERE user_id = {$row['user_id']}"; + $db->sql_query($sql); + } + else + { + echo '<br /> Failed updating user ' . $row['user_id'] . "\n"; + } + + if ($echos > 200) + { + echo '<br />' . "\n"; + $echos = 0; + } + + echo '.'; + $echos++; + + flush(); +} + +$db->sql_freeresult($result); + +echo 'FINISHED'; + +// Done +$db->sql_close(); + +function adjust_avatar($old_name, $midfix) +{ + global $config, $phpbb_root_path; + + $avatar_path = $phpbb_root_path . $config['avatar_path']; + if (@file_exists($avatar_path . '/' . $old_name) && @is_writable($avatar_path . '/' . $old_name)) + { + $new_name = $config['avatar_salt'] . '_' . $midfix . '.' . substr(strrchr($old_name, '.'), 1); + @rename($avatar_path . '/' . $old_name, $avatar_path . '/' . $new_name); + return $midfix . '.' . substr(strrchr($old_name, '.'), 1); + } + return false; +} +?>
\ No newline at end of file |