blob: 5594493a8eb1d4341726e26f7611d3a6d76f329b (
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
49
50
51
52
53
54
55
56
57
58
|
<?php
/**
* Change profile image names to use guid rather than username
*/
/**
* Need the same function to generate a user matrix, but can't call it
* the same thing as the previous update.
*
* @param int $guid User guid.
*
* @return string File matrix
*/
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 $ENTITY_CACHE, $CONFIG;
$users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity
WHERE username != ''");
while ($user = mysql_fetch_object($users)) {
$ENTITY_CACHE = array();
_elgg_invalidate_query_cache();
$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");
}
}
}
}
|