updateurls.php 3.2 KB

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