4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2008-2011, 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__) . '/..'));
24 $longoptions = array();
26 $helptext = <<<END_OF_UPDATEURLS_HELP
27 updateurls.php [options]
28 update stored URLs in the system
30 END_OF_UPDATEURLS_HELP;
32 require_once INSTALLDIR.'/scripts/commandline.inc';
40 function updateUserUrls()
42 printfnq("Updating user URLs...\n");
44 // XXX: only update user URLs where out-of-date
48 while ($user->fetch()) {
49 printfv("Updating user {$user->nickname}...");
51 $profile = $user->getProfile();
53 updateProfileUrl($profile);
54 updateAvatarUrls($profile);
56 // Broadcast for remote users
58 common_broadcast_profile($profile);
60 } catch (Exception $e) {
61 printv("Error updating URLs: " . $e->getMessage());
68 function updateProfileUrl($profile)
70 $orig = clone($profile);
71 $profile->profileurl = common_profile_url($profile->nickname);
72 $profile->update($orig);
75 function updateAvatarUrls($profile)
77 $avatar = new Avatar();
79 $avatar->profile_id = $profile->id;
80 if ($avatar->find()) {
81 while ($avatar->fetch()) {
82 $orig_url = $avatar->url;
83 $avatar->url = Avatar::url($avatar->filename);
84 if ($avatar->url != $orig_url) {
86 "UPDATE avatar SET url = '" . $avatar->url . "' ".
87 "WHERE profile_id = " . $avatar->profile_id . " ".
88 "AND width = " . $avatar->width . " " .
89 "AND height = " . $avatar->height . " ";
91 if ($avatar->original) {
92 $sql .= "AND original = 1 ";
95 if (!$avatar->query($sql)) {
96 throw new Exception("Can't update avatar for user " . $profile->nickname . ".");
105 function updateGroupUrls()
107 printfnq("Updating group URLs...\n");
109 $group = new User_group();
111 if ($group->find()) {
112 while ($group->fetch()) {
114 printfv("Updating group {$group->nickname}...");
115 $orig = User_group::staticGet('id', $group->id);
116 if (!empty($group->original_logo)) {
117 $group->original_logo = Avatar::url(basename($group->original_logo));
118 $group->homepage_logo = Avatar::url(basename($group->homepage_logo));
119 $group->stream_logo = Avatar::url(basename($group->stream_logo));
120 $group->mini_logo = Avatar::url(basename($group->mini_logo));
122 // XXX: this is a hack to see if a group is local or not
123 $localUri = common_local_url('groupbyid',
124 array('id' => $group->id));
125 if ($group->getUri() != $localUri) {
126 $group->mainpage = common_local_url('showgroup',
127 array('nickname' => $group->nickname));
129 $group->update($orig);
131 } catch (Exception $e) {
132 printv("Can't update avatars for group " . $group->nickname . ": ". $e->getMessage());