4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
23 $shortoptions = 'i:n:a';
24 $longoptions = array('id=', 'nickname=', 'all');
26 $helptext = <<<END_OF_UPDATEAVATARURL_HELP
27 updateavatarurl.php [options]
28 update the URLs of all avatars in the system
30 -i --id ID of user to update
31 -n --nickname nickname of the user to update
34 END_OF_UPDATEAVATARURL_HELP;
36 require_once INSTALLDIR.'/scripts/commandline.inc';
41 if (have_option('i', 'id')) {
42 $id = get_option_value('i', 'id');
43 $user = User::staticGet('id', $id);
45 throw new Exception("Can't find user with id '$id'.");
48 } else if (have_option('n', 'nickname')) {
49 $nickname = get_option_value('n', 'nickname');
50 $user = User::staticGet('nickname', $nickname);
52 throw new Exception("Can't find user with nickname '$nickname'");
55 } else if (have_option('a', 'all')) {
58 while ($user->fetch()) {
63 throw new Exception("You have to provide an ID or nickname or 'all'.");
65 } catch (Exception $e) {
66 print $e->getMessage()."\n";
70 function updateAvatars($user)
72 if (!have_option('q', 'quiet')) {
73 print "Updating avatars for user '".$user->nickname."' (".$user->id.")...";
76 $avatar = new Avatar();
78 $avatar->profile_id = $user->id;
80 if (!$avatar->find()) {
81 if (have_option('v', 'verbose')) {
82 print "(none found)...";
85 while ($avatar->fetch()) {
86 if (have_option('v', 'verbose')) {
87 if ($avatar->original) {
90 print $avatar->width."...";
94 $orig = clone($avatar);
96 $avatar->url = Avatar::url($avatar->filename);
98 if ($avatar->url != $orig->url) {
100 "UPDATE avatar SET url = '" . $avatar->url . "' ".
101 "WHERE profile_id = " . $avatar->profile_id . " ".
102 "AND width = " . $avatar->width . " " .
103 "AND height = " . $avatar->height . " ";
105 if ($avatar->original) {
106 $sql .= "AND original = 1 ";
109 if (!$avatar->query($sql)) {
110 throw new Exception("Can't update avatar for user " . $user->nickname . ".");
116 if (have_option('v', 'verbose')) {