update-user.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/php
  2. <?php
  3. require('_cli.php');
  4. $options = getopt('', array(
  5. 'user:',
  6. 'password:',
  7. 'api-password:',
  8. 'language:',
  9. 'email:',
  10. 'token:',
  11. 'purge_after_months:',
  12. 'feed_min_articles_default:',
  13. 'feed_ttl_default:',
  14. 'since_hours_posts_per_rss:',
  15. 'min_posts_per_rss:',
  16. 'max_posts_per_rss:',
  17. ));
  18. if (empty($options['user'])) {
  19. fail('Usage: ' . basename(__FILE__) . " --user username ( --password 'password' --api-password 'api_password'" .
  20. " --language en --email user@example.net --token 'longRandomString' --purge_after_months 3 " .
  21. " --feed_min_articles_default 50 --feed_ttl_default 3600 --since_hours_posts_per_rss 168 --min_posts_per_rss 2 --max_posts_per_rss 400 )");
  22. }
  23. $username = cliInitUser($options['user']);
  24. echo 'FreshRSS updating user “', $username, "”…\n";
  25. function intParam($name) {
  26. return isset($options[$name]) && ctype_digit($options[$name]) ? intval($options[$name]) : null;
  27. }
  28. $ok = FreshRSS_user_Controller::updateContextUser(
  29. empty($options['password']) ? '' : $options['password'],
  30. empty($options['api-password']) ? '' : $options['api-password'],
  31. array(
  32. 'language' => isset($options['language']) ? $options['language'] : null,
  33. 'mail_login' => isset($options['email']) ? $options['email'] : null,
  34. 'token' => isset($options['token']) ? $options['token'] : null,
  35. 'old_entries' => intParam('purge_after_months'),
  36. 'keep_history_default' => intParam('feed_min_articles_default'),
  37. 'ttl_default' => intParam('feed_ttl_default'),
  38. 'since_hours_posts_per_rss' => intParam('since_hours_posts_per_rss'),
  39. 'min_posts_per_rss' => intParam('min_posts_per_rss'),
  40. 'max_posts_per_rss' => intParam('max_posts_per_rss'),
  41. ));
  42. if (!$ok) {
  43. fail('FreshRSS could not update user!');
  44. }
  45. invalidateHttpCache($username);
  46. accessRights();
  47. done($ok);