| 1 |
#!/usr/bin/env php |
| 2 |
<?php |
| 3 |
/* |
| 4 |
* StatusNet - a distributed open-source microblogging tool |
| 5 |
* Copyright (C) 2008, 2009, 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 = 'i:n:a'; |
| 24 |
$longoptions = array('id=', 'nickname=', 'all'); |
| 25 |
|
| 26 |
$helptext = <<<END_OF_UPDATEAVATARURL_HELP |
| 27 |
updateavatarurl_group.php [options] |
| 28 |
update the URLs of all group avatars in the system |
| 29 |
|
| 30 |
-i --id ID of group to update |
| 31 |
-n --nickname nickname of the group to update |
| 32 |
-a --all update all |
| 33 |
|
| 34 |
END_OF_UPDATEAVATARURL_HELP; |
| 35 |
|
| 36 |
require_once INSTALLDIR.'/scripts/commandline.inc'; |
| 37 |
|
| 38 |
try { |
| 39 |
$user = null; |
| 40 |
|
| 41 |
if (have_option('i', 'id')) { |
| 42 |
$id = get_option_value('i', 'id'); |
| 43 |
$group = User_group::staticGet('id', $id); |
| 44 |
if (empty($group)) { |
| 45 |
throw new Exception("Can't find group with id '$id'."); |
| 46 |
} |
| 47 |
updateGroupAvatars($group); |
| 48 |
} else if (have_option('n', 'nickname')) { |
| 49 |
$nickname = get_option_value('n', 'nickname'); |
| 50 |
$group = User_group::staticGet('nickname', $nickname); |
| 51 |
if (empty($group)) { |
| 52 |
throw new Exception("Can't find group with nickname '$nickname'"); |
| 53 |
} |
| 54 |
updateGroupAvatars($group); |
| 55 |
} else if (have_option('a', 'all')) { |
| 56 |
$group = new User_group(); |
| 57 |
if ($group->find()) { |
| 58 |
while ($group->fetch()) { |
| 59 |
updateGroupAvatars($group); |
| 60 |
} |
| 61 |
} |
| 62 |
} else { |
| 63 |
show_help(); |
| 64 |
exit(1); |
| 65 |
} |
| 66 |
} catch (Exception $e) { |
| 67 |
print $e->getMessage()."\n"; |
| 68 |
exit(1); |
| 69 |
} |
| 70 |
|
| 71 |
function updateGroupAvatars($group) |
| 72 |
{ |
| 73 |
if (!have_option('q', 'quiet')) { |
| 74 |
print "Updating avatars for group '".$group->nickname."' (".$group->id.")..."; |
| 75 |
} |
| 76 |
|
| 77 |
if (empty($group->original_logo)) { |
| 78 |
print "(none found)..."; |
| 79 |
} else { |
| 80 |
// Using clone here was screwing up the group->find() iteration |
| 81 |
$orig = User_group::staticGet('id', $group->id); |
| 82 |
|
| 83 |
$group->original_logo = Avatar::url(basename($group->original_logo)); |
| 84 |
$group->homepage_logo = Avatar::url(basename($group->homepage_logo)); |
| 85 |
$group->stream_logo = Avatar::url(basename($group->stream_logo)); |
| 86 |
$group->mini_logo = Avatar::url(basename($group->mini_logo)); |
| 87 |
|
| 88 |
if (!$group->update($orig)) { |
| 89 |
throw new Exception("Can't update avatars for group " . $group->nickname . "."); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
if (have_option('v', 'verbose')) { |
| 94 |
print "DONE."; |
| 95 |
} |
| 96 |
if (!have_option('q', 'quiet') || have_option('v', 'verbose')) { |
| 97 |
print "\n"; |
| 98 |
} |
| 99 |
} |