updateuris.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. * Update User URIs.
  22. *
  23. * @package GNUsocial
  24. * @author Bruno Casteleiro <brunoccast@fc.up.pt>
  25. * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
  26. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  27. */
  28. define('INSTALLDIR', dirname(__FILE__, 2));
  29. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  30. $shortoptions = '';
  31. $longoptions = array();
  32. $helptext = <<<END_OF_UPDATEURLS_HELP
  33. updateuris.php [options]
  34. update stored user URIs in the system
  35. END_OF_UPDATEURLS_HELP;
  36. require_once INSTALLDIR.'/scripts/commandline.inc';
  37. function main()
  38. {
  39. updateUserUris();
  40. }
  41. function updateUserUris()
  42. {
  43. printfnq("Updating user URIs...\n");
  44. $user = new User();
  45. if ($user->find()) {
  46. while ($user->fetch()) {
  47. printfv("Updating user {$user->nickname}...");
  48. try {
  49. updateUserUri($user);
  50. } catch(Exception $e) {
  51. echo "\nError updating {$user->nickname} URI: " . $e->getMessage() . "\n";
  52. }
  53. printfv("DONE.\n");
  54. }
  55. }
  56. }
  57. function updateUserUri($user)
  58. {
  59. $orig = clone($user);
  60. $user->uri = common_user_uri($user);
  61. $user->updateWithKeys($orig);
  62. }
  63. main();