blob: 4df044cff560f9e7a57b9adc13212808ab747645 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php
/**
* Change profile image names to use guid rather than username
*/
function user_file_matrix_2010071001($guid) {
// lookup the entity
$user = get_entity($guid);
if ($user->type != 'user') {
// only to be used for user directories
return FALSE;
}
if (!$user->time_created) {
// no idea where this user has its files
return FALSE;
}
$time_created = date('Y/m/d', $user->time_created);
return "$time_created/$user->guid/";
}
$sizes = array('large', 'medium', 'small', 'tiny', 'master', 'topbar');
global $DB_QUERY_CACHE, $DB_PROFILE, $ENTITY_CACHE, $CONFIG;
$users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity WHERE username != ''");
while ($user = mysql_fetch_object($users)) {
$DB_QUERY_CACHE = $DB_PROFILE = $ENTITY_CACHE = array();
$user_directory = user_file_matrix_2010071001($user->guid);
if (!$user_directory) {
continue;
}
$profile_directory = $CONFIG->dataroot . $user_directory . "profile/";
if (!file_exists($profile_directory)) {
continue;
}
foreach ($sizes as $size) {
$old_filename = "$profile_directory{$user->username}{$size}.jpg";
$new_filename = "$profile_directory{$user->guid}{$size}.jpg";
if (file_exists($old_filename)) {
if (!rename($old_filename, $new_filename)) {
error_log("Failed to rename profile photo for $user->username");
}
}
}
}
|