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