-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbackfill_more_user_info_in_flickrusers.php
82 lines (53 loc) · 1.62 KB
/
backfill_more_user_info_in_flickrusers.php
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
$root = dirname(dirname(__FILE__));
ini_set("include_path", "{$root}/www:{$root}/www/include");
set_time_limit(0);
include("include/init.php");
loadlib("backfill");
loadlib("flickr_api");
loadlib("flickr_users");
loadlib("flickr_users_path_aliases");
function _get_nsid($flickr_user, $more=array()){
# TO DO: put this all in a function somewhere and
# call/queue it when a user signs up...
# As db_main:Users
$user = users_get_by_id($flickr_user['user_id']);
if (! $user){
return;
}
$method = 'flickr.people.getInfo';
$args = array(
'user_id' => $flickr_user['nsid'],
);
$ret = flickr_api_call($method, $args);
if (! $ret['ok']){
dumper($args);
dumper($ret);
return;
}
$rsp = $ret['rsp']['person'];
$path_alias = $rsp['path_alias'];
$username = $rsp['username']['_content'];
echo "[{$user['id']}] path alias: {$path_alias} screen name: {$username}\n";
if ($path_alias != $flickr_user['path_alias']){
$update = array(
'path_alias' => $path_alias,
);
$rsp = flickr_users_update_user($flickr_user, $update);
echo "[{$user['id']}] update path alias: {$rsp['ok']}\n";
# just let this fail silently if there's a duplicate
flickr_users_path_aliases_create($user, $path_alias);
}
if ($username != $user['username']){
$update = array(
'username' => $username,
);
$rsp = users_update_user($user, $update);
echo "[{$user['id']}] update username: {$rsp['ok']}\n";
}
}
# TO DO: a flag/option to only fetch users w/out a path_alias
$sql = "SELECT * FROM FlickrUsers";
backfill_db_users($sql, '_get_nsid');
exit();
?>