]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/updateurls.php
Introduced common_location_shared() to check if location sharing is always,
[quix0rs-gnu-social.git] / scripts / updateurls.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - a distributed open-source microblogging tool
5  * Copyright (C) 2008-2011, StatusNet, Inc.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
22
23 $shortoptions = '';
24 $longoptions = array();
25
26 $helptext = <<<END_OF_UPDATEURLS_HELP
27 updateurls.php [options]
28 update stored URLs in the system
29
30 END_OF_UPDATEURLS_HELP;
31
32 require_once INSTALLDIR.'/scripts/commandline.inc.php';
33
34 function main()
35 {
36     updateUserUrls();
37     updateGroupUrls();
38 }
39
40 function updateUserUrls()
41 {
42     printfnq("Updating user URLs...\n");
43
44     // XXX: only update user URLs where out-of-date
45
46     $user = new User();
47     if ($user->find()) {
48         while ($user->fetch()) {
49             printfv("Updating user {$user->nickname}...");
50             try {
51                 $profile = $user->getProfile();
52
53                 updateProfileUrl($profile);
54             } catch (Exception $e) {
55                 echo "Error updating URLs: " . $e->getMessage();
56             }
57             printfv("DONE.");
58         }
59     }
60 }
61
62 function updateProfileUrl($profile)
63 {
64     $orig = clone($profile);
65     $profile->profileurl = common_profile_url($profile->nickname);
66     $profile->update($orig);
67 }
68
69 function updateGroupUrls()
70 {
71     printfnq("Updating group URLs...\n");
72
73     $group = new User_group();
74
75     if ($group->find()) {
76         while ($group->fetch()) {
77             try {
78                 printfv("Updating group {$group->nickname}...");
79                 $orig = User_group::getKV('id', $group->id);
80                 if (!empty($group->original_logo)) {
81                     $group->original_logo = Avatar::url(basename($group->original_logo));
82                     $group->homepage_logo = Avatar::url(basename($group->homepage_logo));
83                     $group->stream_logo = Avatar::url(basename($group->stream_logo));
84                     $group->mini_logo = Avatar::url(basename($group->mini_logo));
85                 }
86                 // XXX: this is a hack to see if a group is local or not
87                 $localUri = common_local_url('groupbyid',
88                                              array('id' => $group->id));
89                 if ($group->getUri() != $localUri) {
90                     $group->mainpage = common_local_url('showgroup',
91                                                         array('nickname' => $group->nickname));
92                 }
93                 $group->update($orig);
94                 printfv("DONE.");
95             } catch (Exception $e) {
96                 echo "Can't update avatars for group " . $group->nickname . ": ". $e->getMessage();
97             }
98         }
99     }
100 }
101
102 main();