restoreuser.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010 StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. define('INSTALLDIR', dirname(__DIR__));
  20. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  21. $shortoptions = 'i:n:f:';
  22. $longoptions = array('id=', 'nickname=', 'file=');
  23. $helptext = <<<END_OF_RESTOREUSER_HELP
  24. restoreuser.php [options]
  25. Restore a backed-up user file to the database. If
  26. neither ID or name provided, will create a new user.
  27. -i --id ID of user to export
  28. -n --nickname nickname of the user to export
  29. -f --file file to read from (STDIN by default)
  30. END_OF_RESTOREUSER_HELP;
  31. require_once INSTALLDIR.'/scripts/commandline.inc';
  32. function getActivityStreamDocument()
  33. {
  34. $filename = get_option_value('f', 'file');
  35. if (empty($filename)) {
  36. show_help();
  37. exit(1);
  38. }
  39. if (!file_exists($filename)) {
  40. throw new Exception("No such file '$filename'.");
  41. }
  42. if (!is_file($filename)) {
  43. throw new Exception("Not a regular file: '$filename'.");
  44. }
  45. if (!is_readable($filename)) {
  46. throw new Exception("File '$filename' not readable.");
  47. }
  48. // TRANS: Commandline script output. %s is the filename that contains a backup for a user.
  49. printfv(_("Getting backup from file '%s'.")."\n",$filename);
  50. $xml = file_get_contents($filename);
  51. return $xml;
  52. }
  53. try {
  54. try {
  55. $user = getUser();
  56. } catch (NoUserArgumentException $noae) {
  57. $user = null;
  58. }
  59. $xml = getActivityStreamDocument();
  60. $qm = QueueManager::get();
  61. $qm->enqueue(array($user, $xml, true), 'feedimp');
  62. } catch (Exception $e) {
  63. print $e->getMessage()."\n";
  64. exit(1);
  65. }