updateurls.php 3.2 KB

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