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);
55 } catch (Exception $e) {
56 echo "Error updating URLs: " . $e->getMessage();
63 function updateProfileUrl($profile)
65 $orig = clone($profile);
66 $profile->profileurl = common_profile_url($profile->nickname);
67 $profile->update($orig);
70 function updateAvatarUrls($profile)
72 $avatar = new Avatar();
74 $avatar->profile_id = $profile->id;
75 if ($avatar->find()) {
76 while ($avatar->fetch()) {
77 $orig_url = $avatar->url;
78 $avatar->url = Avatar::url($avatar->filename);
79 if ($avatar->url != $orig_url) {
81 "UPDATE avatar SET url = '" . $avatar->url . "' ".
82 "WHERE profile_id = " . $avatar->profile_id . " ".
83 "AND width = " . $avatar->width . " " .
84 "AND height = " . $avatar->height . " ";
86 if ($avatar->original) {
87 $sql .= "AND original = 1 ";
90 if (!$avatar->query($sql)) {
91 throw new Exception("Can't update avatar for user " . $profile->nickname . ".");
100 function updateGroupUrls()
102 printfnq("Updating group URLs...\n");
104 $group = new User_group();
106 if ($group->find()) {
107 while ($group->fetch()) {
109 printfv("Updating group {$group->nickname}...");
110 $orig = User_group::getKV('id', $group->id);
111 if (!empty($group->original_logo)) {
112 $group->original_logo = Avatar::url(basename($group->original_logo));
113 $group->homepage_logo = Avatar::url(basename($group->homepage_logo));
114 $group->stream_logo = Avatar::url(basename($group->stream_logo));
115 $group->mini_logo = Avatar::url(basename($group->mini_logo));
117 // XXX: this is a hack to see if a group is local or not
118 $localUri = common_local_url('groupbyid',
119 array('id' => $group->id));
120 if ($group->getUri() != $localUri) {
121 $group->mainpage = common_local_url('showgroup',
122 array('nickname' => $group->nickname));
124 $group->update($orig);
126 } catch (Exception $e) {
127 echo "Can't update avatars for group " . $group->nickname . ": ". $e->getMessage();